From: Matthias Clasen Date: Tue, 8 Feb 2005 04:28:31 +0000 (+0000) Subject: New function to list all environment variables. (#166327, Hans Petter X-Git-Tag: GLIB_2_7_0~177 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f18cab0ce371406e5913ec31d7f5bac35d072f15;p=platform%2Fupstream%2Fglib.git New function to list all environment variables. (#166327, Hans Petter 2005-02-07 Matthias Clasen * glib/glib.symbols: * glib/gutils.h: * glib/gutils.c (g_listenv): New function to list all environment variables. (#166327, Hans Petter Jansson) --- diff --git a/ChangeLog b/ChangeLog index a6260e2..3101db1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-02-07 Matthias Clasen + + * glib/glib.symbols: + * glib/gutils.h: + * glib/gutils.c (g_listenv): New function to list all + environment variables. (#166327, Hans Petter Jansson) + 2005-02-07 Tor Lillqvist * glib-zip.in: Add gmodule-no-export-2.0.pc. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index a6260e2..3101db1 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +2005-02-07 Matthias Clasen + + * glib/glib.symbols: + * glib/gutils.h: + * glib/gutils.c (g_listenv): New function to list all + environment variables. (#166327, Hans Petter Jansson) + 2005-02-07 Tor Lillqvist * glib-zip.in: Add gmodule-no-export-2.0.pc. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index a6260e2..3101db1 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,10 @@ +2005-02-07 Matthias Clasen + + * glib/glib.symbols: + * glib/gutils.h: + * glib/gutils.c (g_listenv): New function to list all + environment variables. (#166327, Hans Petter Jansson) + 2005-02-07 Tor Lillqvist * glib-zip.in: Add gmodule-no-export-2.0.pc. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index a6260e2..3101db1 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +2005-02-07 Matthias Clasen + + * glib/glib.symbols: + * glib/gutils.h: + * glib/gutils.c (g_listenv): New function to list all + environment variables. (#166327, Hans Petter Jansson) + 2005-02-07 Tor Lillqvist * glib-zip.in: Add gmodule-no-export-2.0.pc. diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 0dd4579..7a8e1b4 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2005-02-07 Matthias Clasen + + * glib/glib-sections.txt: Add g_listenv. + 2005-02-04 Matthias Clasen * glib/tmpl/linked_lists_double.sgml: diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 07ad82b..a68bb2f 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -1283,6 +1283,7 @@ g_set_prgname g_getenv g_setenv g_unsetenv +g_listenv g_get_user_name g_get_real_name g_get_user_cache_dir diff --git a/glib/glib.symbols b/glib/glib.symbols index ea4c785..ec32726 100644 --- a/glib/glib.symbols +++ b/glib/glib.symbols @@ -372,6 +372,7 @@ g_key_file_set_string_list g_key_file_set_value g_key_file_to_data G_GNUC_MALLOC glib_check_version +g_listenv g_list_alloc g_list_append g_list_concat diff --git a/glib/gutils.c b/glib/gutils.c index 61ec38f..7806d75 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -1215,12 +1215,12 @@ g_setenv (const gchar *variable, } #ifndef G_OS_WIN32 -#ifndef HAVE_UNSETENV + /* According to the Single Unix Specification, environ is not in * any system header, although unistd.h often declares it. */ extern char **environ; -#endif + #endif /** @@ -1312,6 +1312,36 @@ g_unsetenv (const gchar *variable) #endif /* G_OS_WIN32 */ } +/** + * g_listenv: + * + * Gets the names of all variables set in the environment. + * + * Return: a NUL-terminated list of strings which must be freed + * with g_strfreev(). + * + * Since: 2.8 + */ +gchar ** +g_listenv (void) +{ + gchar **result, *eq; + gint len, i; + + len = g_strv_length (environ); + result = g_new0 (gchar *, len + 1); + + for (i = 0; i < len; i++) + { + eq = strchr (environ[i], '='); + result[i] = g_strndup (environ[i], eq - environ[i]); + } + + result[len] = NULL; + + return result; +} + G_LOCK_DEFINE_STATIC (g_utils_global); static gchar *g_tmp_dir = NULL; diff --git a/glib/gutils.h b/glib/gutils.h index 08634c4..f2e483b 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -193,7 +193,7 @@ gboolean g_setenv (const gchar *variable, const gchar *value, gboolean overwrite); void g_unsetenv (const gchar *variable); - +gchar** g_listenv (void); /* we try to provide a usefull equivalent for ATEXIT if it is * not defined, but use is actually abandoned. people should