From: Arran Cudbard-Bell Date: Tue, 16 Oct 2012 09:45:39 +0000 (+0100) Subject: Remove dependency on stdbool and use FRs bool constants X-Git-Tag: release_2_2_1~250 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad5e81ffc20ac9eec3102f1c1f58ef2ff38e04cc;p=thirdparty%2Ffreeradius-server.git Remove dependency on stdbool and use FRs bool constants --- diff --git a/src/include/base64.h b/src/include/base64.h index de294a98289..84ecf52e98f 100644 --- a/src/include/base64.h +++ b/src/include/base64.h @@ -19,28 +19,27 @@ #ifndef _FR_BASE64_H # define _FR_BASE64_H -/* Get size_t. */ -# include +#include +RCSIDH(base64_h, "$Id$") -/* Get bool. */ -# include +# include /* This uses that the expression (n+(k-1))/k means the smallest integer >= n/k, i.e., the ceiling of n/k. */ # define FR_BASE64_ENC_LENGTH(inlen) ((((inlen) + 2) / 3) * 4) # define FR_BASE64_DEC_LENGTH(inlen) ((3 * (inlen / 4)) + 2) -extern bool fr_isbase64 (char ch); +extern int fr_isbase64 (char ch); extern void fr_base64_encode (const char *in, size_t inlen, char *out, size_t outlen); extern size_t fr_base64_encode_alloc (const char *in, size_t inlen, char **out); -extern bool fr_base64_decode (const char *in, size_t inlen, - char *out, size_t *outlen); +extern int fr_base64_decode (const char *in, size_t inlen, + char *out, size_t *outlen); -extern bool fr_base64_decode_alloc (const char *in, size_t inlen, - char **out, size_t *outlen); +extern int fr_base64_decode_alloc (const char *in, size_t inlen, + char **out, size_t *outlen); #endif /* BASE64_H */ \ No newline at end of file diff --git a/src/include/libradius.h b/src/include/libradius.h index 2973eb03804..7f757770bd8 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -37,7 +37,6 @@ RCSIDH(libradius_h, "$Id$") #include #include -#include #include #include #include diff --git a/src/lib/base64.c b/src/lib/base64.c index 69796a0ce6f..2541bf1c05d 100644 --- a/src/lib/base64.c +++ b/src/lib/base64.c @@ -43,7 +43,7 @@ #include RCSID("$Id$") -/* Get prototype. */ +#include #include /* Get malloc. */ @@ -63,9 +63,8 @@ to_uchar (char ch) If OUTLEN is less than FR_BASE64_ENC_LENGTH(INLEN), write as many bytes as possible. If OUTLEN is larger than FR_BASE64_ENC_LENGTH(INLEN), also zero terminate the output buffer. */ -void -fr_base64_encode (const char *in, size_t inlen, - char *out, size_t outlen) +void fr_base64_encode (const char *in, size_t inlen, + char *out, size_t outlen) { static const char b64str[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -286,32 +285,30 @@ static const signed char b64[0x100] = { }; #if UCHAR_MAX == 255 -# define uchar_in_range(c) true +# define uchar_in_range(c) TRUE #else # define uchar_in_range(c) ((c) <= 255) #endif -/* Return true if CH is a character from the Base64 alphabet, and - false otherwise. Note that '=' is padding and not considered to be +/* Return TRUE if CH is a character from the Base64 alphabet, and + FALSE otherwise. Note that '=' is padding and not considered to be part of the alphabet. */ -bool -fr_isbase64 (char ch) +int fr_isbase64 (char ch) { return uchar_in_range (to_uchar (ch)) && 0 <= b64[to_uchar (ch)]; } /* Decode base64 encoded input array IN of length INLEN to output - array OUT that can hold *OUTLEN bytes. Return true if decoding was - successful, i.e. if the input was valid base64 data, false + array OUT that can hold *OUTLEN bytes. Return TRUE if decoding was + successful, i.e. if the input was valid base64 data, FALSE otherwise. If *OUTLEN is too small, as many bytes as possible will be written to OUT. On return, *OUTLEN holds the length of decoded bytes in OUT. Note that as soon as any non-alphabet characters are - encountered, decoding is stopped and false is returned. This means + encountered, decoding is stopped and FALSE is returned. This means that, when applicable, you must remove any line terminators that is part of the data stream before calling this function. */ -bool -fr_base64_decode (const char *in, size_t inlen, - char *out, size_t *outlen) +int fr_base64_decode (const char *in, size_t inlen, + char *out, size_t *outlen) { size_t outleft = *outlen; @@ -380,9 +377,9 @@ fr_base64_decode (const char *in, size_t inlen, *outlen -= outleft; if (inlen != 0) - return false; + return FALSE; - return true; + return TRUE; } /* Allocate an output buffer in *OUT, and decode the base64 encoded @@ -391,14 +388,13 @@ fr_base64_decode (const char *in, size_t inlen, if the caller is not interested in the decoded length. *OUT may be NULL to indicate an out of memory error, in which case *OUTLEN contains the size of the memory block needed. The function returns - true on successful decoding and memory allocation errors. (Use the + TRUE on successful decoding and memory allocation errors. (Use the *OUT and *OUTLEN parameters to differentiate between successful - decoding and memory error.) The function returns false if the + decoding and memory error.) The function returns FALSE if the input was invalid, in which case *OUT is NULL and *OUTLEN is undefined. */ -bool -fr_base64_decode_alloc (const char *in, size_t inlen, char **out, - size_t *outlen) +int fr_base64_decode_alloc (const char *in, size_t inlen, char **out, + size_t *outlen) { /* This may allocate a few bytes too much, depending on input, but it's not worth the extra CPU time to compute the exact amount. @@ -409,17 +405,17 @@ fr_base64_decode_alloc (const char *in, size_t inlen, char **out, *out = malloc (needlen); if (!*out) - return true; + return TRUE; if (!fr_base64_decode (in, inlen, *out, &needlen)) { free (*out); *out = NULL; - return false; + return FALSE; } if (outlen) *outlen = needlen; - return true; + return TRUE; } \ No newline at end of file