diff options
-rw-r--r-- | coreutils/md5_sha1_sum.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index 626dcee56..633b6e534 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * Copyright (C) 2003 Glenn L. McGrath | 3 | * Copyright (C) 2003 Glenn L. McGrath |
3 | * Copyright (C) 2003-2004 Erik Andersen | 4 | * Copyright (C) 2003-2004 Erik Andersen |
@@ -47,45 +48,44 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo) | |||
47 | RESERVE_CONFIG_UBUFFER(in_buf, 4096); | 48 | RESERVE_CONFIG_UBUFFER(in_buf, 4096); |
48 | void (*update)(const void*, size_t, void*); | 49 | void (*update)(const void*, size_t, void*); |
49 | void (*final)(void*, void*); | 50 | void (*final)(void*, void*); |
50 | 51 | ||
51 | if(strcmp(filename, "-") == 0) { | 52 | if (strcmp(filename, "-") == 0) { |
52 | src_fd = STDIN_FILENO; | 53 | src_fd = STDIN_FILENO; |
53 | } else if(0 > (src_fd = open(filename, O_RDONLY))) { | 54 | } else if(0 > (src_fd = open(filename, O_RDONLY))) { |
54 | bb_perror_msg("%s", filename); | 55 | bb_perror_msg("%s", filename); |
55 | return NULL; | 56 | return NULL; |
56 | } | 57 | } |
57 | 58 | ||
58 | // figure specific hash algorithims | 59 | /* figure specific hash algorithims */ |
59 | if(ENABLE_MD5SUM && hash_algo==HASH_MD5) { | 60 | if (ENABLE_MD5SUM && hash_algo==HASH_MD5) { |
60 | md5_begin(&context.md5); | 61 | md5_begin(&context.md5); |
61 | update = (void (*)(const void*, size_t, void*))md5_hash; | 62 | update = (void (*)(const void*, size_t, void*))md5_hash; |
62 | final = (void (*)(void*, void*))md5_end; | 63 | final = (void (*)(void*, void*))md5_end; |
63 | hash_len = 16; | 64 | hash_len = 16; |
64 | } else if(ENABLE_SHA1SUM && hash_algo==HASH_SHA1) { | 65 | } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) { |
65 | sha1_begin(&context.sha1); | 66 | sha1_begin(&context.sha1); |
66 | update = (void (*)(const void*, size_t, void*))sha1_hash; | 67 | update = (void (*)(const void*, size_t, void*))sha1_hash; |
67 | final = (void (*)(void*, void*))sha1_end; | 68 | final = (void (*)(void*, void*))sha1_end; |
68 | hash_len = 20; | 69 | hash_len = 20; |
69 | } else { | 70 | } else { |
70 | bb_error_msg_and_die("algotithm not supported"); | 71 | bb_error_msg_and_die("algorithm not supported"); |
71 | } | 72 | } |
72 | |||
73 | 73 | ||
74 | while(0 < (count = read(src_fd, in_buf, sizeof in_buf))) { | 74 | while (0 < (count = read(src_fd, in_buf, sizeof in_buf))) { |
75 | update(in_buf, count, &context); | 75 | update(in_buf, count, &context); |
76 | } | 76 | } |
77 | 77 | ||
78 | if(count == 0) { | 78 | if (count == 0) { |
79 | final(in_buf, &context); | 79 | final(in_buf, &context); |
80 | hash_value = hash_bin_to_hex(in_buf, hash_len); | 80 | hash_value = hash_bin_to_hex(in_buf, hash_len); |
81 | } | 81 | } |
82 | 82 | ||
83 | RELEASE_CONFIG_BUFFER(in_buf); | 83 | RELEASE_CONFIG_BUFFER(in_buf); |
84 | 84 | ||
85 | if(src_fd != STDIN_FILENO) { | 85 | if (src_fd != STDIN_FILENO) { |
86 | close(src_fd); | 86 | close(src_fd); |
87 | } | 87 | } |
88 | 88 | ||
89 | return hash_value; | 89 | return hash_value; |
90 | } | 90 | } |
91 | 91 | ||
@@ -112,7 +112,7 @@ static int hash_files(int argc, char **argv, hash_algo_t hash_algo) | |||
112 | if (argc == optind) { | 112 | if (argc == optind) { |
113 | argv[argc++] = "-"; | 113 | argv[argc++] = "-"; |
114 | } | 114 | } |
115 | 115 | ||
116 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && flags & FLAG_CHECK) { | 116 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && flags & FLAG_CHECK) { |
117 | FILE *pre_computed_stream; | 117 | FILE *pre_computed_stream; |
118 | int count_total = 0; | 118 | int count_total = 0; |
@@ -189,13 +189,13 @@ static int hash_files(int argc, char **argv, hash_algo_t hash_algo) | |||
189 | #ifdef CONFIG_MD5SUM | 189 | #ifdef CONFIG_MD5SUM |
190 | int md5sum_main(int argc, char **argv) | 190 | int md5sum_main(int argc, char **argv) |
191 | { | 191 | { |
192 | return(hash_files(argc, argv, HASH_MD5)); | 192 | return (hash_files(argc, argv, HASH_MD5)); |
193 | } | 193 | } |
194 | #endif | 194 | #endif |
195 | 195 | ||
196 | #ifdef CONFIG_SHA1SUM | 196 | #ifdef CONFIG_SHA1SUM |
197 | int sha1sum_main(int argc, char **argv) | 197 | int sha1sum_main(int argc, char **argv) |
198 | { | 198 | { |
199 | return(hash_files(argc, argv, HASH_SHA1)); | 199 | return (hash_files(argc, argv, HASH_SHA1)); |
200 | } | 200 | } |
201 | #endif | 201 | #endif |