Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/sum.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/coreutils/sum.c
r1765 r2725 11 11 * Taken from coreutils and turned into a busybox applet by Mike Frysinger 12 12 * 13 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.13 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 14 14 */ 15 15 … … 22 22 /* SYSV: calculate and print the checksum and the size in 512-byte blocks */ 23 23 /* Return 1 if successful. */ 24 static unsigned sum_file(const char *file, constunsigned type)24 static unsigned sum_file(const char *file, unsigned type) 25 25 { 26 26 #define buf bb_common_bufsiz1 27 uintmax_t total_bytes = 0; 28 int fd = 0, r; 29 27 unsigned long long total_bytes = 0; 28 int fd, r; 30 29 /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ 31 30 unsigned s = 0; 32 31 33 if (NOT_LONE_DASH(file)) { 34 fd = open(file, O_RDONLY); 35 if (fd == -1) 36 goto ret_bad; 37 } 32 fd = open_or_warn_stdin(file); 33 if (fd == -1) 34 return 0; 38 35 39 36 while (1) { … … 45 42 /* no error */ 46 43 break; 47 ret_bad: 48 bb_perror_msg(file); 44 bb_simple_perror_msg(file); 49 45 return 0; 50 46 } … … 68 64 r = (s & 0xffff) + ((s & 0xffffffff) >> 16); 69 65 s = (r & 0xffff) + (r >> 16); 70 printf("%d % ju %s\n", s, (total_bytes+511)/512, file);66 printf("%d %llu %s\n", s, (total_bytes + 511) / 512, file); 71 67 } else 72 printf("%05d %5 ju %s\n", s, (total_bytes+1023)/1024, file);68 printf("%05d %5llu %s\n", s, (total_bytes + 1023) / 1024, file); 73 69 return 1; 74 70 #undef buf 75 71 } 76 72 77 int sum_main(int argc, char **argv) ;78 int sum_main(int argc , char **argv)73 int sum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 74 int sum_main(int argc UNUSED_PARAM, char **argv) 79 75 { 80 76 unsigned n; … … 82 78 83 79 n = getopt32(argv, "sr"); 80 argv += optind; 84 81 if (n & 1) type = SUM_SYSV; 85 82 /* give the bsd priority over sysv func */ 86 83 if (n & 2) type = SUM_BSD; 87 84 88 if ( argc == optind) {85 if (!argv[0]) { 89 86 /* Do not print the name */ 90 87 n = sum_file("-", type); … … 93 90 - more than one file given 94 91 - doing sysv */ 95 type += argc - 1 > optind || type == SUM_SYSV; 96 for (n = 1; optind < argc; optind++) 97 n &= sum_file(argv[optind], type); 92 type += (argv[1] || type == SUM_SYSV); 93 n = 1; 94 do { 95 n &= sum_file(*argv, type); 96 } while (*++argv); 98 97 } 99 98 return !n;
Note:
See TracChangeset
for help on using the changeset viewer.