summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko2021-06-22 10:21:47 +0200
committerDenys Vlasenko2021-06-22 10:24:06 +0200
commit91b9549a8c739e5f0061dffb292d0dedbe913892 (patch)
tree858ef3713adc455c7234b4bff4a096de778420aa /coreutils
parent836580a7d690dcdade82ce6bdd1f172af1417d0e (diff)
downloadbusybox-91b9549a8c739e5f0061dffb292d0dedbe913892.zip
busybox-91b9549a8c739e5f0061dffb292d0dedbe913892.tar.gz
crc32: code shrink for !CKSUM config
function old new delta cksum_main 215 203 -12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cksum.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/coreutils/cksum.c b/coreutils/cksum.c
index 6b601b7..83b7e32 100644
--- a/coreutils/cksum.c
+++ b/coreutils/cksum.c
@@ -51,7 +51,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
setup_common_bufsiz();
do {
uint32_t crc;
- off_t filesize;
+ IF_CKSUM(off_t filesize;)
const char *fname = *argv ? *argv : bb_msg_standard_input;
int fd = open_or_warn_stdin(fname);
@@ -61,37 +61,43 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
}
crc = IS_CKSUM ? 0 : 0xffffffff;
- filesize = 0;
+ IF_CKSUM(filesize = 0;)
#define read_buf bb_common_bufsiz1
for (;;) {
int bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE);
if (bytes_read < 0)
bb_simple_perror_msg_and_die(fname);
if (bytes_read > 0) {
- filesize += bytes_read;
+ IF_CKSUM(filesize += bytes_read;)
} else {
+ IF_CKSUM(uoff_t t;)
+
close(fd);
+ if (IS_CRC32)
+ break;
+#if ENABLE_CKSUM
fd = -1; /* break flag */
/* Checksum filesize bytes, LSB first */
- if (IS_CKSUM) {
- uoff_t t = filesize;
- bytes_read = 0;
- while (t != 0) {
- read_buf[bytes_read++] = (uint8_t)t;
- t >>= 8;
- }
+ t = filesize;
+ /*bytes_read = 0; - already is */
+ while (t != 0) {
+ read_buf[bytes_read++] = (uint8_t)t;
+ t >>= 8;
}
+#endif
}
crc = (IS_CKSUM ? crc32_block_endian1 : crc32_block_endian0)(crc, read_buf, bytes_read, crc32_table);
- if (fd < 0)
+ if (ENABLE_CKSUM && fd < 0)
break;
}
crc = ~crc;
+#if ENABLE_CKSUM
if (IS_CKSUM)
printf((*argv ? "%u %"OFF_FMT"u %s\n" : "%u %"OFF_FMT"u\n"),
(unsigned)crc, filesize, *argv);
else
+#endif
printf((*argv ? "%08x %s\n" : "%08x\n"),
(unsigned)crc, *argv);
} while (*argv && *++argv);