Mercurial > libpst
comparison src/libstrfunc.c @ 43:f6db1f060a95
start on outlook 2003 64 bit format
author | carl |
---|---|
date | Sun, 06 Jan 2008 14:47:06 -0800 |
parents | 6fe121a971c9 |
children | 997cf1373f9e |
comparison
equal
deleted
inserted
replaced
42:7a97f50c39c5 | 43:f6db1f060a95 |
---|---|
7 #include "libstrfunc.h" | 7 #include "libstrfunc.h" |
8 | 8 |
9 | 9 |
10 static unsigned char _sf_uc_ib[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=="; | 10 static unsigned char _sf_uc_ib[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=="; |
11 | 11 |
12 char * | 12 char *base64_encode(void *data, size_t size) { |
13 base64_encode(void *data, size_t size) { | 13 char *output; |
14 char *output; | 14 register char *ou; |
15 register char *ou; | 15 register unsigned char *p=(unsigned char *)data; |
16 register unsigned char *p=(unsigned char *)data; | 16 register void * dte = (void*)((char*)data + size); |
17 #ifdef __LINUX__ | 17 register int nc=0; |
18 register void * dte = ((char*)data + size); | |
19 #endif | |
20 | 18 |
21 #ifndef __LINUX__ | 19 if ( data == NULL || size == 0 ) return NULL; |
22 register void * dte = (void*)((char*)data + size); | |
23 #endif | |
24 //register void *dte=data + size; | |
25 register int nc=0; | |
26 | 20 |
27 if ( data == NULL || size == 0 ) | 21 ou = output = (char *)malloc(size / 3 * 4 + (size / 57) + 5); |
28 return NULL; | 22 if(!output) return NULL; |
29 | 23 |
30 ou=output=(char *)malloc(size / 3 * 4 + (size / 57) + 5); | 24 while((char *)dte - (char *)p >= 3) { |
31 if(!output) | 25 unsigned char x = p[0]; |
32 return NULL; | 26 unsigned char y = p[1]; |
27 unsigned char z = p[2]; | |
28 ou[0] = _sf_uc_ib[ x >> 2 ]; | |
29 ou[1] = _sf_uc_ib[ ((x & 0x03) << 4) | (y >> 4) ]; | |
30 ou[2] = _sf_uc_ib[ ((y & 0x0F) << 2) | (z >> 6) ]; | |
31 ou[3] = _sf_uc_ib[ z & 0x3F ]; | |
32 p+=3; | |
33 ou+=4; | |
34 nc+=4; | |
35 if(!(nc % 76)) *ou++='\n'; | |
36 }; | |
37 if ((char *)dte - (char *)p == 2) { | |
38 *ou++ = _sf_uc_ib[ *p >> 2 ]; | |
39 *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) | (p[1] >> 4) ]; | |
40 *ou++ = _sf_uc_ib[ ((p[1] & 0x0F) << 2) ]; | |
41 *ou++ = '='; | |
42 } else if((char *)dte - (char *)p == 1) { | |
43 *ou++ = _sf_uc_ib[ *p >> 2 ]; | |
44 *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) ]; | |
45 *ou++ = '='; | |
46 *ou++ = '='; | |
47 }; | |
33 | 48 |
34 while((char *)dte - (char *)p >= 3) { | 49 *ou=0; |
35 unsigned char x = p[0]; | |
36 unsigned char y = p[1]; | |
37 unsigned char z = p[2]; | |
38 ou[0] = _sf_uc_ib[ x >> 2 ]; | |
39 ou[1] = _sf_uc_ib[ ((x & 0x03) << 4) | (y >> 4) ]; | |
40 ou[2] = _sf_uc_ib[ ((y & 0x0F) << 2) | (z >> 6) ]; | |
41 ou[3] = _sf_uc_ib[ z & 0x3F ]; | |
42 p+=3; | |
43 ou+=4; | |
44 nc+=4; | |
45 if(!(nc % 76)) *ou++='\n'; | |
46 }; | |
47 if((char *)dte - (char *)p == 2) { | |
48 *ou++ = _sf_uc_ib[ *p >> 2 ]; | |
49 *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) | (p[1] >> 4) ]; | |
50 *ou++ = _sf_uc_ib[ ((p[1] & 0x0F) << 2) ]; | |
51 *ou++ = '='; | |
52 } else if((char *)dte - (char *)p == 1) { | |
53 *ou++ = _sf_uc_ib[ *p >> 2 ]; | |
54 *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) ]; | |
55 *ou++ = '='; | |
56 *ou++ = '='; | |
57 }; | |
58 | 50 |
59 *ou=0; | 51 return output; |
60 | |
61 return output; | |
62 }; | 52 }; |
63 | 53 |
54 | |
55 void hexdump(char *hbuf, int start, int stop, int ascii) /* {{{ HexDump all or a part of some buffer */ | |
56 { | |
57 char c; | |
58 int diff,i; | |
59 | |
60 while (start < stop ) { | |
61 diff = stop - start; | |
62 if (diff > 16) diff = 16; | |
63 | |
64 fprintf(stderr, ":%08X ",start); | |
65 | |
66 for (i = 0; i < diff; i++) { | |
67 if( 8 == i ) fprintf( stderr, " " ); | |
68 fprintf(stderr, "%02X ",(unsigned char)*(hbuf+start+i)); | |
69 } | |
70 if (ascii) { | |
71 for (i = diff; i < 16; i++) fprintf(stderr, " "); | |
72 for (i = 0; i < diff; i++) { | |
73 c = *(hbuf+start+i); | |
74 fprintf(stderr, "%c", isprint(c) ? c : '.'); | |
75 } | |
76 } | |
77 fprintf(stderr, "\n"); | |
78 start += 16; | |
79 } | |
80 } |