From: Martin Mares Date: Sat, 11 Feb 2012 20:11:11 +0000 (+0100) Subject: Base64: Made thread-safe X-Git-Tag: v5.0~41 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=fc44bcb9343984091d9cd1a9474d03d78a988332;p=libucw.git Base64: Made thread-safe --- diff --git a/ucw/base64.c b/ucw/base64.c index 9865f4c6..56f30766 100644 --- a/ucw/base64.c +++ b/ucw/base64.c @@ -11,6 +11,7 @@ #include "ucw/lib.h" #include "ucw/base64.h" +#include "ucw/threads.h" #include @@ -67,16 +68,17 @@ base64_decode(byte *dest, const byte *src, uns len) static uns table_built = 0; if (table_built == 0) { - byte *chp; - table_built = 1; + ucwlib_lock(); for(ch = 0; ch < 256; ch++) { - chp = strchr(base64_table, ch); + byte *chp = strchr(base64_table, ch); if(chp) { reverse_table[ch] = chp - base64_table; } else { reverse_table[ch] = 0xff; } } + table_built = 1; + ucwlib_unlock(); } /* run through the whole string, converting as we go */