aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-06-22 10:21:47 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-06-22 10:24:06 +0200
commit91b9549a8c739e5f0061dffb292d0dedbe913892 (patch)
tree858ef3713adc455c7234b4bff4a096de778420aa
parent836580a7d690dcdade82ce6bdd1f172af1417d0e (diff)
downloadbusybox-w32-91b9549a8c739e5f0061dffb292d0dedbe913892.tar.gz
busybox-w32-91b9549a8c739e5f0061dffb292d0dedbe913892.tar.bz2
busybox-w32-91b9549a8c739e5f0061dffb292d0dedbe913892.zip
crc32: code shrink for !CKSUM config
function old new delta cksum_main 215 203 -12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/cksum.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/coreutils/cksum.c b/coreutils/cksum.c
index 6b601b752..83b7e3238 100644
--- a/coreutils/cksum.c
+++ b/coreutils/cksum.c
@@ -51,7 +51,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
51 setup_common_bufsiz(); 51 setup_common_bufsiz();
52 do { 52 do {
53 uint32_t crc; 53 uint32_t crc;
54 off_t filesize; 54 IF_CKSUM(off_t filesize;)
55 const char *fname = *argv ? *argv : bb_msg_standard_input; 55 const char *fname = *argv ? *argv : bb_msg_standard_input;
56 int fd = open_or_warn_stdin(fname); 56 int fd = open_or_warn_stdin(fname);
57 57
@@ -61,37 +61,43 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
61 } 61 }
62 62
63 crc = IS_CKSUM ? 0 : 0xffffffff; 63 crc = IS_CKSUM ? 0 : 0xffffffff;
64 filesize = 0; 64 IF_CKSUM(filesize = 0;)
65#define read_buf bb_common_bufsiz1 65#define read_buf bb_common_bufsiz1
66 for (;;) { 66 for (;;) {
67 int bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE); 67 int bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE);
68 if (bytes_read < 0) 68 if (bytes_read < 0)
69 bb_simple_perror_msg_and_die(fname); 69 bb_simple_perror_msg_and_die(fname);
70 if (bytes_read > 0) { 70 if (bytes_read > 0) {
71 filesize += bytes_read; 71 IF_CKSUM(filesize += bytes_read;)
72 } else { 72 } else {
73 IF_CKSUM(uoff_t t;)
74
73 close(fd); 75 close(fd);
76 if (IS_CRC32)
77 break;
78#if ENABLE_CKSUM
74 fd = -1; /* break flag */ 79 fd = -1; /* break flag */
75 /* Checksum filesize bytes, LSB first */ 80 /* Checksum filesize bytes, LSB first */
76 if (IS_CKSUM) { 81 t = filesize;
77 uoff_t t = filesize; 82 /*bytes_read = 0; - already is */
78 bytes_read = 0; 83 while (t != 0) {
79 while (t != 0) { 84 read_buf[bytes_read++] = (uint8_t)t;
80 read_buf[bytes_read++] = (uint8_t)t; 85 t >>= 8;
81 t >>= 8;
82 }
83 } 86 }
87#endif
84 } 88 }
85 crc = (IS_CKSUM ? crc32_block_endian1 : crc32_block_endian0)(crc, read_buf, bytes_read, crc32_table); 89 crc = (IS_CKSUM ? crc32_block_endian1 : crc32_block_endian0)(crc, read_buf, bytes_read, crc32_table);
86 if (fd < 0) 90 if (ENABLE_CKSUM && fd < 0)
87 break; 91 break;
88 } 92 }
89 93
90 crc = ~crc; 94 crc = ~crc;
95#if ENABLE_CKSUM
91 if (IS_CKSUM) 96 if (IS_CKSUM)
92 printf((*argv ? "%u %"OFF_FMT"u %s\n" : "%u %"OFF_FMT"u\n"), 97 printf((*argv ? "%u %"OFF_FMT"u %s\n" : "%u %"OFF_FMT"u\n"),
93 (unsigned)crc, filesize, *argv); 98 (unsigned)crc, filesize, *argv);
94 else 99 else
100#endif
95 printf((*argv ? "%08x %s\n" : "%08x\n"), 101 printf((*argv ? "%08x %s\n" : "%08x\n"),
96 (unsigned)crc, *argv); 102 (unsigned)crc, *argv);
97 } while (*argv && *++argv); 103 } while (*argv && *++argv);