Patch from vorlon@debian.org, see bugzilal #122
authorJohn Terpstra <jht@samba.org>
Sun, 15 Jun 2003 06:07:53 +0000 (06:07 +0000)
committerJohn Terpstra <jht@samba.org>
Sun, 15 Jun 2003 06:07:53 +0000 (06:07 +0000)
Samba should preferentially use the locale information from the native system,
and only fall back on 'display charset' if this is unavailable or unsupported.

source/configure.in
source/include/includes.h
source/lib/charcnv.c

index c81712da5cf774e9603d80da69b3d58f242532c5..7a116b60ab5a30142976508e9e23aa4c8e3ff454 100644 (file)
@@ -529,6 +529,7 @@ AC_CHECK_HEADERS(sys/mount.h sys/vfs.h sys/fs/s5param.h sys/filsys.h termios.h t
 AC_CHECK_HEADERS(sys/termio.h sys/statfs.h sys/dustat.h sys/statvfs.h stdarg.h sys/sockio.h)
 AC_CHECK_HEADERS(security/pam_modules.h security/_pam_macros.h dlfcn.h)
 AC_CHECK_HEADERS(sys/syslog.h syslog.h execinfo.h)
+AC_CHECK_HEADERS(langinfo.h locale.h)
 
 # In valgrind 1.0.x, it's just valgrind.h.  In 1.9.x+ there's a
 # subdirectory of headers.
@@ -843,6 +844,7 @@ AC_CHECK_FUNCS(lstat64 fopen64 atexit grantpt dup2 lseek64 ftruncate64 readdir64
 AC_CHECK_FUNCS(fseek64 fseeko64 ftell64 ftello64 setluid getpwanam setlinebuf)
 AC_CHECK_FUNCS(srandom random srand rand setenv usleep strcasecmp fcvt fcvtl symlink readlink)
 AC_CHECK_FUNCS(syslog vsyslog getgrouplist timegm)
+AC_CHECK_FUNCS(setlocale nl_langinfo)
 # setbuffer, shmget, shm_open are needed for smbtorture
 AC_CHECK_FUNCS(setbuffer shmget shm_open backtrace_symbols)
 
index 3dbe6d10934b58cb00a0ac07bd378c0cb20d5154..edaeda3abedaf55bb659aeb10f0b3639d6a8851f 100644 (file)
 #include <attr/xattr.h>
 #endif
 
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+#if HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+
 /* Special macros that are no-ops except when run under Valgrind on
  * x86.  They've moved a little bit from valgrind 1.0.4 to 1.9.4 */
 #if HAVE_VALGRIND_MEMCHECK_H
index 708ef343e1a91a704569d7639b09fc6d5abdf9f8..b37f468134dd8915b827e63f73b3b59e66138a3d 100644 (file)
@@ -90,10 +90,28 @@ void init_iconv(void)
        if (!conv_handles[CH_UCS2][CH_UNIX])
                conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", "UCS-2LE");
 
+#ifdef HAVE_SETLOCALE
+       setlocale(LC_ALL, "");
+#endif
+
        for (c1=0;c1<NUM_CHARSETS;c1++) {
                for (c2=0;c2<NUM_CHARSETS;c2++) {
                        const char *n1 = charset_name((charset_t)c1);
                        const char *n2 = charset_name((charset_t)c2);
+#ifdef HAVE_NL_LANGINFO
+                       const char *ln = nl_langinfo(CODESET);
+
+                       if (c1==CH_DISPLAY && conv_handles[c1][c2] &&
+                           strcmp(ln, conv_handles[c1][c2]->from_name) == 0 &&
+                           strcmp(n2, conv_handles[c1][c2]->to_name) == 0)
+                               continue;
+                          
+                       if (c2==CH_DISPLAY && conv_handles[c1][c2] &&
+                           strcmp(n1, conv_handles[c1][c2]->from_name) == 0 &&
+                           strcmp(ln, conv_handles[c1][c2]->to_name) == 0)
+                               continue;
+                          
+#endif
                        if (conv_handles[c1][c2] &&
                            strcmp(n1, conv_handles[c1][c2]->from_name) == 0 &&
                            strcmp(n2, conv_handles[c1][c2]->to_name) == 0)
@@ -104,6 +122,25 @@ void init_iconv(void)
                        if (conv_handles[c1][c2])
                                smb_iconv_close(conv_handles[c1][c2]);
 
+#ifdef HAVE_NL_LANGINFO
+                       if (c1==CH_DISPLAY && c2==CH_DISPLAY) {
+                               conv_handles[c1][c2] = smb_iconv_open(ln,ln);
+                               if (conv_handles[c1][c2] != (smb_iconv_t)-1) {
+                                       continue;
+                               }
+                       } else if (c1==CH_DISPLAY) {
+                               conv_handles[c1][c2] = smb_iconv_open(n2,ln);
+                               if (conv_handles[c1][c2] != (smb_iconv_t)-1) {
+                                       continue;
+                               }
+                       } else if (c2==CH_DISPLAY) {
+                               conv_handles[c1][c2] = smb_iconv_open(ln,n1);
+                               if (conv_handles[c1][c2] != (smb_iconv_t)-1) {
+                                       continue;
+                               }
+                       }
+                       /* Fall back to the configured charset. */
+#endif
                        conv_handles[c1][c2] = smb_iconv_open(n2,n1);
                        if (conv_handles[c1][c2] == (smb_iconv_t)-1) {
                                DEBUG(0,("Conversion from %s to %s not supported\n",