summaryrefslogtreecommitdiff
path: root/source3/lib/util_unistr.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2005-12-27 20:52:36 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:05:58 -0500
commit5a4881bf396e691524329bcd6aa1ae4a7f4084ec (patch)
treeea2cce14847e28629ec48f2a70f547bdbb08fe98 /source3/lib/util_unistr.c
parentd186ff50721011f839a02aaac4866201eda23034 (diff)
downloadsamba-5a4881bf396e691524329bcd6aa1ae4a7f4084ec.tar.gz
samba-5a4881bf396e691524329bcd6aa1ae4a7f4084ec.tar.bz2
samba-5a4881bf396e691524329bcd6aa1ae4a7f4084ec.zip
r12522: Try and fix bug #2926 by removing setlocale(LC_ALL, "C")
and replace calls to isupper/islower/toupper/tolower with ASCII equivalents (mapping into _w variants). Jeremy. (This used to be commit c2752347eb2deeb2798c580ec7fc751a847717e9)
Diffstat (limited to 'source3/lib/util_unistr.c')
-rw-r--r--source3/lib/util_unistr.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index b979745d36..880416a549 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -51,6 +51,7 @@ static uint8 doschar_table[8192]; /* 65536 characters / 8 bits/byte */
void load_case_tables(void)
{
static int initialised;
+ char *old_locale = NULL, *saved_locale = NULL;
int i;
if (initialised) {
@@ -61,6 +62,17 @@ void load_case_tables(void)
upcase_table = map_file(lib_path("upcase.dat"), 0x20000);
lowcase_table = map_file(lib_path("lowcase.dat"), 0x20000);
+#ifdef HAVE_SETLOCALE
+ /* Get the name of the current locale. */
+ old_locale = setlocale(LC_ALL, NULL);
+
+ /* Save it as it is in static storage. */
+ saved_locale = SMB_STRDUP(old_locale);
+
+ /* We set back the locale to C to get ASCII-compatible toupper/lower functions. */
+ setlocale(LC_ALL, "C");
+#endif
+
/* we would like Samba to limp along even if these tables are
not available */
if (!upcase_table) {
@@ -92,6 +104,12 @@ void load_case_tables(void)
lowcase_table[v] = UCS2_CHAR(isupper(i)?tolower(i):i);
}
}
+
+#ifdef HAVE_SETLOCALE
+ /* Restore the old locale. */
+ setlocale (LC_ALL, saved_locale);
+ SAFE_FREE(saved_locale);
+#endif
}
/*
@@ -997,3 +1015,41 @@ UNISTR2* ucs2_to_unistr2(TALLOC_CTX *ctx, UNISTR2* dst, smb_ucs2_t* src)
return dst;
}
+
+/*************************************************************
+ ascii only toupper - saves the need for smbd to be in C locale.
+*************************************************************/
+
+int toupper_ascii(int c)
+{
+ smb_ucs2_t uc = toupper_w(UCS2_CHAR(c));
+ return UCS2_TO_CHAR(uc);
+}
+
+/*************************************************************
+ ascii only tolower - saves the need for smbd to be in C locale.
+*************************************************************/
+
+int tolower_ascii(int c)
+{
+ smb_ucs2_t uc = tolower_w(UCS2_CHAR(c));
+ return UCS2_TO_CHAR(uc);
+}
+
+/*************************************************************
+ ascii only isupper - saves the need for smbd to be in C locale.
+*************************************************************/
+
+int isupper_ascii(int c)
+{
+ return isupper_w(UCS2_CHAR(c));
+}
+
+/*************************************************************
+ ascii only islower - saves the need for smbd to be in C locale.
+*************************************************************/
+
+int islower_ascii(int c)
+{
+ return islower_w(UCS2_CHAR(c));
+}