-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dd
fix gnu test not-rewound.sh
#6088
Merged
sylvestre
merged 1 commit into
uutils:main
from
cre4ture:fix/gnu_test_dd_not_rewound_sh
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
pub mod display; | ||
pub mod error; | ||
pub mod io; | ||
pub mod line_ending; | ||
pub mod os; | ||
pub mod panic; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// This file is part of the uutils coreutils package. | ||
// | ||
// For the full copyright and license information, please view the LICENSE | ||
// file that was distributed with this source code. | ||
|
||
/// Encapsulates differences between OSs regarding the access to | ||
/// file handles / descriptors. | ||
/// This is useful when dealing with lower level stdin/stdout access. | ||
/// | ||
/// In detail: | ||
/// On unix like OSs, file _descriptors_ are used in this context. | ||
/// On windows OSs, file _handles_ are used. | ||
/// | ||
/// Even though they are distinct classes, they share common functionality. | ||
/// Access to this common functionality is provided in `OwnedFileDescriptorOrHandle`. | ||
|
||
#[cfg(not(windows))] | ||
use std::os::fd::{AsFd, OwnedFd}; | ||
#[cfg(windows)] | ||
use std::os::windows::io::{AsHandle, OwnedHandle}; | ||
use std::{ | ||
fs::{File, OpenOptions}, | ||
io, | ||
path::Path, | ||
process::Stdio, | ||
}; | ||
|
||
#[cfg(windows)] | ||
type NativeType = OwnedHandle; | ||
#[cfg(not(windows))] | ||
type NativeType = OwnedFd; | ||
|
||
/// abstraction wrapper for native file handle / file descriptor | ||
pub struct OwnedFileDescriptorOrHandle { | ||
fx: NativeType, | ||
} | ||
|
||
impl OwnedFileDescriptorOrHandle { | ||
/// create from underlying native type | ||
pub fn new(x: NativeType) -> Self { | ||
Self { fx: x } | ||
} | ||
|
||
/// create by opening a file | ||
pub fn open_file(options: &OpenOptions, path: &Path) -> io::Result<Self> { | ||
let f = options.open(path)?; | ||
Self::from(f) | ||
} | ||
|
||
/// conversion from borrowed native type | ||
/// | ||
/// e.g. `std::io::stdout()`, `std::fs::File`, ... | ||
#[cfg(windows)] | ||
pub fn from<T: AsHandle>(t: T) -> io::Result<Self> { | ||
Ok(Self { | ||
fx: t.as_handle().try_clone_to_owned()?, | ||
}) | ||
} | ||
|
||
/// conversion from borrowed native type | ||
/// | ||
/// e.g. `std::io::stdout()`, `std::fs::File`, ... | ||
#[cfg(not(windows))] | ||
pub fn from<T: AsFd>(t: T) -> io::Result<Self> { | ||
Ok(Self { | ||
fx: t.as_fd().try_clone_to_owned()?, | ||
}) | ||
} | ||
|
||
/// instantiates a corresponding `File` | ||
pub fn into_file(self) -> File { | ||
File::from(self.fx) | ||
} | ||
|
||
/// instantiates a corresponding `Stdio` | ||
pub fn into_stdio(self) -> Stdio { | ||
Stdio::from(self.fx) | ||
} | ||
|
||
/// clones self. useful when needing another | ||
/// owned reference to same file | ||
pub fn try_clone(&self) -> io::Result<Self> { | ||
self.fx.try_clone().map(Self::new) | ||
} | ||
|
||
/// provides native type to be used with | ||
/// OS specific functions without abstraction | ||
pub fn as_raw(&self) -> &NativeType { | ||
&self.fx | ||
} | ||
} | ||
|
||
/// instantiates a corresponding `Stdio` | ||
impl From<OwnedFileDescriptorOrHandle> for Stdio { | ||
fn from(value: OwnedFileDescriptorOrHandle) -> Self { | ||
value.into_stdio() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please document it?
As it will be part of the API like:
https://docs.rs/uucore/0.0.24/uucore/error/index.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats cool.
I added some documentation.
Thanks.