Separate implementation on Win32: Use the wide character API on NT-based
authorTor Lillqvist <tml@novell.com>
Wed, 1 Mar 2006 14:18:55 +0000 (14:18 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Wed, 1 Mar 2006 14:18:55 +0000 (14:18 +0000)
2006-03-01  Tor Lillqvist  <tml@novell.com>

* 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
ChangeLog.pre-2-10
ChangeLog.pre-2-12
glib/glib.symbols
glib/gutils.c

index a64a3b8..a33c43c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-03-01  Tor Lillqvist  <tml@novell.com>
+
+       * 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  <mclasen@redhat.com>
 
        * configure.in: Bump version
index a64a3b8..a33c43c 100644 (file)
@@ -1,3 +1,12 @@
+2006-03-01  Tor Lillqvist  <tml@novell.com>
+
+       * 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  <mclasen@redhat.com>
 
        * configure.in: Bump version
index a64a3b8..a33c43c 100644 (file)
@@ -1,3 +1,12 @@
+2006-03-01  Tor Lillqvist  <tml@novell.com>
+
+       * 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  <mclasen@redhat.com>
 
        * configure.in: Bump version
index 624b25c..2b88fec 100644 (file)
@@ -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
index b0df1f4..83ab9b1 100644 (file)
@@ -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);