Remove dependency on stdbool and use FRs bool constants
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 16 Oct 2012 09:45:39 +0000 (10:45 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 16 Oct 2012 09:59:52 +0000 (10:59 +0100)
src/include/base64.h
src/include/libradius.h
src/lib/base64.c

index de294a9..84ecf52 100644 (file)
 #ifndef _FR_BASE64_H
 # define _FR_BASE64_H
 
-/* Get size_t. */
-# include <stddef.h>
+#include <freeradius-devel/ident.h>
+RCSIDH(base64_h, "$Id$")
 
-/* Get bool. */
-# include <stdbool.h>
+# include <stddef.h>
 
 /* 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
index 2973eb0..7f75777 100644 (file)
@@ -37,7 +37,6 @@ RCSIDH(libradius_h, "$Id$")
 #include <stdlib.h>
 #include <stdarg.h>
 
-#include <freeradius-devel/bool.h>
 #include <freeradius-devel/radius.h>
 #include <freeradius-devel/token.h>
 #include <freeradius-devel/hash.h>
index 69796a0..2541bf1 100644 (file)
@@ -43,7 +43,7 @@
 #include <freeradius-devel/ident.h>
 RCSID("$Id$")
 
-/* Get prototype. */
+#include <freeradius-devel/libradius.h>
 #include <freeradius-devel/base64.h>
 
 /* 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