((Character) < 128)
#define IS_BASE64(Character) \
(IS_ASCII (Character) && base64_char_to_value[Character] >= 0)
+#define IS_BASE64_IGNORABLE(Character) \
+ ((Character) == ' ' || (Character) == '\t' || (Character) == '\n' \
+ || (Character) == '\f' || (Character) == '\r')
+
+/* Used by base64_decode_1 to retrieve a non-base64-ignorable
+ character or return retval if there are no characters left to
+ process. */
+#define READ_QUADRUPLET_BYTE(retval) \
+ do \
+ { \
+ if (i == length) \
+ return (retval); \
+ c = from[i++]; \
+ } \
+ while (IS_BASE64_IGNORABLE (c))
/* Don't use alloca for regions larger than this, lest we overflow
their stack. */
char *to;
int length;
{
- int counter = 0, i = 0;
+ int i = 0;
char *e = to;
unsigned char c;
unsigned long value;
- while (i < length)
+ while (1)
{
- /* Accept wrapping lines, reversibly if at each 76 characters. */
-
- c = from[i++];
- if (c == '\n')
- {
- if (i == length)
- break;
- c = from[i++];
- if (i == length)
- break;
- counter = 1;
- }
- else
- counter++;
+ /* Process first byte of a quadruplet. */
- /* Process first byte of a quadruplet. */
+ READ_QUADRUPLET_BYTE (e-to);
if (!IS_BASE64 (c))
return -1;
/* Process second byte of a quadruplet. */
- if (i == length)
- return -1;
- c = from[i++];
+ READ_QUADRUPLET_BYTE (-1);
if (!IS_BASE64 (c))
return -1;
*e++ = (unsigned char) (value >> 16);
/* Process third byte of a quadruplet. */
-
- if (i == length)
- return -1;
- c = from[i++];
+
+ READ_QUADRUPLET_BYTE (-1);
if (c == '=')
{
- c = from[i++];
+ READ_QUADRUPLET_BYTE (-1);
+
if (c != '=')
return -1;
continue;
/* Process fourth byte of a quadruplet. */
- if (i == length)
- return -1;
- c = from[i++];
+ READ_QUADRUPLET_BYTE (-1);
if (c == '=')
continue;
*e++ = (unsigned char) (0xff & value);
}
-
- return e - to;
}
\f
void