aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-06-07 17:38:33 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-06-07 17:38:33 +0000
commita721204ec502238198b5703cfea99fd97cbca266 (patch)
tree431ea4e9635339feefe6ff6a94b031c0c14a62e6
parenta9e4617494537a65ecc711003414a4f97eaad8cc (diff)
downloadbusybox-w32-a721204ec502238198b5703cfea99fd97cbca266.tar.gz
busybox-w32-a721204ec502238198b5703cfea99fd97cbca266.tar.bz2
busybox-w32-a721204ec502238198b5703cfea99fd97cbca266.zip
Better error handling
-rw-r--r--coreutils/sha1sum.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/coreutils/sha1sum.c b/coreutils/sha1sum.c
index c6534b5cb..1c31e3c55 100644
--- a/coreutils/sha1sum.c
+++ b/coreutils/sha1sum.c
@@ -112,7 +112,7 @@ static void sha_hash(unsigned int *data, int *hash)
112 hash[4] += e; 112 hash[4] += e;
113} 113}
114 114
115static void sha1sum_stream(FILE *fd, unsigned int *hashval) 115static char sha1sum_stream(FILE *fd, unsigned int *hashval)
116{ 116{
117 RESERVE_CONFIG_BUFFER(buffer, 64); 117 RESERVE_CONFIG_BUFFER(buffer, 64);
118 int length = 0; 118 int length = 0;
@@ -145,7 +145,7 @@ static void sha1sum_stream(FILE *fd, unsigned int *hashval)
145 145
146 RELEASE_CONFIG_BUFFER(buffer); 146 RELEASE_CONFIG_BUFFER(buffer);
147 147
148 return; 148 return(EXIT_SUCCESS);
149} 149}
150 150
151static void print_hash(unsigned int *hash_value, unsigned char hash_length, unsigned char *filename) 151static void print_hash(unsigned int *hash_value, unsigned char hash_length, unsigned char *filename)
@@ -167,11 +167,12 @@ static void print_hash(unsigned int *hash_value, unsigned char hash_length, unsi
167/* This should become a common function used by sha1sum and md5sum, 167/* This should become a common function used by sha1sum and md5sum,
168 * it needs extra functionality first 168 * it needs extra functionality first
169 */ 169 */
170extern int authenticate(int argc, char **argv, void (*hash_ptr)(FILE *stream, unsigned int *hashval), const unsigned char hash_length) 170extern int authenticate(int argc, char **argv, char (*hash_ptr)(FILE *stream, unsigned int *hashval), const unsigned char hash_length)
171{ 171{
172 unsigned int hash_value[hash_length]; 172 unsigned int hash_value[hash_length];
173 unsigned char flags = 0; 173 unsigned char flags = 0;
174 int opt; 174 int opt;
175 int return_value;
175 176
176 while ((opt = getopt(argc, argv, "sc:w")) != -1) { 177 while ((opt = getopt(argc, argv, "sc:w")) != -1) {
177 switch (opt) { 178 switch (opt) {
@@ -193,31 +194,37 @@ extern int authenticate(int argc, char **argv, void (*hash_ptr)(FILE *stream, un
193 argv[argc++] = "-"; 194 argv[argc++] = "-";
194 } 195 }
195 196
197 return_value = EXIT_SUCCESS;
196 while (optind < argc) { 198 while (optind < argc) {
197 FILE *stream; 199 FILE *stream;
198 unsigned char *file_ptr = argv[optind]; 200 unsigned char *file_ptr = argv[optind];
199 201
202 optind++;
203
200 if ((file_ptr[0] == '-') && (file_ptr[1] == '\0')) { 204 if ((file_ptr[0] == '-') && (file_ptr[1] == '\0')) {
201 stream = stdin; 205 stream = stdin;
202 } else { 206 } else {
203 stream = bb_wfopen(file_ptr, "r"); 207 stream = bb_wfopen(file_ptr, "r");
204 if (stream == NULL) { 208 if (stream == NULL) {
205 return(EXIT_FAILURE); 209 return_value = EXIT_FAILURE;
210 continue;
206 } 211 }
207 } 212 }
208 hash_ptr(stream, hash_value); 213 if (hash_ptr(stream, hash_value) == EXIT_FAILURE) {
209 if (!flags & FLAG_SILENT) { 214 return_value = EXIT_FAILURE;
215 }
216 else if (!flags & FLAG_SILENT) {
210 print_hash(hash_value, hash_length, file_ptr); 217 print_hash(hash_value, hash_length, file_ptr);
211 } 218 }
212 219
213 if (fclose(stream) == EOF) { 220 if (fclose(stream) == EOF) {
214 bb_perror_msg_and_die("Couldnt close file %s", file_ptr); 221 bb_perror_msg("Couldnt close file %s", file_ptr);
222 return_value = EXIT_FAILURE;
215 } 223 }
216 224
217 optind++;
218 } 225 }
219 226
220 return(EXIT_SUCCESS); 227 return(return_value);
221} 228}
222 229
223extern int sha1sum_main(int argc, char **argv) 230extern int sha1sum_main(int argc, char **argv)