aboutsummaryrefslogtreecommitdiff
path: root/coreutils/sum.c
diff options
context:
space:
mode:
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 2edd92036..d6a76dbbc 100644
--- a/coreutils/sum.c
+++ b/coreutils/sum.c
@@ -13,12 +13,6 @@
13 * Licensed under the GPL v2, see the file LICENSE in this tarball. 13 * Licensed under the GPL v2, see the file LICENSE in this tarball.
14 */ 14 */
15 15
16#include <stdio.h>
17#include <sys/types.h>
18#include <sys/stat.h>
19#include <fcntl.h>
20#include <unistd.h>
21
22#include "busybox.h" 16#include "busybox.h"
23 17
24/* 1 if any of the files read were the standard input */ 18/* 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)
38 int checksum = 0; /* The checksum mod 2^16. */ 32 int checksum = 0; /* The checksum mod 2^16. */
39 uintmax_t total_bytes = 0; /* The number of bytes. */ 33 uintmax_t total_bytes = 0; /* The number of bytes. */
40 int ch; /* Each character read. */ 34 int ch; /* Each character read. */
35 int ret = 0;
41 36
42 if (IS_STDIN(file)) { 37 if (IS_STDIN(file)) {
43 fp = stdin; 38 fp = stdin;
44 have_read_stdin = 1; 39 have_read_stdin++;
45 } else { 40 } else {
46 fp = bb_wfopen(file, "r"); 41 fp = bb_wfopen(file, "r");
47 if (fp == NULL) 42 if (fp == NULL)
48 return 0; 43 goto out;
49 } 44 }
50 45
51 while ((ch = getc(fp)) != EOF) { 46 while ((ch = getc(fp)) != EOF) {
@@ -58,21 +53,21 @@ static int bsd_sum_file(const char *file, int print_name)
58 if (ferror(fp)) { 53 if (ferror(fp)) {
59 bb_perror_msg(file); 54 bb_perror_msg(file);
60 bb_fclose_nonstdin(fp); 55 bb_fclose_nonstdin(fp);
61 return 0; 56 goto out;
62 } 57 }
63 58
64 if (bb_fclose_nonstdin(fp) == EOF) { 59 if (bb_fclose_nonstdin(fp) == EOF) {
65 bb_perror_msg(file); 60 bb_perror_msg(file);
66 return 0; 61 goto out;
67 } 62 }
68 63 ret++;
69 printf("%05d %5ju ", checksum, (total_bytes+1023)/1024); 64 printf("%05d %5ju ", checksum, (total_bytes+1023)/1024);
70 if (print_name > 1) 65 if (print_name > 1)
71 puts(file); 66 puts(file);
72 else 67 else
73 printf("\n"); 68 printf("\n");
74 69out:
75 return 1; 70 return ret;
76} 71}
77 72
78/* Calculate and print the checksum and the size in 512-byte blocks 73/* Calculate and print the checksum and the size in 512-byte blocks