]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/base64.c
ABI tools: Better reporting of missing files
[libucw.git] / ucw / base64.c
index 9865f4c60c5c1a4101a0252d1def151d47112f1e..997b6da5e1c41bbd14d63bc720d776e6a5a28b0a 100644 (file)
@@ -9,8 +9,9 @@
 
 #undef LOCAL_DEBUG
 
-#include "ucw/lib.h"
-#include "ucw/base64.h"
+#include <ucw/lib.h>
+#include <ucw/base64.h>
+#include <ucw/threads.h>
 
 #include <string.h>
 
@@ -23,11 +24,11 @@ static const byte base64_table[] =
        };
 static const byte base64_pad = '=';
 
-uns
-base64_encode(byte *dest, const byte *src, uns len)
+uint
+base64_encode(byte *dest, const byte *src, uint len)
 {
        const byte *current = src;
-       uns i = 0;
+       uint i = 0;
 
        while (len > 2) { /* keep going until we have less than 24 bits */
                dest[i++] = base64_table[current[0] >> 2];
@@ -57,26 +58,27 @@ base64_encode(byte *dest, const byte *src, uns len)
 }
 
 /* as above, but backwards. :) */
-uns
-base64_decode(byte *dest, const byte *src, uns len)
+uint
+base64_decode(byte *dest, const byte *src, uint len)
 {
        const byte *current = src;
-       uns ch;
-       uns i = 0, j = 0;
+       uint ch;
+       uint i = 0, j = 0;
        static byte reverse_table[256];
-       static uns table_built = 0;
+       static uint 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 */