Mercurial > libpst
comparison src/libstrfunc.c @ 36:6fe121a971c9 stable-0-5-7
valgrind fixes
author | carl |
---|---|
date | Thu, 09 Aug 2007 15:46:34 -0700 |
parents | b88ceb81dba2 |
children | f6db1f060a95 |
comparison
equal
deleted
inserted
replaced
35:b2f247463b83 | 36:6fe121a971c9 |
---|---|
3 | 3 |
4 #include <stdio.h> | 4 #include <stdio.h> |
5 #include <ctype.h> | 5 #include <ctype.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include "libstrfunc.h" | 7 #include "libstrfunc.h" |
8 | |
9 char *_sf_b64_buf=NULL; | |
10 size_t _sf_b64_len=0; | |
11 | 8 |
12 | 9 |
13 static unsigned char _sf_uc_ib[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=="; | 10 static unsigned char _sf_uc_ib[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=="; |
14 | 11 |
15 char * | 12 char * |
24 #ifndef __LINUX__ | 21 #ifndef __LINUX__ |
25 register void * dte = (void*)((char*)data + size); | 22 register void * dte = (void*)((char*)data + size); |
26 #endif | 23 #endif |
27 //register void *dte=data + size; | 24 //register void *dte=data + size; |
28 register int nc=0; | 25 register int nc=0; |
29 | 26 |
30 if ( data == NULL || size == 0 ) | 27 if ( data == NULL || size == 0 ) |
31 return NULL; | 28 return NULL; |
32 | 29 |
33 ou=output=(char *)malloc(size / 3 * 4 + (size / 50) + 5); | 30 ou=output=(char *)malloc(size / 3 * 4 + (size / 57) + 5); |
34 if(!output) | 31 if(!output) |
35 return NULL; | 32 return NULL; |
36 | 33 |
37 while((char *)dte - (char *)p >= 3) { | 34 while((char *)dte - (char *)p >= 3) { |
38 *ou = _sf_uc_ib[ *p >> 2 ]; | 35 unsigned char x = p[0]; |
39 ou[1] = _sf_uc_ib[ ((*p & 0x03) << 4) | (p[1] >> 4) ]; | 36 unsigned char y = p[1]; |
40 ou[2] = _sf_uc_ib[ ((p[1] & 0x0F) << 2) | (p[2] >> 6) ]; | 37 unsigned char z = p[2]; |
41 ou[3] = _sf_uc_ib[ p[2] & 0x3F ]; | 38 ou[0] = _sf_uc_ib[ x >> 2 ]; |
42 | 39 ou[1] = _sf_uc_ib[ ((x & 0x03) << 4) | (y >> 4) ]; |
43 p+=3; | 40 ou[2] = _sf_uc_ib[ ((y & 0x0F) << 2) | (z >> 6) ]; |
44 ou+=4; | 41 ou[3] = _sf_uc_ib[ z & 0x3F ]; |
45 | 42 p+=3; |
46 nc+=4; | 43 ou+=4; |
47 if(!(nc % 76)) *ou++='\n'; | 44 nc+=4; |
45 if(!(nc % 76)) *ou++='\n'; | |
48 }; | 46 }; |
49 if((char *)dte - (char *)p == 2) { | 47 if((char *)dte - (char *)p == 2) { |
50 *ou++ = _sf_uc_ib[ *p >> 2 ]; | 48 *ou++ = _sf_uc_ib[ *p >> 2 ]; |
51 *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) | (p[1] >> 4) ]; | 49 *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) | (p[1] >> 4) ]; |
52 *ou++ = _sf_uc_ib[ ((p[1] & 0x0F) << 2) ]; | 50 *ou++ = _sf_uc_ib[ ((p[1] & 0x0F) << 2) ]; |
53 *ou++ = '='; | 51 *ou++ = '='; |
54 } else if((char *)dte - (char *)p == 1) { | 52 } else if((char *)dte - (char *)p == 1) { |
55 *ou++ = _sf_uc_ib[ *p >> 2 ]; | 53 *ou++ = _sf_uc_ib[ *p >> 2 ]; |
56 *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) ]; | 54 *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) ]; |
57 *ou++ = '='; | 55 *ou++ = '='; |
58 *ou++ = '='; | 56 *ou++ = '='; |
59 }; | 57 }; |
60 | 58 |
61 *ou=0; | 59 *ou=0; |
62 | 60 |
63 _sf_b64_len = (ou - output); | 61 return output; |
64 | |
65 if(_sf_b64_buf) | |
66 free(_sf_b64_buf); | |
67 return _sf_b64_buf=output; | |
68 }; | 62 }; |
69 | 63 |