cvs: /php4/ext/standard base64.c
| From: | Sascha Schumann | Date: | Wed, 21 Jul 1999 09:02:06 +0000 |
| Subject: | cvs: /php4/ext/standard base64.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-2404@lists.php.net to get a copy of this message | ||
sas Wed Jul 21 05:02:06 1999 EDT
Modified files:
/php4/ext/standard base64.c
Log:
use reverse lookup array, submitted by bfranklin@dct.com, #1755
Index: php4/ext/standard/base64.c
diff -u php4/ext/standard/base64.c:1.6 php4/ext/standard/base64.c:1.7
--- php4/ext/standard/base64.c:1.6 Fri Jul 16 09:12:55 1999
+++ php4/ext/standard/base64.c Wed Jul 21 05:02:05 1999
@@ -15,7 +15,7 @@
| Author: Jim Winstead (jimw@php.net) |
+----------------------------------------------------------------------+
*/
-/* $Id: base64.c,v 1.6 1999/07/16 13:12:55 zeev Exp $ */
+/* $Id: base64.c,v 1.7 1999/07/21 09:02:05 sas Exp $ */
#include <string.h>
@@ -71,6 +71,19 @@
unsigned char *_php3_base64_decode(const unsigned char *string, int length, int *ret_length) {
const unsigned char *current = string;
int ch, i = 0, j = 0, k;
+ /* this sucks for threaded environments */
+ static short reverse_table[256];
+ static int table_built;
+
+ if(++table_built == 1) {
+ char *chp;
+ for(ch = 0; ch < 256; ch++) {
+ chp = strchr(base64_table, ch);
+ if(chp)
+ reverse_table[ch] = chp - base64_table;
+ else
+ reverse_table[ch] = -1;
+ }
unsigned char *result = (unsigned char *)emalloc((length / 4 * 3 + 1) * sizeof(char));
if (result == NULL) {
@@ -80,9 +93,8 @@
/* run through the whole string, converting as we go */
while ((ch = *current++) != '\0') {
if (ch == base64_pad) break;
- ch = (int)strchr(base64_table, ch);
- if (ch == 0) continue;
- ch -= (int)base64_table;
+ ch = reverse_table[ch];
+ if (ch < 0) continue;
switch(i % 4) {
case 0: