]> mj.ucw.cz Git - libucw.git/commitdiff
Base64: Made thread-safe
authorMartin Mares <mj@ucw.cz>
Sat, 11 Feb 2012 20:11:11 +0000 (21:11 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 11 Feb 2012 20:11:11 +0000 (21:11 +0100)
ucw/base64.c

index 9865f4c60c5c1a4101a0252d1def151d47112f1e..56f30766af1050a4eaa96f928549b57d25c41ebd 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "ucw/lib.h"
 #include "ucw/base64.h"
+#include "ucw/threads.h"
 
 #include <string.h>
 
@@ -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 */