From 224ee4053e9eb75380341a45689a76ac659b7a96 Mon Sep 17 00:00:00 2001 From: millert <> Date: Thu, 29 Apr 2004 02:39:32 +0000 Subject: [PATCH] Some KNF --- src/lib/libc/hash/helper.c | 50 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/lib/libc/hash/helper.c b/src/lib/libc/hash/helper.c index f7dd752d..5a64c3c8 100644 --- a/src/lib/libc/hash/helper.c +++ b/src/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 @@ -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)); }