]> jfr.im git - irc/quakenet/newserv.git/blame - lib/base64.c
BUILD: add require-all build mode
[irc/quakenet/newserv.git] / lib / base64.c
CommitLineData
c86edd1d
Q
1/*
2 * base64.c: base64 functions
3 */
4
5#include "base64.h"
6#include <assert.h>
7
8int numerictab[] = {
9 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11 0, 0, 0, 0, 0, 0, 0, 0, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0,
12 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
13 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 62, 0, 63, 0, 0, 0, 26, 27, 28,
14 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
15 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
19 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
20 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
21 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
22};
23
24char tokens[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789[]";
25
d8b17362
CP
26/*
27VALID_INLINE long numerictolong(const char *numeric, int numericlen)
c86edd1d
Q
28{
29 long mynumeric=0;
30 int i;
31
32 for (i=0;i<numericlen;i++) {
33 mynumeric=(mynumeric << 6)+numerictab[(int) *(numeric++)];
34 }
35
36 return mynumeric;
37}
d8b17362 38*/
c86edd1d
Q
39
40char *longtonumeric(long param, int len)
41{
42 static char mynum[7]; /* Static buffers rock. Multi-thread at your peril */
43 int i;
44
45 /* To go with our marvellous static buffer we
46 * have this rather groovy length limit. */
47 assert(len<=6);
48
49 for (i=len-1;i>=0;i--) {
50 mynum[i] = tokens[(param % 64)];
51 param /= 64;
52 }
53 mynum[len] = '\0';
54
55 return (mynum);
56}
57
58/* Slightly more sane version of the above */
59
60char *longtonumeric2(long param, int len, char *mynum)
61{
62 int i;
63
64 for (i=len-1;i>=0;i--) {
65 mynum[i] = tokens[(param % 64)];
66 param /= 64;
67 }
68 mynum[len] = '\0';
69
70 return (mynum);
71}
72