Mercurial > hg > toybox
diff lib/lib.c @ 1605:c4c9267467f8 draft
Add base64.
The tizen guys wanted this. Yeah, I know there's base64 code in
uuencode/uudecode, but that this has -i, input lines aren't of fixed length,
encode/decode are in same file, there's no prefix/suffix code, it always
writes to stdout... Eliminating the code duplication wouldn't be worth
the if/else I'd have to add, so I just did a new one.
Factored out the base64 table init into lib.c though: that was worth sharing.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 13 Dec 2014 11:58:08 -0600 |
parents | f057223498e4 |
children | 45fb262230c9 |
line wrap: on
line diff
--- a/lib/lib.c Sat Dec 13 11:56:41 2014 -0600 +++ b/lib/lib.c Sat Dec 13 11:58:08 2014 -0600 @@ -571,6 +571,21 @@ } } +// Init base64 table + +void base64_init(char *p) +{ + int i; + + for (i = 'A'; i != ':'; i++) { + if (i == 'Z'+1) i = 'a'; + if (i == 'z'+1) i = '0'; + *(p++) = i; + } + *(p++) = '+'; + *(p++) = '/'; +} + // Quick and dirty query size of terminal, doesn't do ANSI probe fallback. // set x=80 y=25 before calling to provide defaults. Returns 0 if couldn't // determine size.