diff options
Diffstat (limited to 'coreutils/cksum.c')
-rw-r--r-- | coreutils/cksum.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/coreutils/cksum.c b/coreutils/cksum.c index 5849ddab2..9a45fd656 100644 --- a/coreutils/cksum.c +++ b/coreutils/cksum.c | |||
@@ -3,12 +3,13 @@ | |||
3 | * cksum - calculate the CRC32 checksum of a file | 3 | * cksum - calculate the CRC32 checksum of a file |
4 | * | 4 | * |
5 | * Copyright (C) 2006 by Rob Sullivan, with ideas from code by Walter Harms | 5 | * Copyright (C) 2006 by Rob Sullivan, with ideas from code by Walter Harms |
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ |
8 | 8 | ||
9 | #include "busybox.h" | 9 | #include "busybox.h" |
10 | 10 | ||
11 | int cksum_main(int argc, char **argv) { | 11 | int cksum_main(int argc, char **argv) |
12 | { | ||
12 | 13 | ||
13 | uint32_t *crc32_table = crc32_filltable(1); | 14 | uint32_t *crc32_table = crc32_filltable(1); |
14 | 15 | ||
@@ -17,36 +18,36 @@ int cksum_main(int argc, char **argv) { | |||
17 | long length, filesize; | 18 | long length, filesize; |
18 | int bytes_read; | 19 | int bytes_read; |
19 | char *cp; | 20 | char *cp; |
20 | RESERVE_CONFIG_BUFFER(buf, BUFSIZ); | 21 | |
21 | int inp_stdin = (argc == optind) ? 1 : 0; | 22 | int inp_stdin = (argc == optind) ? 1 : 0; |
22 | 23 | ||
23 | do { | 24 | do { |
24 | fp = bb_wfopen_input((inp_stdin) ? bb_msg_standard_input : *++argv); | 25 | fp = bb_wfopen_input((inp_stdin) ? bb_msg_standard_input : *++argv); |
25 | 26 | ||
26 | crc = 0; | 27 | crc = 0; |
27 | length = 0; | 28 | length = 0; |
28 | 29 | ||
29 | while ((bytes_read = fread(buf, 1, BUFSIZ, fp)) > 0) { | 30 | while ((bytes_read = fread(bb_common_bufsiz1, 1, BUFSIZ, fp)) > 0) { |
30 | cp = buf; | 31 | cp = bb_common_bufsiz1; |
31 | length += bytes_read; | 32 | length += bytes_read; |
32 | while (bytes_read--) | 33 | while (bytes_read--) |
33 | crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ (*cp++)) & 0xffL]; | 34 | crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ (*cp++)) & 0xffL]; |
34 | } | 35 | } |
35 | 36 | ||
36 | filesize = length; | 37 | filesize = length; |
37 | 38 | ||
38 | for (; length; length >>= 8) | 39 | for (; length; length >>= 8) |
39 | crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ length) & 0xffL]; | 40 | crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ length) & 0xffL]; |
40 | crc ^= 0xffffffffL; | 41 | crc ^= 0xffffffffL; |
41 | 42 | ||
42 | if (inp_stdin) { | 43 | if (inp_stdin) { |
43 | printf("%"PRIu32" %li\n", crc, filesize); | 44 | bb_printf("%" PRIu32 " %li\n", crc, filesize); |
44 | break; | 45 | break; |
45 | } | 46 | } |
46 | 47 | ||
47 | printf("%"PRIu32" %li %s\n", crc, filesize, *argv); | 48 | bb_printf("%" PRIu32 " %li %s\n", crc, filesize, *argv); |
48 | fclose(fp); | 49 | fclose(fp); |
49 | } while (*(argv+1)); | 50 | } while (*(argv + 1)); |
50 | 51 | ||
51 | return EXIT_SUCCESS; | 52 | return EXIT_SUCCESS; |
52 | } | 53 | } |