diff options
author | morriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7> | 2010-12-07 20:24:57 +0000 |
---|---|---|
committer | morriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7> | 2010-12-07 20:24:57 +0000 |
commit | c8e796b97fb0d1d63c4a40b30271178445bdc6fc (patch) | |
tree | 7bcd79657b58a844ffc2adb4e024def56e2ae36d /wsutil | |
parent | 8bfc128c08b5b741089ef12625b60bc8d034955c (diff) |
Move getenv_utf8() to wsutil.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@35148 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'wsutil')
-rw-r--r-- | wsutil/file_util.c | 48 | ||||
-rw-r--r-- | wsutil/file_util.h | 6 | ||||
-rw-r--r-- | wsutil/libwsutil.def | 1 | ||||
-rw-r--r-- | wsutil/unicode-utils.c | 12 |
4 files changed, 60 insertions, 7 deletions
diff --git a/wsutil/file_util.c b/wsutil/file_util.c index f901c99b8b..6968bdd236 100644 --- a/wsutil/file_util.c +++ b/wsutil/file_util.c @@ -446,7 +446,8 @@ ws_stdio_freopen (const gchar *filename, /* DLL loading */ static gboolean -init_dll_load_paths() { +init_dll_load_paths() +{ TCHAR path_w[MAX_PATH]; if (program_path && system_path) @@ -480,7 +481,8 @@ init_dll_load_paths() { } gboolean -ws_init_dll_search_path() { +ws_init_dll_search_path() +{ gboolean dll_dir_set = FALSE; wchar_t *program_path_w; @@ -508,7 +510,8 @@ ws_init_dll_search_path() { */ void * -ws_load_library(gchar *library_name) { +ws_load_library(gchar *library_name) +{ gchar *full_path; wchar_t *full_path_w; HMODULE dll_h; @@ -546,7 +549,8 @@ ws_load_library(gchar *library_name) { } GModule * -ws_module_open(gchar *module_name, GModuleFlags flags) { +ws_module_open(gchar *module_name, GModuleFlags flags) +{ gchar *full_path; GModule *mod; @@ -577,3 +581,39 @@ 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 */ +#if GLIB_CHECK_VERSION(2,6,0) + /* 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 */ +#endif + + return envvar; +} + diff --git a/wsutil/file_util.h b/wsutil/file_util.h index 798cea9261..4225fe5933 100644 --- a/wsutil/file_util.h +++ b/wsutil/file_util.h @@ -123,6 +123,12 @@ void *ws_load_library(gchar *library_name); * @return A handle to the DLL if found, NULL on failure. */ GModule *ws_module_open(gchar *module_name, GModuleFlags flags); + +/* + * utf8 version of getenv, needed to get win32 filename paths + */ +extern char *getenv_utf8(const char *varname); + #else /* _WIN32 */ #define ws_read read #define ws_write write diff --git a/wsutil/libwsutil.def b/wsutil/libwsutil.def index a0d4ed1b47..a2c3e26a5e 100644 --- a/wsutil/libwsutil.def +++ b/wsutil/libwsutil.def @@ -10,6 +10,7 @@ EXPORTS ; file_util.c +getenv_utf8 ws_stdio_fopen ws_stdio_freopen ws_stdio_mkdir diff --git a/wsutil/unicode-utils.c b/wsutil/unicode-utils.c index f011d46292..80541a5784 100644 --- a/wsutil/unicode-utils.c +++ b/wsutil/unicode-utils.c @@ -47,7 +47,9 @@ */ /* Convert from UTF-8 to UTF-16. */ -wchar_t * utf_8to16(const char *utf8str) { +wchar_t * +utf_8to16(const char *utf8str) +{ static wchar_t *utf16buf[3]; static int utf16buf_len[3]; static int idx; @@ -84,7 +86,9 @@ wchar_t * utf_8to16(const char *utf8str) { return utf16buf[idx]; } -void utf_8to16_snprintf(TCHAR *utf16buf, gint utf16buf_len, const gchar* fmt, ...) { +void +utf_8to16_snprintf(TCHAR *utf16buf, gint utf16buf_len, const gchar* fmt, ...) +{ va_list ap; gchar* dst; @@ -98,7 +102,9 @@ void utf_8to16_snprintf(TCHAR *utf16buf, gint utf16buf_len, const gchar* fmt, .. } /* Convert from UTF-16 to UTF-8. */ -gchar * utf_16to8(const wchar_t *utf16str) { +gchar * +utf_16to8(const wchar_t *utf16str) +{ static gchar *utf8buf[3]; static int utf8buf_len[3]; static int idx; |