+}
+
+/**
+ * g_setenv:
+ * @variable: the environment variable to set, must not contain '='.
+ * @value: the value for to set the variable to.
+ * @overwrite: whether to change the variable if it already exists.
+ *
+ * Sets an environment variable. Both the variable's name and value
+ * should be in the GLib file name encoding. On UNIX, this means that
+ * they can be arbitrary byte strings. On Windows, they should be in
+ * UTF-8.
+ *
+ * Note that on some systems, when variables are overwritten, the memory
+ * used for the previous variables and its value isn't reclaimed.
+ *
+ * You should be mindful of the fact that environment variable handling
+ * in UNIX is not thread-safe, and your program may crash if one thread
+ * calls g_setenv() while another thread is calling getenv(). (And note
+ * that many functions, such as gettext(), call getenv() internally.)
+ * This function is only safe to use at the very start of your program,
+ * before creating any other threads (or creating objects that create
+ * worker threads of their own).
+ *
+ * If you need to set up the environment for a child process, you can
+ * use g_get_environ() to get an environment array, modify that with
+ * g_environ_setenv() and g_environ_unsetenv(), and then pass that
+ * array directly to execvpe(), g_spawn_async(), or the like.
+ *
+ * Returns: %FALSE if the environment variable couldn't be set.
+ *
+ * Since: 2.4
+ */
+gboolean
+g_setenv (const gchar *variable,
+ const gchar *value,
+ gboolean overwrite)
+{
+ gint result;
+#ifndef HAVE_SETENV
+ gchar *string;
+#endif
+
+ g_return_val_if_fail (variable != NULL, FALSE);
+ g_return_val_if_fail (strchr (variable, '=') == NULL, FALSE);
+ g_return_val_if_fail (value != NULL, FALSE);
+
+#ifdef HAVE_SETENV
+ result = setenv (variable, value, overwrite);
+#else
+ if (!overwrite && getenv (variable) != NULL)
+ return TRUE;
+
+ /* This results in a leak when you overwrite existing
+ * settings. It would be fairly easy to fix this by keeping
+ * our own parallel array or hash table.
+ */
+ string = g_strconcat (variable, "=", value, NULL);
+ result = putenv (string);
+#endif
+ return result == 0;
+}
+
+#ifdef HAVE__NSGETENVIRON
+#define environ (*_NSGetEnviron())
+#else
+/* According to the Single Unix Specification, environ is not
+ * in any system header, although unistd.h often declares it.
+ */
+extern char **environ;
+#endif
+
+/**
+ * g_unsetenv:
+ * @variable: the environment variable to remove, must not contain '='
+ *
+ * Removes an environment variable from the environment.
+ *
+ * Note that on some systems, when variables are overwritten, the
+ * memory used for the previous variables and its value isn't reclaimed.
+ *
+ * You should be mindful of the fact that environment variable handling
+ * in UNIX is not thread-safe, and your program may crash if one thread
+ * calls g_unsetenv() while another thread is calling getenv(). (And note
+ * that many functions, such as gettext(), call getenv() internally.) This
+ * function is only safe to use at the very start of your program, before
+ * creating any other threads (or creating objects that create worker
+ * threads of their own).
+ *
+ * If you need to set up the environment for a child process, you can
+ * use g_get_environ() to get an environment array, modify that with
+ * g_environ_setenv() and g_environ_unsetenv(), and then pass that
+ * array directly to execvpe(), g_spawn_async(), or the like.
+ *
+ * Since: 2.4
+ */
+void
+g_unsetenv (const gchar *variable)
+{
+ g_return_if_fail (variable != NULL);
+ g_return_if_fail (strchr (variable, '=') == NULL);
+
+#ifdef HAVE_UNSETENV
+ unsetenv (variable);
+#else /* !HAVE_UNSETENV */
+ /* Mess directly with the environ array.
+ * This seems to be the only portable way to do this.
+ */
+ g_environ_unsetenv_internal (environ, variable, FALSE);
+#endif /* !HAVE_UNSETENV */
+}
+
+/**
+ * g_listenv:
+ *
+ * Gets the names of all variables set in the environment.
+ *
+ * Programs that want to be portable to Windows should typically use
+ * this function and g_getenv() instead of using the environ array
+ * from the C library directly. On Windows, the strings in the environ
+ * array are in system codepage encoding, while in most of the typical
+ * use cases for environment variables in GLib-using programs you want
+ * the UTF-8 encoding that this function and g_getenv() provide.
+ *
+ * Returns: (array zero-terminated=1) (transfer full): a %NULL-terminated
+ * list of strings which must be freed with g_strfreev().
+ *
+ * Since: 2.8
+ */
+gchar **
+g_listenv (void)
+{
+ gchar **result, *eq;
+ gint len, i, j;
+
+ len = g_strv_length (environ);
+ result = g_new0 (gchar *, len + 1);
+
+ j = 0;
+ for (i = 0; i < len; i++)
+ {
+ eq = strchr (environ[i], '=');
+ if (eq)
+ result[j++] = g_strndup (environ[i], eq - environ[i]);
+ }
+
+ result[j] = NULL;