summaryrefslogtreecommitdiffstats
path: root/lib/base64.c
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-02-12 12:03:58 +0000
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-02-12 12:03:58 +0000
commitabbad00edd7f5f3d33ae77a9d5ac338e5bea5fb3 (patch)
tree0d55fb4d8e5ad7a9376d1bccdea31104cbecacfe /lib/base64.c
parentbd7029a99b0c2974265c6665638ef14a052f42ab (diff)
downloadmonitoring-plugins-abbad00edd7f5f3d33ae77a9d5ac338e5bea5fb3.tar.gz
Import Gnulib floorf and base64 and removed our old base64 library.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1926 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/base64.c')
-rw-r--r--lib/base64.c50
1 files changed, 0 insertions, 50 deletions
diff --git a/lib/base64.c b/lib/base64.c
deleted file mode 100644
index 1f1fcb8c..00000000
--- a/lib/base64.c
+++ /dev/null
@@ -1,50 +0,0 @@
1/****************************************************************************
2* Function to encode in Base64
3*
4* Written by Lauri Alanko
5*
6*****************************************************************************/
7
8#include "common.h"
9#include "base64.h"
10
11char *
12base64 (const char *bin, size_t len)
13{
14
15 char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1);
16 size_t i = 0, j = 0;
17
18 char BASE64_END = '=';
19 char base64_table[64];
20 strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64);
21
22 while (j < len - 2) {
23 buf[i++] = base64_table[bin[j] >> 2];
24 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
25 buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)];
26 buf[i++] = base64_table[bin[j + 2] & 63];
27 j += 3;
28 }
29
30 switch (len - j) {
31 case 1:
32 buf[i++] = base64_table[bin[j] >> 2];
33 buf[i++] = base64_table[(bin[j] & 3) << 4];
34 buf[i++] = BASE64_END;
35 buf[i++] = BASE64_END;
36 break;
37 case 2:
38 buf[i++] = base64_table[bin[j] >> 2];
39 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
40 buf[i++] = base64_table[(bin[j + 1] & 15) << 2];
41 buf[i++] = BASE64_END;
42 break;
43 case 0:
44 break;
45 }
46
47 buf[i] = '\0';
48 return buf;
49}
50