Changeset 8445 for trunk/module-ghttp.c
- Timestamp:
- 03/01/13 11:56:47 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-ghttp.c
r8341 r8445 40 40 41 41 return 0; 42 }43 44 45 static inline unsigned char to_uchar (char ch)46 {47 return ch;48 }49 50 void base64_encode(const char *in, size_t inlen, char *out, size_t outlen)51 {52 static const char b64str[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";53 while (inlen && outlen) {54 *out++ = b64str[(to_uchar (in[0]) >> 2) & 0x3f];55 if (!--outlen) break;56 *out++ = b64str[((to_uchar (in[0]) << 4) + (--inlen ? to_uchar (in[1]) >> 4 : 0)) & 0x3f];57 if (!--outlen) break;58 *out++ = (inlen ? b64str[((to_uchar (in[1]) << 2) + (--inlen ? to_uchar (in[2]) >> 6 : 0)) & 0x3f] : '=');59 if (!--outlen) break;60 *out++ = inlen ? b64str[to_uchar (in[2]) & 0x3f] : '=';61 if (!--outlen) break;62 if (inlen) inlen--;63 if (inlen) in += 3;64 65 if (outlen) *out = '\0';66 }67 }68 69 size_t b64encode(const char *in, size_t inlen, char **out)70 {71 size_t outlen = 1 + BASE64_LENGTH (inlen);72 if (inlen > outlen) {73 *out = NULL;74 return 0;75 }76 if(!cs_malloc(out, outlen)) return -1;77 base64_encode (in, inlen, *out, outlen);78 return outlen - 1;79 42 } 80 43
Note:
See TracChangeset
for help on using the changeset viewer.