1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 20:47:46 +00:00

cksum: code improvements for cksum --raw --algorithm

This commit is contained in:
D9nni 2024-01-10 15:15:23 +02:00
parent c7b15ddce9
commit 911df1d76c

View file

@ -176,27 +176,21 @@ where
.map_err_context(|| "failed to read input".to_string())?; .map_err_context(|| "failed to read input".to_string())?;
if options.raw { if options.raw {
match options.algo_name { let bytes = match options.algo_name {
ALGORITHM_OPTIONS_CRC ALGORITHM_OPTIONS_CRC => {
| ALGORITHM_OPTIONS_SYSV
| ALGORITHM_OPTIONS_BSD => {
let bytes = sum.parse::<u32>().unwrap().to_be_bytes(); let bytes = sum.parse::<u32>().unwrap().to_be_bytes();
let mut first_nonzero = 0; bytes.to_vec()
for byte in bytes {
if byte != 0 {
break;
} }
first_nonzero += 1; ALGORITHM_OPTIONS_SYSV | ALGORITHM_OPTIONS_BSD => {
} let bytes = sum.parse::<u16>().unwrap().to_be_bytes();
stdout().write_all(&bytes[first_nonzero..])?; bytes.to_vec()
} }
_ => { _ => {
let bytes = decode(sum).unwrap(); let bytes = decode(sum).unwrap();
bytes
}
};
stdout().write_all(&bytes)?; stdout().write_all(&bytes)?;
}
}
return Ok(()); return Ok(());
} }
// The BSD checksum output is 5 digit integer // The BSD checksum output is 5 digit integer