Home
Highly Reusable Software By activity User Interface Text Strings Math Processing
Stored Data
Communications
Hard World File System
|
#License - #Source code - #Example Use -
#include <librock/parse.h> int librock_base64enc(char *wptr, /* Output. Must have room to store 4 bytes */ long *paccum, /* Accumulator. NOTE: Initialize to 0 or 1*/ int ch) /* Byte to encode in range 0-0xff, or -1 to pad at end */
Inserting NUL termination and newlines in the output is up to the caller.
This function returns the number of characters written at pointer, either 0, or 4.
To encode more than one byte, see librock_base64encN
instead.
Typical use is
#ifdef librock_TYPICAL_USE_base64enc #include <stdlib.h> const char *ptr = "Some string to encode."; long accum = 0; /* Must initialize */ char *out = malloc(strlen(ptr) * 4/3+9); /* at least 4 bytes for every 3, plus 4 bytes extra plus '\0' end*/ char *wptr = out; if (!wptr) { /* Error handling */ } while(*ptr) { wptr += librock_base64enc(wptr,&accum,*ptr & 0xff); ptr++; } wptr += librock_base64enc(wptr,&accum,-1); *wptr = '\0'; printf("%s\n",out); #endif
Copyright 1998-2002 Forrest J. Cavalier III, http://www.mibsoftware.com Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in <librock/license/librock.txt> librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45
librock_base64enc passed tests in tbase64 (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_base64enc passed tests in tbase64 (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)
Want to help? We welcome comments, patches. -- Need help? Request paid support.