Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_base64encN - Encode binary data as MIME base 64
#License - #Source code - #Example Use -

SYNOPSIS

#include <librock/parse.h>

int
librock_base64encN(char *wptr, /* Output.  Must have room to store 4 bytes */
         long *paccum, /* Accumulator.  NOTE: Initialize to 0 or 1*/
         const char *ptr, /* Pointer to bytes to encode */
         int amt);     /* Number of bytes to encode or -1 */

DESCRIPTION

This function performs MIME Base64 encoding. An accumulator is used to collect 3 bytes on successive calls, which are then encoded and written to wptr. To end the encoding, call with amt == -1, which will pad if necessary.

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.

Typical use is

#ifdef librock_TYPICAL_USE_base64encN
    #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 */
    }
    wptr += librock_base64encN(wptr,&accum,ptr,strlen(ptr));
    wptr += librock_base64encN(wptr,&accum,0,-1);
    *wptr = '\0';
    printf("%s\n",out);
#endif

USES

// No external calls

LICENSE

  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

Source Code

./comm/person/email/base64.c (implementation, plus source of this manual page)

This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2003 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

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.