3 Copyright (c) 2010 Matthias Kramm <kramm@quiss.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 static const char base64
[65]=
26 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
28 void write_base64(FILE*fi
, const char* s
)
30 const unsigned char*b
= (const unsigned char*)s
;
31 const unsigned char*end
= b
+ strlen(b
);
32 const unsigned char*end_minus_3
= end
- 3;
34 while(b
<= end_minus_3
) {
36 data
[0] = base64
[(b
[0]>>2)&63 ];
37 data
[1] = base64
[(b
[0]<<4|b
[1]>>4)&63];
38 data
[2] = base64
[(b
[1]<<2|b
[2]>>6)&63];
39 data
[3] = base64
[(b
[2])&63 ];
40 fwrite(data
, 4, 1, fi
);
44 unsigned char data
[4];
49 data
[0] = base64
[(b
[0]>>2)&63];
50 data
[1] = base64
[(b
[0]<<4)&63];
55 data
[0] = base64
[(b
[0]>>2)&63];
56 data
[1] = base64
[(b
[0]<<4|b
[1]>>4)&63];
57 data
[2] = base64
[(b
[1]<<2)&63];
61 fprintf(stderr
, "internal error in base64 implementation (%d)\n", end
-b
);
64 fwrite(data
, 4, 1, fi
);