clean up codec reverse inits

This commit is contained in:
Erik Ekman 2009-02-17 21:03:13 +00:00 committed by Erik Ekman
parent c7b21b7d84
commit 0b280bec2b
2 changed files with 18 additions and 28 deletions

View File

@ -27,7 +27,6 @@
static const char cb32[] = static const char cb32[] =
"abcdefghijklmnopqrstuvwxyz012345"; "abcdefghijklmnopqrstuvwxyz012345";
static unsigned char rev32[128]; static unsigned char rev32[128];
static int reverse_init = 0;
static int base32_decode(void *, size_t *, const char *, size_t); static int base32_decode(void *, size_t *, const char *, size_t);
static int base32_encode(char *, size_t *, const void *, size_t); static int base32_encode(char *, size_t *, const void *, size_t);
@ -70,6 +69,22 @@ base32_blksize_enc()
return BLKSIZE_ENC; return BLKSIZE_ENC;
} }
static void
base32_reverse_init()
{
int i;
unsigned char c;
static int reverse_init = 0;
if (!reverse_init) {
for (i = 0; i < 32; i++) {
c = cb32[i];
rev32[(int) c] = i;
}
reverse_init = 1;
}
}
int int
b32_5to8(int in) b32_5to8(int in)
{ {
@ -79,15 +94,7 @@ b32_5to8(int in)
int int
b32_8to5(int in) b32_8to5(int in)
{ {
int i; base32_reverse_init();
int c;
if (!reverse_init) {
for (i = 0; i < 32; i++) {
c = cb32[i];
rev32[(int) c] = i;
}
reverse_init = 1;
}
return rev32[in]; return rev32[in];
} }
@ -186,17 +193,9 @@ base32_decode(void *buf, size_t *buflen, const char *str, size_t slen)
size_t newsize; size_t newsize;
size_t maxsize; size_t maxsize;
const char *p; const char *p;
unsigned char c;
int len; int len;
int i;
if (!reverse_init) { base32_reverse_init();
for (i = 0; i < 32; i++) {
c = cb32[i];
rev32[(int) c] = i;
}
reverse_init = 1;
}
/* chars needed to decode slen */ /* chars needed to decode slen */
newsize = BLKSIZE_RAW * (slen / BLKSIZE_ENC + 1) + 1; newsize = BLKSIZE_RAW * (slen / BLKSIZE_ENC + 1) + 1;

View File

@ -78,7 +78,6 @@ base64_encode(char *buf, size_t *buflen, const void *data, size_t size)
{ {
size_t newsize; size_t newsize;
size_t maxsize; size_t maxsize;
unsigned char c;
unsigned char *s; unsigned char *s;
unsigned char *p; unsigned char *p;
unsigned char *q; unsigned char *q;
@ -86,14 +85,6 @@ base64_encode(char *buf, size_t *buflen, const void *data, size_t size)
memset(buf, 0, *buflen); memset(buf, 0, *buflen);
if (!reverse_init) {
for (i = 0; i < 64; i++) {
c = cb64[i];
rev64[(int) c] = i;
}
reverse_init = 1;
}
/* how many chars can we encode within the buf */ /* how many chars can we encode within the buf */
maxsize = BLKSIZE_RAW * (*buflen / BLKSIZE_ENC); maxsize = BLKSIZE_RAW * (*buflen / BLKSIZE_ENC);
/* how big will the encoded data be */ /* how big will the encoded data be */