2 * C Implementation: uuencode
7 * Author: Michal Sojka <sojkam1@fel.cvut.cz>, (C) 2005
9 * Copyright: See COPYING file that comes with this distribution
16 static char uuencode_table[64];
17 static char initialized = 0;
19 * Initializes uuencode_table.
21 void uuencode_init() {
23 uuencode_table[0] = 0x60;
25 for(i = 1; i < 64; i++) {
26 uuencode_table[i] = (char)(0x20 + i);
32 * Uuencodes up to 45 bytes of data. The output string is not terminated by any newline character.
33 * @param dest Where to store output string. There should be space at least for 62 bytes.
36 * @return Zero on success, -1 on error.
38 int uuencode_line(char *dest, unsigned char *source, int length) {
45 if (length > 45 || length < 0)
48 *dest++ = uuencode_table[length];
49 for (i = 0; i < length; i+=3) {
51 data = (data << 8) | ((i+1 < length) ? *source++ : 0);
52 data = (data << 8) | ((i+2 < length) ? *source++ : 0);
54 *dest++ = uuencode_table[(data >> 18) & 0x3f];
55 *dest++ = uuencode_table[(data >> 12) & 0x3f];
56 *dest++ = uuencode_table[(data >> 6) & 0x3f];
57 *dest++ = uuencode_table[ data & 0x3f];