diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-05-16 22:35:59 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-05-16 22:35:59 +0000 |
commit | 1fb7961e081f43fcfdb12bc588cc294115841f9c (patch) | |
tree | b45f4fcd8aaac0b753a2ab3272e1453a419f0179 /coreutils/sum.c | |
parent | b2312e9901d1ed03e769b22bbdeda8055b692675 (diff) | |
download | busybox-w32-1fb7961e081f43fcfdb12bc588cc294115841f9c.tar.gz busybox-w32-1fb7961e081f43fcfdb12bc588cc294115841f9c.tar.bz2 busybox-w32-1fb7961e081f43fcfdb12bc588cc294115841f9c.zip |
use more busybox functions and remove redundant code
Diffstat (limited to 'coreutils/sum.c')
-rw-r--r-- | coreutils/sum.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/coreutils/sum.c b/coreutils/sum.c index 2618648b2..d68043cf3 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c | |||
@@ -56,11 +56,9 @@ static int bsd_sum_file(const char *file, int print_name) | |||
56 | fp = stdin; | 56 | fp = stdin; |
57 | have_read_stdin = 1; | 57 | have_read_stdin = 1; |
58 | } else { | 58 | } else { |
59 | fp = fopen(file, "r"); | 59 | fp = bb_wfopen(file, "r"); |
60 | if (fp == NULL) { | 60 | if (fp == NULL) |
61 | bb_perror_msg("%s", file); | ||
62 | return 0; | 61 | return 0; |
63 | } | ||
64 | } | 62 | } |
65 | 63 | ||
66 | while ((ch = getc(fp)) != EOF) { | 64 | while ((ch = getc(fp)) != EOF) { |
@@ -71,22 +69,22 @@ static int bsd_sum_file(const char *file, int print_name) | |||
71 | } | 69 | } |
72 | 70 | ||
73 | if (ferror(fp)) { | 71 | if (ferror(fp)) { |
74 | bb_perror_msg("%s", file); | 72 | bb_perror_msg(file); |
75 | if (!IS_STDIN(file)) | 73 | bb_fclose_nonstdin(fp); |
76 | fclose(fp); | ||
77 | return 0; | 74 | return 0; |
78 | } | 75 | } |
79 | 76 | ||
80 | if (!IS_STDIN(file) && fclose(fp) == EOF) { | 77 | if (bb_fclose_nonstdin(fp) == EOF) { |
81 | bb_perror_msg("%s", file); | 78 | bb_perror_msg(file); |
82 | return 0; | 79 | return 0; |
83 | } | 80 | } |
84 | 81 | ||
85 | printf("%05d %5s", checksum, | 82 | printf("%05d %5s ", checksum, |
86 | make_human_readable_str(total_bytes, 1, 1024)); | 83 | make_human_readable_str(total_bytes, 1, 1024)); |
87 | if (print_name > 1) | 84 | if (print_name > 1) |
88 | printf(" %s", file); | 85 | puts(file); |
89 | putchar('\n'); | 86 | else |
87 | printf("\n"); | ||
90 | 88 | ||
91 | return 1; | 89 | return 1; |
92 | } | 90 | } |
@@ -112,7 +110,7 @@ static int sysv_sum_file(const char *file, int print_name) | |||
112 | } else { | 110 | } else { |
113 | fd = open(file, O_RDONLY); | 111 | fd = open(file, O_RDONLY); |
114 | if (fd == -1) { | 112 | if (fd == -1) { |
115 | bb_perror_msg("%s", file); | 113 | bb_perror_msg(file); |
116 | return 0; | 114 | return 0; |
117 | } | 115 | } |
118 | } | 116 | } |
@@ -125,7 +123,7 @@ static int sysv_sum_file(const char *file, int print_name) | |||
125 | break; | 123 | break; |
126 | 124 | ||
127 | if (bytes_read == -1) { | 125 | if (bytes_read == -1) { |
128 | bb_perror_msg("%s", file); | 126 | bb_perror_msg(file); |
129 | if (!IS_STDIN(file)) | 127 | if (!IS_STDIN(file)) |
130 | close(fd); | 128 | close(fd); |
131 | return 0; | 129 | return 0; |
@@ -137,18 +135,19 @@ static int sysv_sum_file(const char *file, int print_name) | |||
137 | } | 135 | } |
138 | 136 | ||
139 | if (!IS_STDIN(file) && close(fd) == -1) { | 137 | if (!IS_STDIN(file) && close(fd) == -1) { |
140 | bb_perror_msg("%s", file); | 138 | bb_perror_msg(file); |
141 | return 0; | 139 | return 0; |
142 | } | 140 | } |
143 | 141 | ||
144 | r = (s & 0xffff) + ((s & 0xffffffff) >> 16); | 142 | r = (s & 0xffff) + ((s & 0xffffffff) >> 16); |
145 | checksum = (r & 0xffff) + (r >> 16); | 143 | checksum = (r & 0xffff) + (r >> 16); |
146 | 144 | ||
147 | printf("%d %s", checksum, | 145 | printf("%d %s ", checksum, |
148 | make_human_readable_str(total_bytes, 1, 512)); | 146 | make_human_readable_str(total_bytes, 1, 512)); |
149 | if (print_name) | 147 | if (print_name) |
150 | printf(" %s", file); | 148 | puts(file); |
151 | putchar('\n'); | 149 | else |
150 | printf("\n"); | ||
152 | 151 | ||
153 | return 1; | 152 | return 1; |
154 | } | 153 | } |