Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/coreutils/cksum.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/coreutils/cksum.c
r821 r1770 4 4 * 5 5 * Copyright (C) 2006 by Rob Sullivan, with ideas from code by Walter Harms 6 * 6 * 7 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ 8 8 9 #include <stdio.h> 10 #include <unistd.h> 11 #include <fcntl.h> 12 #include "busybox.h" 9 #include "libbb.h" 13 10 14 int cksum_main(int argc, char **argv) { 15 16 uint32_t *crc32_table = bb_crc32_filltable(1); 11 int cksum_main(int argc, char **argv); 12 int cksum_main(int argc, char **argv) 13 { 14 uint32_t *crc32_table = crc32_filltable(NULL, 1); 17 15 18 16 FILE *fp; … … 21 19 int bytes_read; 22 20 char *cp; 23 RESERVE_CONFIG_BUFFER(buf, BUFSIZ); 21 24 22 int inp_stdin = (argc == optind) ? 1 : 0; 25 23 26 24 do { 27 fp = bb_wfopen_input((inp_stdin) ? bb_msg_standard_input : *++argv);28 25 fp = fopen_or_warn_stdin((inp_stdin) ? bb_msg_standard_input : *++argv); 26 29 27 crc = 0; 30 28 length = 0; 31 32 while ((bytes_read = fread(buf, 1, BUFSIZ, fp)) > 0) { 33 cp = buf; 29 30 #define read_buf bb_common_bufsiz1 31 while ((bytes_read = fread(read_buf, 1, BUFSIZ, fp)) > 0) { 32 cp = read_buf; 34 33 length += bytes_read; 35 34 while (bytes_read--) 36 35 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ (*cp++)) & 0xffL]; 37 36 } 38 37 39 38 filesize = length; 40 39 41 40 for (; length; length >>= 8) 42 41 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ length) & 0xffL]; … … 44 43 45 44 if (inp_stdin) { 46 printf("%" PRIu32" %li\n", crc, filesize);45 printf("%" PRIu32 " %li\n", crc, filesize); 47 46 break; 48 47 } 49 50 printf("%" PRIu32" %li %s\n", crc, filesize, *argv);48 49 printf("%" PRIu32 " %li %s\n", crc, filesize, *argv); 51 50 fclose(fp); 52 } while (*(argv +1));53 54 return EXIT_SUCCESS;51 } while (*(argv + 1)); 52 53 fflush_stdout_and_exit(EXIT_SUCCESS); 55 54 }
Note:
See TracChangeset
for help on using the changeset viewer.