MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / decode

Function decode

test/benchmark/base64.c:40–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38#define next_char(x) char x = decode_table[(unsigned char)*str++]; if (x < 0) return 1;
39
40int decode(int size, const char* str, int* out_size, char** output) {
41 *output = (char*) malloc( decode_size(size) );
42 char *out = *output;
43 while (size > 0 && (str[size - 1] == '\n' || str[size - 1] == '\r' || str[size - 1] == '=')) size--;
44 const char* ends = str + size - 4;
45 while (1) {
46 if (str > ends) break;
47 while (*str == '\n' || *str == '\r') str++;
48
49 if (str > ends) break;
50 next_char(a); next_char(b); next_char(c); next_char(d);
51
52 *out++ = (char)(a << 2 | b >> 4);
53 *out++ = (char)(b << 4 | c >> 2);
54 *out++ = (char)(c << 6 | d >> 0);
55 }
56
57 int mod = (str - ends) % 4;
58 if (mod == 2) {
59 next_char(a); next_char(b);
60 *out++ = (char)(a << 2 | b >> 4);
61 } else if (mod == 3) {
62 next_char(a); next_char(b); next_char(c);
63 *out++ = (char)(a << 2 | b >> 4);
64 *out++ = (char)(b << 4 | c >> 2);
65 }
66
67 *out = '\0';
68 *out_size = out - *output;
69 return 0;
70}
71
72void encode(int size, const char* str, int* out_size, char** output) {
73 *output = (char*) malloc( encode_size(size) );

Callers 2

mainFunction · 0.85
test_fs_js_api.cFile · 0.85

Calls 2

decode_sizeFunction · 0.85
mallocFunction · 0.50

Tested by

no test coverage detected