summaryrefslogtreecommitdiff
path: root/coreutils/sum.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer2006-08-28 23:31:54 +0000
committerBernhard Reutner-Fischer2006-08-28 23:31:54 +0000
commit73561cc75ac31e63bcab4b4ebfaf738e4ca225e6 (patch)
tree2a57564b8917a983365c765d4daa83032d9f0a17 /coreutils/sum.c
parent6ce8dae1d5a201156a83201de6c49cdcc4c8df3e (diff)
downloadbusybox-73561cc75ac31e63bcab4b4ebfaf738e4ca225e6.zip
busybox-73561cc75ac31e63bcab4b4ebfaf738e4ca225e6.tar.gz
- pull from busybox_scratch: r15829:15850
Various fixes, cleanups and shrinkage: saves 952 Bytes: text data bss dec hex filename 1087742 15853 790632 1894227 1ce753 ../busybox/busybox.old 1086790 15853 790632 1893275 1ce39b busybox via: # scripts/bloat-o-meter ../busybox/busybox_unstripped.old busybox_unstripped function old new delta ipcrm_main 756 822 +66 getval - 61 +61 maybe_set_utc - 40 +40 udhcpc_main 2896 2912 +16 md5_hash_block 428 437 +9 opt 8 16 +8 qgravechar 106 110 +4 make_bitmap 292 295 +3 inflate_unzip 2056 2059 +3 add_partition 1412 1414 +2 __parsespent 156 158 +2 qrealloc 41 42 +1 format - 1 +1 catv_main 313 314 +1 watch_main 293 292 -1 varunset 81 80 -1 part 1 - -1 check_if_skip 837 836 -1 start_stop_daemon_main 840 837 -3 create_lost_and_found 175 172 -3 supress_non_delimited_lines 4 - -4 static.l 4 - -4 static.c 5 1 -4 bsd_sum_file 237 233 -4 eval2 338 332 -6 arithmetic_common 166 158 -8 cmpfunc 22 5 -17 cksum_main 294 275 -19 cmp_main 465 439 -26 dd_main 1535 1508 -27 rmmod_main 376 333 -43 cut_file 727 644 -83 ipcs_main 3809 3721 -88 cut_main 722 614 -108 date_main 1443 1263 -180 remove_ids 222 - -222 ------------------------------------------------------------------------------ (add/remove: 3/4 grow/shrink: 11/18 up/down: 217/-853) Total: -636 bytes
Diffstat (limited to 'coreutils/sum.c')
-rw-r--r--coreutils/sum.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/coreutils/sum.c b/coreutils/sum.c
index 2edd920..d6a76db 100644
--- a/coreutils/sum.c
+++ b/coreutils/sum.c
@@ -13,12 +13,6 @@
* Licensed under the GPL v2, see the file LICENSE in this tarball.
*/
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
#include "busybox.h"
/* 1 if any of the files read were the standard input */
@@ -38,14 +32,15 @@ static int bsd_sum_file(const char *file, int print_name)
int checksum = 0; /* The checksum mod 2^16. */
uintmax_t total_bytes = 0; /* The number of bytes. */
int ch; /* Each character read. */
+ int ret = 0;
if (IS_STDIN(file)) {
fp = stdin;
- have_read_stdin = 1;
+ have_read_stdin++;
} else {
fp = bb_wfopen(file, "r");
if (fp == NULL)
- return 0;
+ goto out;
}
while ((ch = getc(fp)) != EOF) {
@@ -58,21 +53,21 @@ static int bsd_sum_file(const char *file, int print_name)
if (ferror(fp)) {
bb_perror_msg(file);
bb_fclose_nonstdin(fp);
- return 0;
+ goto out;
}
if (bb_fclose_nonstdin(fp) == EOF) {
bb_perror_msg(file);
- return 0;
+ goto out;
}
-
+ ret++;
printf("%05d %5ju ", checksum, (total_bytes+1023)/1024);
if (print_name > 1)
puts(file);
else
printf("\n");
-
- return 1;
+out:
+ return ret;
}
/* Calculate and print the checksum and the size in 512-byte blocks