5static size_t div_up(
size_t dividend,
size_t divisor) {
6 return dividend / divisor + (dividend % divisor != 0);
10 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
14char *
gv_base64(
const unsigned char *source,
size_t size) {
18 for (
size_t data_i = 0; data_i < size; data_i += 3) {
19 unsigned char d0 = source[data_i];
20 int v = (d0 & 0xFC) >> 2;
23 unsigned char d1 = data_i + 1 < size ? source[data_i + 1] : 0;
27 if (size <= data_i + 1) {
31 unsigned char d2 = data_i + 2 < size ? source[data_i + 2] : 0;
35 if (size <= data_i + 2) {
44 while (buf_i % 4 != 0) {
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
char * gv_base64(const unsigned char *source, size_t size)
size_t gv_base64_size(size_t source_size)
static size_t div_up(size_t dividend, size_t divisor)
static const char base64_alphabet[]