From 80a80edd5ec87b41d86faa03c9a9b7a773f32f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Thu, 31 Mar 2016 04:38:51 +0100 Subject: wsutil: Remove getenv_utf8(), replaced with g_getenv() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getenv() calls in filesystem.c too for consistency. Change-Id: I31425179290e556e6696953531989d93777adf92 Reviewed-on: https://code.wireshark.org/review/14752 Petri-Dish: João Valverde Reviewed-by: João Valverde Tested-by: João Valverde Reviewed-by: Michael Mann --- wsutil/file_util.c | 33 --------------------------------- wsutil/file_util.h | 5 ----- wsutil/filesystem.c | 41 ++++++++++++++++++++--------------------- 3 files changed, 20 insertions(+), 59 deletions(-) (limited to 'wsutil') diff --git a/wsutil/file_util.c b/wsutil/file_util.c index dab691719b..4f749fb517 100644 --- a/wsutil/file_util.c +++ b/wsutil/file_util.c @@ -605,39 +605,6 @@ ws_module_open(gchar *module_name, GModuleFlags flags) return NULL; } -/* utf8 version of getenv, needed to get win32 filename paths */ -char * -getenv_utf8(const char *varname) -{ - char *envvar; - wchar_t *envvarw; - wchar_t *varnamew; - - envvar = getenv(varname); - - /* since GLib 2.6 we need an utf8 version of the filename */ - /* using the wide char version of getenv should work under all circumstances */ - - /* convert given varname to utf16, needed by _wgetenv */ - varnamew = g_utf8_to_utf16(varname, -1, NULL, NULL, NULL); - if (varnamew == NULL) { - return envvar; - } - - /* use wide char version of getenv */ - envvarw = _wgetenv(varnamew); - g_free(varnamew); - if (envvarw == NULL) { - return envvar; - } - - /* convert value to utf8 */ - envvar = g_utf16_to_utf8(envvarw, -1, NULL, NULL, NULL); - /* XXX - memleak */ - - return envvar; -} - /** Create or open a "Wireshark is running" mutex. */ #define WIRESHARK_IS_RUNNING_UUID "9CA78EEA-EA4D-4490-9240-FC01FCEF464B" diff --git a/wsutil/file_util.h b/wsutil/file_util.h index 057fdadb55..1588ced5de 100644 --- a/wsutil/file_util.h +++ b/wsutil/file_util.h @@ -152,11 +152,6 @@ void *ws_load_library(const gchar *library_name); WS_DLL_PUBLIC GModule *ws_module_open(gchar *module_name, GModuleFlags flags); -/* - * utf8 version of getenv, needed to get win32 filename paths - */ -WS_DLL_PUBLIC char *getenv_utf8(const char *varname); - /** Create or open a "Wireshark is running" mutex. * Create or open a mutex which signals that Wireshark or its associated * executables is running. Used by the installer to test for a running application. diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index 8869cec10b..2a68a9949d 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -473,8 +473,7 @@ init_progfile_dir(const char *arg0 */ if (GetModuleFileName(NULL, prog_pathname_w, G_N_ELEMENTS(prog_pathname_w)) != 0 && GetLastError() != ERROR_INSUFFICIENT_BUFFER) { /* - * XXX - Should we use g_utf16_to_utf8(), as in - * getenv_utf8()? + * XXX - Should we use g_utf16_to_utf8()? */ prog_pathname = utf_16to8(prog_pathname_w); /* @@ -527,8 +526,8 @@ init_progfile_dir(const char *arg0 char *prog_pathname; char *curdir; long path_max; - char *pathstr; - char *path_start, *path_end; + const char *pathstr; + const char *path_start, *path_end; size_t path_component_len, path_len; char *retstr; char *path; @@ -543,7 +542,7 @@ init_progfile_dir(const char *arg0 * set, causes us to look for plugins and the like in the build * directory.) */ - if (getenv("WIRESHARK_RUN_FROM_BUILD_DIRECTORY") != NULL + if (g_getenv("WIRESHARK_RUN_FROM_BUILD_DIRECTORY") != NULL && !started_with_special_privs()) running_in_build_directory_flag = TRUE; @@ -623,7 +622,7 @@ DIAG_ON(pedantic) * that's executable. */ prog_pathname = NULL; /* haven't found it yet */ - pathstr = getenv("PATH"); + pathstr = g_getenv("PATH"); path_start = pathstr; if (path_start != NULL) { while (*path_start != '\0') { @@ -876,13 +875,13 @@ get_datafile_dir(void) datafile_dir = g_strdup(TOP_SRCDIR); return datafile_dir; } else { - if (getenv("WIRESHARK_DATA_DIR") && !started_with_special_privs()) { + if (g_getenv("WIRESHARK_DATA_DIR") && !started_with_special_privs()) { /* * The user specified a different directory for data files * and we aren't running with special privileges. * XXX - We might be able to dispense with the priv check */ - datafile_dir = g_strdup(getenv("WIRESHARK_DATA_DIR")); + datafile_dir = g_strdup(g_getenv("WIRESHARK_DATA_DIR")); } #ifdef __APPLE__ /* @@ -975,12 +974,12 @@ init_plugin_dir(void) */ plugin_dir = g_strdup_printf("%s/plugins", get_progfile_dir()); } else { - if (getenv("WIRESHARK_PLUGIN_DIR") && !started_with_special_privs()) { + if (g_getenv("WIRESHARK_PLUGIN_DIR") && !started_with_special_privs()) { /* * The user specified a different directory for plugins * and we aren't running with special privileges. */ - plugin_dir = g_strdup(getenv("WIRESHARK_PLUGIN_DIR")); + plugin_dir = g_strdup(g_getenv("WIRESHARK_PLUGIN_DIR")); } #ifdef __APPLE__ /* @@ -1042,7 +1041,7 @@ static const char *extcap_dir = NULL; static void init_extcap_dir(void) { #ifdef _WIN32 - char *alt_extcap_path; + const char *alt_extcap_path; /* * On Windows, the data file directory is the installation @@ -1052,7 +1051,7 @@ static void init_extcap_dir(void) { * on Windows, the data file directory is the directory * in which the Wireshark binary resides. */ - alt_extcap_path = getenv_utf8("WIRESHARK_EXTCAP_DIR"); + alt_extcap_path = g_getenv("WIRESHARK_EXTCAP_DIR"); if (alt_extcap_path) { /* * The user specified a different directory for extcap hooks. @@ -1071,12 +1070,12 @@ static void init_extcap_dir(void) { */ extcap_dir = g_strdup_printf("%s/extcap", get_progfile_dir()); } else { - if (getenv("WIRESHARK_EXTCAP_DIR") && !started_with_special_privs()) { + if (g_getenv("WIRESHARK_EXTCAP_DIR") && !started_with_special_privs()) { /* * The user specified a different directory for extcap hooks * and we aren't running with special privileges. */ - extcap_dir = g_strdup(getenv("WIRESHARK_EXTCAP_DIR")); + extcap_dir = g_strdup(g_getenv("WIRESHARK_EXTCAP_DIR")); } #ifdef __APPLE__ /* @@ -1248,7 +1247,7 @@ get_persconffile_dir_no_profile(void) /* * See if the user has selected an alternate environment. */ - env = getenv_utf8("WIRESHARK_APPDATA"); + env = g_getenv("WIRESHARK_APPDATA"); if (env != NULL) { persconffile_dir = g_strdup(env); return persconffile_dir; @@ -1262,7 +1261,7 @@ get_persconffile_dir_no_profile(void) * so means you can use Wireshark even if the home directory * is an inaccessible network drive. */ - env = getenv_utf8("APPDATA"); + env = g_getenv("APPDATA"); if (env != NULL) { /* * Concatenate %APPDATA% with "\Wireshark". @@ -1274,7 +1273,7 @@ get_persconffile_dir_no_profile(void) /* * OK, %APPDATA% wasn't set, so use %USERPROFILE%\Application Data. */ - env = getenv_utf8("USERPROFILE"); + env = g_getenv("USERPROFILE"); if (env != NULL) { persconffile_dir = g_build_filename(env, "Application Data", "Wireshark", NULL); return persconffile_dir; @@ -1304,7 +1303,7 @@ get_persconffile_dir_no_profile(void) * (Note: before GLib 2.36, g_get_home_dir() didn't look at $HOME, * but we always want to do so, so we don't use g_get_home_dir().) */ - homedir = getenv("HOME"); + homedir = g_getenv("HOME"); if (homedir == NULL) { /* * It's not set. @@ -1695,7 +1694,7 @@ static const char * get_home_dir(void) { static const char *home = NULL; - char *homedrive, *homepath; + const char *homedrive, *homepath; char *homestring; char *lastsep; @@ -1708,9 +1707,9 @@ get_home_dir(void) * Is there a chance that it might be set but one or more of * HOMEDRIVE or HOMEPATH isn't set? */ - homedrive = getenv_utf8("HOMEDRIVE"); + homedrive = g_getenv("HOMEDRIVE"); if (homedrive != NULL) { - homepath = getenv_utf8("HOMEPATH"); + homepath = g_getenv("HOMEPATH"); if (homepath != NULL) { /* * This is cached, so we don't need to worry about -- cgit v1.2.3