From 2e0f2b8dfc9327d69c605ec7f498da1a38222050 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 12 Jun 2006 16:54:51 +0000 Subject: [PATCH] Use g_listenv() and g_getenv() instead of looking at environ directly. 2006-06-12 Tor Lillqvist * app/plug-in/gimpenvirontable.c (gimp_environ_table_populate): Use g_listenv() and g_getenv() instead of looking at environ directly. Fixes breakage on Win32 when any (!) environment variable has a non-ASCII value, as environ is in system codepage, while we want UTF-8. --- ChangeLog | 8 ++++++++ app/plug-in/gimpenvirontable.c | 29 ++++++++++------------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61faa30ec5..29820acb21 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-06-12 Tor Lillqvist + + * app/plug-in/gimpenvirontable.c (gimp_environ_table_populate): + Use g_listenv() and g_getenv() instead of looking at environ + directly. Fixes breakage on Win32 when any (!) environment + variable has a non-ASCII value, as environ is in system codepage, + while we want UTF-8. + 2006-06-12 Sven Neumann * plug-ins/common/redeye.c (remove_redeye): cleanup, use diff --git a/app/plug-in/gimpenvirontable.c b/app/plug-in/gimpenvirontable.c index 459a2080d6..5ab5dc55df 100644 --- a/app/plug-in/gimpenvirontable.c +++ b/app/plug-in/gimpenvirontable.c @@ -46,10 +46,6 @@ struct _GimpEnvironValue }; -/* FIXME: check how portable this is */ -extern char **environ; - - static void gimp_environ_table_finalize (GObject *object); static void gimp_environ_table_load_env_file (const GimpDatafileData *file_data, @@ -301,26 +297,20 @@ gimp_environ_table_legal_name (gchar *name) static void gimp_environ_table_populate (GimpEnvironTable *environ_table) { - gchar **var = environ; - gchar *name, *p; + gchar **var = g_listenv (); GPtrArray *env_array; env_array = g_ptr_array_new (); while (*var) { - p = strchr (*var, '='); + /* g_listenv() only returns the names of environment variables + * that are correctly specified (name=value) in the environ + * array (Unix) or the process environment string table (Win32). + */ - /* shouldn't happen... but just to be safe... */ - if (p) - { - name = g_strndup (*var, p - *var); - - if (gimp_environ_table_pass_through (environ_table, name)) - g_ptr_array_add (env_array, g_strdup (*var)); - - g_free (name); - } + if (gimp_environ_table_pass_through (environ_table, *var)) + g_ptr_array_add (env_array, g_strconcat (*var, "=", g_getenv (*var), NULL)); var++; } @@ -356,11 +346,12 @@ gimp_environ_table_populate_one (const gchar *name, GimpEnvironValue *val, GPtrArray *env_array) { - gchar *old, *var = NULL; + const gchar *old; + gchar *var = NULL; if (val->separator) { - old = getenv (name); + old = g_getenv (name); if (old) var = g_strconcat (name, "=", val->value, val->separator, old, NULL);