From 75e5b2e906bd8563bf0f53a76065618c88122e1c Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 12 May 2014 14:35:12 +0200 Subject: [PATCH] Use void pointers to opaque buffers. --- src/utils.c | 14 ++++++++------ src/utils.h | 10 +++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/utils.c b/src/utils.c index 510dd2f..594c91a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -52,14 +52,16 @@ static int charhex2bin(char c) { return toupper(c) - 'A' + 10; } -int hex2bin(const char *src, char *dst, int length) { +int hex2bin(const char *src, void *vdst, int length) { + char *dst = vdst; int i; for(i = 0; i < length && isxdigit(src[i * 2]) && isxdigit(src[i * 2 + 1]); i++) dst[i] = charhex2bin(src[i * 2]) * 16 + charhex2bin(src[i * 2 + 1]); return i; } -int bin2hex(const char *src, char *dst, int length) { +int bin2hex(const void *vsrc, char *dst, int length) { + const char *src = vsrc; for(int i = length - 1; i >= 0; i--) { dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15]; dst[i * 2] = hexadecimals[(unsigned char) src[i] >> 4]; @@ -68,7 +70,7 @@ int bin2hex(const char *src, char *dst, int length) { return length * 2; } -int b64decode(const char *src, char *dst, int length) { +int b64decode(const char *src, void *dst, int length) { int i; uint32_t triplet = 0; unsigned char *udst = (unsigned char *)dst; @@ -99,7 +101,7 @@ int b64decode(const char *src, char *dst, int length) { } } -static int b64encode_internal(const char *src, char *dst, int length, const char *alphabet) { +static int b64encode_internal(const void *src, char *dst, int length, const char *alphabet) { uint32_t triplet; const unsigned char *usrc = (unsigned char *)src; int si = length / 3 * 3; @@ -140,11 +142,11 @@ static int b64encode_internal(const char *src, char *dst, int length, const char return length; } -int b64encode(const char *src, char *dst, int length) { +int b64encode(const void *src, char *dst, int length) { return b64encode_internal(src, dst, length, base64_original); } -int b64encode_urlsafe(const char *src, char *dst, int length) { +int b64encode_urlsafe(const void *src, char *dst, int length) { return b64encode_internal(src, dst, length, base64_urlsafe); } diff --git a/src/utils.h b/src/utils.h index 85d6bf2..d89d077 100644 --- a/src/utils.h +++ b/src/utils.h @@ -21,12 +21,12 @@ #ifndef __TINC_UTILS_H__ #define __TINC_UTILS_H__ -extern int hex2bin(const char *src, char *dst, int length); -extern int bin2hex(const char *src, char *dst, int length); +extern int hex2bin(const char *src, void *dst, int length); +extern int bin2hex(const void *src, char *dst, int length); -extern int b64encode(const char *src, char *dst, int length); -extern int b64encode_urlsafe(const char *src, char *dst, int length); -extern int b64decode(const char *src, char *dst, int length); +extern int b64encode(const void *src, char *dst, int length); +extern int b64encode_urlsafe(const void *src, char *dst, int length); +extern int b64decode(const char *src, void *dst, int length); #ifdef HAVE_MINGW extern const char *winerror(int); -- 2.25.1