We have to do some initialization before the string conversion
authorMartin Pool <mbp@samba.org>
Tue, 22 Jan 2002 03:51:28 +0000 (03:51 +0000)
committerMartin Pool <mbp@samba.org>
Tue, 22 Jan 2002 03:51:28 +0000 (03:51 +0000)
routines can work.  The code was copied into both convert_string and
convert_string_allocate -- I split it into a little static function,
and removed an apparently duplicate call to init_valid_table().
(This used to be commit 7f7d22880d40c7344bc402203dd150255fc694cf)

source3/lib/charcnv.c

index 481effbad5221a0e6c41d8a80db626898af61c90..48b9cad7319bbe02444ac190aa200f9ecf112b17 100644 (file)
@@ -27,8 +27,6 @@ static pstring cvtbuf;
 
 static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
 
-static int initialized;
-
 /****************************************************************************
 return the name of a charset to give to iconv()
 ****************************************************************************/
@@ -45,6 +43,19 @@ static char *charset_name(charset_t ch)
        return ret;
 }
 
+
+static void lazy_initialize_conv(void)
+{
+       static int initialized = False;
+
+       if (!initialized) {
+               initialized = True;
+               load_case_tables();
+               init_iconv();
+               init_valid_table();
+       }
+}
+
 /****************************************************************************
  Initialize iconv conversion descriptors 
 ****************************************************************************/
@@ -112,12 +123,7 @@ size_t convert_string(charset_t from, charset_t to,
 
        if (srclen == -1) srclen = strlen(src)+1;
 
-       if (!initialized) {
-               initialized = 1;
-               load_case_tables();
-               init_iconv();
-               init_valid_table();
-       }
+       lazy_initialize_conv();
 
        descriptor = conv_handles[from][to];
 
@@ -174,11 +180,7 @@ size_t convert_string_allocate(charset_t from, charset_t to,
 
        if (src == NULL || srclen == -1) return -1;
 
-       if (!initialized) {
-               initialized = 1;
-               load_case_tables();
-               init_iconv();
-       }
+       lazy_initialize_conv();
 
        descriptor = conv_handles[from][to];