summaryrefslogtreecommitdiff
path: root/lib/util/charset
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-02-18 13:59:05 +1100
committerAndrew Bartlett <abartlet@samba.org>2011-02-18 09:29:35 +0100
commit1ad8e5229f618fc04af371ba52b81f2e7e1f88f5 (patch)
tree691e7f9788fe4c5f2a8e21af7c88d4525813aedb /lib/util/charset
parent2a3a86a86f3d1ab97adda563beda7ee35f6a2414 (diff)
downloadsamba-1ad8e5229f618fc04af371ba52b81f2e7e1f88f5.tar.gz
samba-1ad8e5229f618fc04af371ba52b81f2e7e1f88f5.tar.bz2
samba-1ad8e5229f618fc04af371ba52b81f2e7e1f88f5.zip
lib/util/charset Add back setlocale(), but only when called from binaries
When called from a library, we don't want to call this, as we may overwrite some of our calling program's context. Andrew Bartlett Autobuild-User: Andrew Bartlett <abartlet@samba.org> Autobuild-Date: Fri Feb 18 09:29:35 CET 2011 on sn-devel-104
Diffstat (limited to 'lib/util/charset')
-rw-r--r--lib/util/charset/charset.h1
-rw-r--r--lib/util/charset/codepoints.c26
2 files changed, 24 insertions, 3 deletions
diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h
index b4a5a55461..474d77e54e 100644
--- a/lib/util/charset/charset.h
+++ b/lib/util/charset/charset.h
@@ -223,6 +223,7 @@ smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode,
const char *fromcode, bool native_iconv);
void load_case_tables(void);
+void load_case_tables_library(void);
bool smb_register_charset(const struct charset_functions *funcs_in);
/*
diff --git a/lib/util/charset/codepoints.c b/lib/util/charset/codepoints.c
index 01183e4ad4..5ee95a8af5 100644
--- a/lib/util/charset/codepoints.c
+++ b/lib/util/charset/codepoints.c
@@ -42,8 +42,10 @@ static void *lowcase_table;
/*******************************************************************
load the case handling tables
+
+This is the function that should be called from library code.
********************************************************************/
-void load_case_tables(void)
+void load_case_tables_library(void)
{
TALLOC_CTX *mem_ctx;
@@ -64,6 +66,24 @@ void load_case_tables(void)
}
}
+/*******************************************************************
+load the case handling tables
+
+This MUST only be called from main() in application code, never from a
+library. We don't know if the calling program has already done
+setlocale() to another value, and can't tell if they have.
+********************************************************************/
+void load_case_tables(void)
+{
+ /* This is a useful global hook where we can ensure that the
+ * locale is set from the environment. This is needed so that
+ * we can use LOCALE as a codepage */
+#ifdef HAVE_SETLOCALE
+ setlocale(LC_ALL, "");
+#endif
+ load_case_tables_library();
+}
+
/**
Convert a codepoint_t to upper case.
**/
@@ -73,7 +93,7 @@ _PUBLIC_ codepoint_t toupper_m(codepoint_t val)
return toupper(val);
}
if (upcase_table == NULL) {
- load_case_tables();
+ load_case_tables_library();
}
if (upcase_table == (void *)-1) {
return val;
@@ -93,7 +113,7 @@ _PUBLIC_ codepoint_t tolower_m(codepoint_t val)
return tolower(val);
}
if (lowcase_table == NULL) {
- load_case_tables();
+ load_case_tables_library();
}
if (lowcase_table == (void *)-1) {
return val;