diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/base64.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/base64.c b/src/base64.c index acec723..83205c2 100644 --- a/src/base64.c +++ b/src/base64.c | |||
| @@ -21,10 +21,6 @@ | |||
| 21 | #include <string.h> | 21 | #include <string.h> |
| 22 | #include "base64.h" | 22 | #include "base64.h" |
| 23 | 23 | ||
| 24 | #ifdef WIN32 | ||
| 25 | #define strtok_r strtok_s | ||
| 26 | #endif | ||
| 27 | |||
| 28 | static const char base64_str[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | 24 | static const char base64_str[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
| 29 | static const char base64_pad = '='; | 25 | static const char base64_pad = '='; |
| 30 | 26 | ||
| @@ -112,18 +108,23 @@ unsigned char *base64decode(const char *buf, size_t *size) | |||
| 112 | size_t len = strlen(buf); | 108 | size_t len = strlen(buf); |
| 113 | if (len <= 0) return NULL; | 109 | if (len <= 0) return NULL; |
| 114 | unsigned char *outbuf = (unsigned char*)malloc((len/4)*3+3); | 110 | unsigned char *outbuf = (unsigned char*)malloc((len/4)*3+3); |
| 115 | 111 | const char *ptr = buf; | |
| 116 | unsigned char *line; | ||
| 117 | int p = 0; | 112 | int p = 0; |
| 118 | char* saveptr = NULL; | ||
| 119 | 113 | ||
| 120 | line = (unsigned char*)strtok_r((char*)buf, "\r\n\t ", &saveptr); | 114 | do { |
| 121 | while (line) { | 115 | ptr += strspn(ptr, "\r\n\t "); |
| 122 | p+=base64decode_block(outbuf+p, (const char*)line, strlen((char*)line)); | 116 | if (*ptr == '\0') { |
| 117 | break; | ||
| 118 | } | ||
| 119 | len = strcspn(ptr, "\r\n\t "); | ||
| 120 | if (len > 0) { | ||
| 121 | p+=base64decode_block(outbuf+p, ptr, len); | ||
| 122 | ptr += len; | ||
| 123 | } else { | ||
| 124 | break; | ||
| 125 | } | ||
| 126 | } while (1); | ||
| 123 | 127 | ||
| 124 | // get next line of base64 encoded block | ||
| 125 | line = (unsigned char*)strtok_r(NULL, "\r\n\t ", &saveptr); | ||
| 126 | } | ||
| 127 | outbuf[p] = 0; | 128 | outbuf[p] = 0; |
| 128 | *size = p; | 129 | *size = p; |
| 129 | return outbuf; | 130 | return outbuf; |
