From c3c2c3133561488ce140de4c1a281bca251af311 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 23 Jul 2020 13:20:39 +0530 Subject: [PATCH] glib: Use g_getenv everywhere instead of getenv `getenv()` doesn't work well on Windows, f.ex., it can't fetch env vars set with `SetEnvironmentVariable()`. This also means that it doesn't work at all when targeting UWP since that's the only way to set env vars in that case. --- glib/gconvert.c | 7 ++++--- glib/giowin32.c | 2 +- glib/gmain.c | 2 +- glib/gslice.c | 2 +- glib/gspawn-win32.c | 2 +- glib/gtimezone.c | 2 +- glib/gwin32.c | 16 ++++++++-------- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/glib/gconvert.c b/glib/gconvert.c index 452c852f0..f78cff01d 100644 --- a/glib/gconvert.c +++ b/glib/gconvert.c @@ -49,6 +49,7 @@ #include "gthreadprivate.h" #include "gunicode.h" #include "gfileutils.h" +#include "genviron.h" #include "glibintl.h" @@ -1131,14 +1132,14 @@ g_get_filename_charsets (const gchar ***filename_charsets) if (!(cache->charset && strcmp (cache->charset, charset) == 0)) { const gchar *new_charset; - gchar *p; + const gchar *p; gint i; g_free (cache->charset); g_strfreev (cache->filename_charsets); cache->charset = g_strdup (charset); - p = getenv ("G_FILENAME_ENCODING"); + p = g_getenv ("G_FILENAME_ENCODING"); if (p != NULL && p[0] != '\0') { cache->filename_charsets = g_strsplit (p, ",", 0); @@ -1154,7 +1155,7 @@ g_get_filename_charsets (const gchar ***filename_charsets) } } } - else if (getenv ("G_BROKEN_FILENAMES") != NULL) + else if (g_getenv ("G_BROKEN_FILENAMES") != NULL) { cache->filename_charsets = g_new0 (gchar *, 2); cache->is_utf8 = g_get_charset (&new_charset); diff --git a/glib/giowin32.c b/glib/giowin32.c index 3e38e2a81..b0b6c3d85 100644 --- a/glib/giowin32.c +++ b/glib/giowin32.c @@ -263,7 +263,7 @@ condition_to_string (GIOCondition condition) static gboolean g_io_win32_get_debug_flag (void) { - return (getenv ("G_IO_WIN32_DEBUG") != NULL); + return (g_getenv ("G_IO_WIN32_DEBUG") != NULL); } static void diff --git a/glib/gmain.c b/glib/gmain.c index 34ed594ca..32778750d 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -663,7 +663,7 @@ g_main_context_new (void) if (g_once_init_enter (&initialised)) { #ifdef G_MAIN_POLL_DEBUG - if (getenv ("G_MAIN_POLL_DEBUG") != NULL) + if (g_getenv ("G_MAIN_POLL_DEBUG") != NULL) _g_main_poll_debug = TRUE; #endif diff --git a/glib/gslice.c b/glib/gslice.c index a868609d6..e6f278539 100644 --- a/glib/gslice.c +++ b/glib/gslice.c @@ -364,7 +364,7 @@ slice_config_init (SliceConfig *config) *config = slice_config; - val = getenv ("G_SLICE"); + val = g_getenv ("G_SLICE"); if (val != NULL) { gint flags; diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c index f7559f80a..e1ff7e041 100644 --- a/glib/gspawn-win32.c +++ b/glib/gspawn-win32.c @@ -72,7 +72,7 @@ { \ if (debug == -1) \ { \ - if (getenv ("G_SPAWN_WIN32_DEBUG") != NULL) \ + if (g_getenv ("G_SPAWN_WIN32_DEBUG") != NULL) \ debug = 1; \ else \ debug = 0; \ diff --git a/glib/gtimezone.c b/glib/gtimezone.c index 5fe924fd0..7c1187371 100644 --- a/glib/gtimezone.c +++ b/glib/gtimezone.c @@ -447,7 +447,7 @@ zone_info_unix (const gchar *identifier, gchar *resolved_identifier = NULL; const gchar *tzdir; - tzdir = getenv ("TZDIR"); + tzdir = g_getenv ("TZDIR"); if (tzdir == NULL) tzdir = "/usr/share/zoneinfo"; diff --git a/glib/gwin32.c b/glib/gwin32.c index 48574ec0a..fddb1d21f 100644 --- a/glib/gwin32.c +++ b/glib/gwin32.c @@ -109,7 +109,7 @@ g_win32_getlocale (void) { LCID lcid; LANGID langid; - gchar *ev; + const gchar *ev; gint primary, sub; char iso639[10]; char iso3166[10]; @@ -120,9 +120,9 @@ g_win32_getlocale (void) * since GTK+ 2.10.7 setting either LC_ALL or LANG also sets the * Win32 locale and C library locale through code in gtkmain.c. */ - if (((ev = getenv ("LC_ALL")) != NULL && ev[0] != '\0') - || ((ev = getenv ("LC_MESSAGES")) != NULL && ev[0] != '\0') - || ((ev = getenv ("LANG")) != NULL && ev[0] != '\0')) + if (((ev = g_getenv ("LC_ALL")) != NULL && ev[0] != '\0') + || ((ev = g_getenv ("LC_MESSAGES")) != NULL && ev[0] != '\0') + || ((ev = g_getenv ("LANG")) != NULL && ev[0] != '\0')) return g_strdup (ev); lcid = GetThreadLocale (); @@ -1084,7 +1084,7 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo) case EXCEPTION_ILLEGAL_INSTRUCTION: break; default: - catch_list = getenv ("G_VEH_CATCH"); + catch_list = g_getenv ("G_VEH_CATCH"); while (!catch && catch_list != NULL && @@ -1143,7 +1143,7 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo) fflush (stderr); - debugger_env = getenv ("G_DEBUGGER"); + debugger_env = g_getenv ("G_DEBUGGER"); if (debugger_env == NULL) return EXCEPTION_CONTINUE_SEARCH; @@ -1173,7 +1173,7 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo) NULL, NULL, TRUE, - getenv ("G_DEBUGGER_OLD_CONSOLE") != NULL ? 0 : CREATE_NEW_CONSOLE, + g_getenv ("G_DEBUGGER_OLD_CONSOLE") != NULL ? 0 : CREATE_NEW_CONSOLE, NULL, NULL, &si, @@ -1213,7 +1213,7 @@ g_crash_handler_win32_init (void) * break advanced exception handling such as in CLRs like C# or other managed * code. See: https://blogs.msdn.microsoft.com/jmstall/2006/05/24/beware-of-the-vectored-exception-handler-and-managed-code/ */ - if (getenv ("G_DEBUGGER") == NULL && getenv("G_VEH_CATCH") == NULL) + if (g_getenv ("G_DEBUGGER") == NULL && g_getenv("G_VEH_CATCH") == NULL) return; WinVEH_handle = AddVectoredExceptionHandler (0, &g_win32_veh_handler);