cksum: fixed cksum --raw --algorithm

This commit is contained in:
D9nni
2024-01-10 15:04:19 +02:00
parent 96271ffa3c
commit c7b15ddce9
2 changed files with 18 additions and 7 deletions
+17 -6
View File
@@ -176,16 +176,27 @@ where
.map_err_context(|| "failed to read input".to_string())?;
if options.raw {
match decode(sum.clone()) {
Ok(bytes) => {
stdout().write_all(&bytes)?;
}
Err(_) => {
//bsd, sysv and crc have output generated without encode()
match options.algo_name {
ALGORITHM_OPTIONS_CRC
| ALGORITHM_OPTIONS_SYSV
| ALGORITHM_OPTIONS_BSD => {
let bytes = sum.parse::<u32>().unwrap().to_be_bytes();
let mut first_nonzero = 0;
for byte in bytes {
if byte != 0 {
break;
}
first_nonzero += 1;
}
stdout().write_all(&bytes[first_nonzero..])?;
}
_ =>{
let bytes = decode(sum).unwrap();
stdout().write_all(&bytes)?;
}
}
return Ok(());
}
// The BSD checksum output is 5 digit integer
+1 -1
View File
@@ -1 +1 @@
`x fWEtBlW^J0aX´85B9m
— ‘‰å`Ãxœ ÿf†øWÑûþEtÞBãÀl«¹W^Jö0šaX´ÓÀ8Á´‚‹5BÍÀ9m•Ã