From 5a2950d04112b0ed6c0a524ade58a73579b8842a Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 1 Mar 2006 14:18:55 +0000 Subject: [PATCH] Separate implementation on Win32: Use the wide character API on NT-based 2006-03-01 Tor Lillqvist * glib/gutils.c (g_listenv): Separate implementation on Win32: Use the wide character API on NT-based Windows. Return UTF-8 strings. * glib/glib.symbols: Don't mark g_listenv as PRIVATE, as that meant it wasn't present in the import library. PRIVATE is used only for the backwards-compatibility DLL ABI stability hacks. --- ChangeLog | 9 ++++++ ChangeLog.pre-2-10 | 9 ++++++ ChangeLog.pre-2-12 | 9 ++++++ glib/glib.symbols | 2 +- glib/gutils.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a64a3b8ca..a33c43c39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-03-01 Tor Lillqvist + + * glib/gutils.c (g_listenv): Separate implementation on Win32: Use + the wide character API on NT-based Windows. Return UTF-8 strings. + + * glib/glib.symbols: Don't mark g_listenv as PRIVATE, as that + meant it wasn't present in the import library. PRIVATE is used + only for the backwards-compatibility DLL ABI stability hacks. + 2006-02-24 Matthias Clasen * configure.in: Bump version diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index a64a3b8ca..a33c43c39 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +2006-03-01 Tor Lillqvist + + * glib/gutils.c (g_listenv): Separate implementation on Win32: Use + the wide character API on NT-based Windows. Return UTF-8 strings. + + * glib/glib.symbols: Don't mark g_listenv as PRIVATE, as that + meant it wasn't present in the import library. PRIVATE is used + only for the backwards-compatibility DLL ABI stability hacks. + 2006-02-24 Matthias Clasen * configure.in: Bump version diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index a64a3b8ca..a33c43c39 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,12 @@ +2006-03-01 Tor Lillqvist + + * glib/gutils.c (g_listenv): Separate implementation on Win32: Use + the wide character API on NT-based Windows. Return UTF-8 strings. + + * glib/glib.symbols: Don't mark g_listenv as PRIVATE, as that + meant it wasn't present in the import library. PRIVATE is used + only for the backwards-compatibility DLL ABI stability hacks. + 2006-02-24 Matthias Clasen * configure.in: Bump version diff --git a/glib/glib.symbols b/glib/glib.symbols index 624b25cd5..2b88fec02 100644 --- a/glib/glib.symbols +++ b/glib/glib.symbols @@ -1239,7 +1239,7 @@ g_unsetenv PRIVATE g_get_home_dir PRIVATE g_get_host_name g_setenv PRIVATE -g_listenv PRIVATE +g_listenv #ifdef G_OS_WIN32 g_find_program_in_path_utf8 g_get_current_dir_utf8 diff --git a/glib/gutils.c b/glib/gutils.c index b0df1f4ba..83ab9b1a5 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -1406,6 +1406,7 @@ g_unsetenv (const gchar *variable) gchar ** g_listenv (void) { +#ifndef G_OS_WIN32 gchar **result, *eq; gint len, i, j; @@ -1423,6 +1424,73 @@ g_listenv (void) result[j] = NULL; return result; +#else + gchar **result, *eq; + gint len = 0, i, j; + + if (G_WIN32_HAVE_WIDECHAR_API ()) + { + wchar_t *p, *q; + + p = (wchar_t *) GetEnvironmentStringsW (); + if (p != NULL) + { + q = p; + while (*q) + { + q += wcslen (q) + 1; + len++; + } + } + result = g_new0 (gchar *, len + 1); + + j = 0; + q = p; + while (*q) + { + result[j] = g_utf16_to_utf8 (q, -1, NULL, NULL, NULL); + if (result[j] != NULL) + { + eq = strchr (result[j], '='); + if (eq && eq > result[j]) + { + *eq = '\0'; + j++; + } + else + g_free (result[j]); + } + q += wcslen (q) + 1; + } + result[j] = NULL; + FreeEnvironmentStringsW (p); + } + else + { + len = g_strv_length (environ); + result = g_new0 (gchar *, len + 1); + + j = 0; + for (i = 0; i < len; i++) + { + result[j] = g_locale_to_utf8 (environ[i], -1, NULL, NULL, NULL); + if (result[j] != NULL) + { + eq = strchr (result[j], '='); + if (eq && eq > result[j]) + { + *eq = '\0'; + j++; + } + else + g_free (result[j]); + } + } + result[j] = NULL; + } + + return result; +#endif } G_LOCK_DEFINE_STATIC (g_utils_global);