From 7f7d22880d40c7344bc402203dd150255fc694cf Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 22 Jan 2002 03:51:28 +0000 Subject: We have to do some initialization before the string conversion 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(). --- source/lib/charcnv.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'source/lib') diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c index 481effbad52..48b9cad7319 100644 --- a/source/lib/charcnv.c +++ b/source/lib/charcnv.c @@ -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]; -- cgit