commit 2d6981d14b013ef2b573a349dc2bd41a560af285 parent 3365573fd7ba9f5653418eeca336329047e1c983 Author: z3bra <willyatmailoodotorg> Date: Mon May 9 08:44:36 +12000 Add base64_format() to fold lines at a specified width Diffstat:
base64.c | | | 27 | +++++++++++++-------------- |
base64.h | | | 1 | + |
base64.o | | | 0 |
diff --git a/base64.c b/base64.c @@ -6,6 +6,8 @@ #include "base64.h" +#define BASE64_FOLD 76 + const char base64_table[] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z', @@ -58,20 +60,17 @@ base64_decode(char **buf, const unsigned char *msg, size_t len) return size; } -/* -int -main(int argc, char *argv[]) +size_t +base64_fold(FILE *fp, char *base64, size_t len, size_t fold) { - int i; - size_t len, n; - char *buf = NULL, in[79]; - - while ((n = read(0, in, 77)) > 0) { - in[78] = 0; - len = base64_decode(&buf, in, n); - puts(buf); - free(buf); + size_t i; + + fold = fold > 0 ? fold : BASE64_FOLD; + + for (i = 0; i < len; i += BASE64_FOLD) { + fwrite(base64+i, 1, i+BASE64_FOLD > len ? len - i : BASE64_FOLD, fp); + fwrite("\n", 1, 1, fp); } - return 0; + + return fold; } -*/ diff --git a/base64.h b/base64.h @@ -3,5 +3,6 @@ size_t base64_encode(char **buf, const unsigned char *msg, size_t len); size_t base64_decode(char **buf, const unsigned char *msg, size_t len); +size_t base64_fold(FILE *out, char *msg, size_t len, size_t fold); #endif diff --git a/base64.o b/base64.o Binary files differ