7 /***************************************************************************
8 decode a base64 string in-place - simple and slow algorithm
9 ***************************************************************************/
10 static int base64_decode(char *s)
12 char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
13 int bit_offset, byte_offset, idx, i, n;
14 unsigned char *d = (unsigned char *)s;
19 while (*s && ((*s == '\n') || (p=strchr(b64,*s)))) {
25 byte_offset = (i*6)/8;
27 d[byte_offset] &= ~((1<<(8-bit_offset))-1);
29 d[byte_offset] |= (idx << (2-bit_offset));
32 d[byte_offset] |= (idx >> (bit_offset-2));
34 d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF;
45 static int load_stdin(char **s)
53 int n = read(0, buf, sizeof(buf));
54 if (n == -1 && errno == EINTR) continue;
57 (*s) = realloc((*s), length + n + 1);
60 memcpy((*s)+length, buf, n);
69 int main(int argc, char *argv[])