diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-04-29 02:39:33 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-04-29 02:39:33 +0000 |
commit | 6d616545ae56cb762cff38b7262258a1fda04732 (patch) | |
tree | 7fa1837a9a28e654599809ecc25f5adf0c107a77 /lib/libc/hash/helper.c | |
parent | 48aee63b37d493ee0a8f116cfe010e7a5298dbab (diff) |
Some KNF
Diffstat (limited to 'lib/libc/hash/helper.c')
-rw-r--r-- | lib/libc/hash/helper.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/lib/libc/hash/helper.c b/lib/libc/hash/helper.c index f7dd752dcf1..5a64c3c84fd 100644 --- a/lib/libc/hash/helper.c +++ b/lib/libc/hash/helper.c @@ -1,4 +1,4 @@ -/* $OpenBSD: helper.c,v 1.1 2004/04/26 19:38:12 millert Exp $ */ +/* $OpenBSD: helper.c,v 1.2 2004/04/29 02:39:32 millert Exp $ */ /* * ---------------------------------------------------------------------------- @@ -10,7 +10,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$OpenBSD: helper.c,v 1.1 2004/04/26 19:38:12 millert Exp $"; +static const char rcsid[] = "$OpenBSD: helper.c,v 1.2 2004/04/29 02:39:32 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -28,21 +28,21 @@ static const char rcsid[] = "$OpenBSD: helper.c,v 1.1 2004/04/26 19:38:12 miller char * HASHEnd(HASH_CTX *ctx, char buf[HASH_DIGEST_STRING_LENGTH]) { - int i; - u_char digest[HASH_DIGEST_LENGTH]; - static const char hex[] = "0123456789abcdef"; + int i; + u_int8_t digest[HASH_DIGEST_LENGTH]; + static const char hex[] = "0123456789abcdef"; - if (buf == NULL && (buf = malloc(HASH_DIGEST_STRING_LENGTH)) == NULL) - return(NULL); + if (buf == NULL && (buf = malloc(HASH_DIGEST_STRING_LENGTH)) == NULL) + return(NULL); - HASHFinal(digest,ctx); - for (i = 0; i < HASH_DIGEST_LENGTH; i++) { - buf[i + i] = hex[digest[i] >> 4]; - buf[i + i + 1] = hex[digest[i] & 0x0f]; - } - buf[i + i] = '\0'; - memset(digest, 0, sizeof(digest)); - return(buf); + HASHFinal(digest,ctx); + for (i = 0; i < HASH_DIGEST_LENGTH; i++) { + buf[i + i] = hex[digest[i] >> 4]; + buf[i + i + 1] = hex[digest[i] & 0x0f]; + } + buf[i + i] = '\0'; + memset(digest, 0, sizeof(digest)); + return (buf); } char * @@ -50,28 +50,28 @@ HASHFile(char *filename, char buf[HASH_DIGEST_STRING_LENGTH]) { u_char buffer[BUFSIZ]; HASH_CTX ctx; - int fd, num, oerrno; + int fd, num, save_errno; HASHInit(&ctx); if ((fd = open(filename, O_RDONLY)) < 0) - return(0); + return(NULL); while ((num = read(fd, buffer, sizeof(buffer))) > 0) - HASHUpdate(&ctx, buffer, num); + HASHUpdate(&ctx, buffer, num); - oerrno = errno; + save_errno = errno; close(fd); - errno = oerrno; - return(num < 0 ? 0 : HASHEnd(&ctx, buf)); + errno = save_errno; + return (num < 0 ? NULL : HASHEnd(&ctx, buf)); } char * HASHData(const u_char *data, size_t len, char buf[HASH_DIGEST_STRING_LENGTH]) { - HASH_CTX ctx; + HASH_CTX ctx; - HASHInit(&ctx); - HASHUpdate(&ctx, data, len); - return(HASHEnd(&ctx, buf)); + HASHInit(&ctx); + HASHUpdate(&ctx, data, len); + return (HASHEnd(&ctx, buf)); } |