-
-
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: allow B as a suffix for count, seek, and skip #4137
Conversation
GNU testsuite comparison:
|
Looks like this doesn't quite work as-is:
|
Maybe we could report it back to GNU? Seems like an oversight on their part to not support On our end, fn parse_byte_count(input: &str) -> Result<usize, ParseSizeError> {
// GNU sort (8.32) valid: 1b, k, K, m, M, g, G, t, T, P, E, Z, Y
// GNU sort (8.32) invalid: b, B, 1B, p, e, z, y
const ALLOW_LIST: &[char] = &[
'b', 'k', 'K', 'm', 'M', 'g', 'G', 't', 'T', 'P', 'E', 'Z', 'Y',
];
let mut size_string = input.trim().to_string();
if size_string.ends_with(|c: char| ALLOW_LIST.contains(&c) || c.is_ascii_digit()) {
// b 1, K 1024 (default)
if size_string.ends_with(|c: char| c.is_ascii_digit()) {
size_string.push('K');
} else if size_string.ends_with('b') {
size_string.pop();
}
let size = parse_size(&size_string)?;
usize::try_from(size).map_err(|_| {
ParseSizeError::SizeTooBig(format!(
"Buffer size {} does not fit in address space",
size
))
})
} else if size_string.starts_with(|c: char| c.is_ascii_digit()) {
Err(ParseSizeError::InvalidSuffix("invalid suffix".to_string()))
} else {
Err(ParseSizeError::ParseFailure("parse failure".to_string()))
}
} We'd need some configuration on what the allowed suffixes are, what the default factor is etc. |
976720a
to
cb909c4
Compare
GNU testsuite comparison:
|
Add a `uucore::parse_size::Parser` struct which will allow future commits to add fields that change the behavior of `parse_size()`.
Allow uppercase "B" on its own as a unit specifier for the `count`, `seek`, and `skip` arguments to `dd`. For example, $ printf "abcdef" | dd count=3B status=none abc
cb909c4
to
701550d
Compare
Okay, I've updated this pull request to add a |
GNU testsuite comparison:
|
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.
Even better than what I had in mind!
Allow uppercase "B" on its own as a unit specifier for the
count
,seek
, andskip
arguments todd
.For example,
This should fix GNU test suite file
tests/dd/bytes.sh
.