RFC: IDN support in getaddrinfo().
Simon Josefsson
jas@extundo.com
Mon Mar 8 19:50:00 GMT 2004
Ulrich Drepper <drepper@redhat.com> writes:
> ~ the toutf8 code supports glibc now correctly. Note, the non-glibc
> code isn't really right. You cannot use setlocale() if the program
> hasn't done it by itself. And I don't think using the CHARSET envvar
> is wise either. Just require the application to chose the right
> locale. This is what the glibc code now does.
This reflect what's going into libidn 0.4.1.
2004-03-08 Simon Josefsson <jas@extundo.com>
* toutf8.c (stringprep_locale_charset_slow): Remove.
(stringprep_locale_charset): Rewrite.
Index: toutf8.c
===================================================================
RCS file: /cvs/glibc/libc/libidn/toutf8.c,v
retrieving revision 1.2
diff -u -p -u -w -r1.2 toutf8.c
--- toutf8.c 8 Mar 2004 07:53:35 -0000 1.2
+++ toutf8.c 8 Mar 2004 19:47:40 -0000
@@ -45,70 +45,46 @@
# include <locale.h>
# endif
-# ifndef _LIBC
-static const char *
-stringprep_locale_charset_slow (void)
+# ifdef _LIBC
+# define stringprep_locale_charset() nl_langinfo (CODESET)
+# else
+/**
+ * stringprep_locale_charset:
+ *
+ * Find out current locale charset. The function respect the CHARSET
+ * environment variable, but typically uses nl_langinfo(CODESET) when
+ * it is supported. It fall back on "ASCII" if CHARSET isn't set and
+ * nl_langinfo isn't supported or return anything.
+ *
+ * Note that this function return the application's locale's preferred
+ * charset (or thread's locale's preffered charset, if your system
+ * support thread-specific locales). It does not return what the
+ * system may be using. Thus, if you receive data from external
+ * sources you cannot in general use this function to guess what
+ * charset it is encoded in. Use stringprep_convert from the external
+ * representation into the charset returned by this function, to have
+ * data in the locale encoding.
+ *
+ * Return value: Return the character set used by the current locale.
+ * It will never return NULL, but use "ASCII" as a fallback.
+ **/
+const char *
+stringprep_locale_charset (void)
{
- return nl_langinfo (CODESET);
const char *charset = getenv ("CHARSET"); /* flawfinder: ignore */
if (charset && *charset)
return charset;
# ifdef LOCALE_WORKS
- {
- char *p;
-
- p = setlocale (LC_CTYPE, NULL);
- setlocale (LC_CTYPE, "");
-
charset = nl_langinfo (CODESET);
- setlocale (LC_CTYPE, p);
-
if (charset && *charset)
return charset;
- }
# endif
return "ASCII";
}
-
-static const char *stringprep_locale_charset_cache;
-# endif
-
-/**
- * stringprep_locale_charset:
- *
- * Find out system locale charset.
- *
- * Note that this function return what it believe the SYSTEM is using
- * as a locale, not what locale the program is currently in (modified,
- * e.g., by a setlocale(LC_CTYPE, "ISO-8859-1")). The reason is that
- * data read from argv[], stdin etc comes from the system, and is more
- * likely to be encoded using the system locale than the program
- * locale.
- *
- * You can set the environment variable CHARSET to override the value
- * returned. Note that this function caches the result, so you will
- * have to modify CHARSET before calling (even indirectly) any
- * stringprep functions, e.g., by setting it when invoking the
- * application.
- *
- * Return value: Return the character set used by the system locale.
- * It will never return NULL, but use "ASCII" as a fallback.
- **/
-# ifdef _LIBC
-# define stringprep_locale_charset() nl_langinfo (CODESET)
-# else
-const char *
-stringprep_locale_charset (void)
-{
- if (!stringprep_locale_charset_cache)
- stringprep_locale_charset_cache = stringprep_locale_charset_slow ();
-
- return stringprep_locale_charset_cache;
-}
# endif
/**
More information about the Libc-alpha
mailing list