Move getenv_utf8() to wsutil.
svn path=/trunk/; revision=35148
This commit is contained in:
parent
d6eff0493c
commit
ad47f04c94
|
@ -882,42 +882,6 @@ get_systemfile_dir(void)
|
|||
#define PF_DIR ".wireshark"
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
/* 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;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
set_profile_name(const gchar *profilename)
|
||||
{
|
||||
|
|
|
@ -82,7 +82,7 @@ extern const char *get_datafile_dir(void);
|
|||
*/
|
||||
extern char *get_datafile_path(const char *filename);
|
||||
|
||||
/*
|
||||
/*
|
||||
* Get the personal plugin dir.
|
||||
*/
|
||||
extern char *get_plugins_pers_dir(void);
|
||||
|
@ -96,7 +96,7 @@ extern char *get_plugins_pers_dir(void);
|
|||
extern const char *get_systemfile_dir(void);
|
||||
|
||||
/*
|
||||
* Set the configuration profile name to be used for storing
|
||||
* Set the configuration profile name to be used for storing
|
||||
* personal configuration files.
|
||||
*/
|
||||
extern void set_profile_name(const gchar *profilename);
|
||||
|
@ -128,34 +128,34 @@ extern void profile_store_persconffiles(gboolean store);
|
|||
*/
|
||||
extern gboolean profile_exists(const gchar *profilename);
|
||||
|
||||
/*
|
||||
/*
|
||||
* Create a directory for the given configuration profile.
|
||||
* If we attempted to create it, and failed, return -1 and
|
||||
* set "*pf_dir_path_return" to the pathname of the directory we failed
|
||||
* to create (it's g_mallocated, so our caller should free it); otherwise,
|
||||
* return 0.
|
||||
*/
|
||||
extern int create_persconffile_profile(const char *profilename,
|
||||
extern int create_persconffile_profile(const char *profilename,
|
||||
char **pf_dir_path_return);
|
||||
|
||||
/*
|
||||
/*
|
||||
* Delete the directory for the given configuration profile.
|
||||
* If we attempted to delete it, and failed, return -1 and
|
||||
* set "*pf_dir_path_return" to the pathname of the directory we failed
|
||||
* to delete (it's g_mallocated, so our caller should free it); otherwise,
|
||||
* return 0.
|
||||
*/
|
||||
extern int delete_persconffile_profile(const char *profilename,
|
||||
extern int delete_persconffile_profile(const char *profilename,
|
||||
char **pf_dir_path_return);
|
||||
|
||||
/*
|
||||
/*
|
||||
* Rename the directory for the given confinguration profile.
|
||||
*/
|
||||
extern int rename_persconffile_profile(const char *fromname, const char *toname,
|
||||
char **pf_from_dir_path_return,
|
||||
char **pf_from_dir_path_return,
|
||||
char **pf_to_dir_path_return);
|
||||
|
||||
/*
|
||||
/*
|
||||
* Copy files in one profile to the other.
|
||||
*/
|
||||
extern int copy_persconffile_profile(const char *toname, const char *fromname,
|
||||
|
@ -205,7 +205,7 @@ extern const char *get_persdatafile_dir(void);
|
|||
*/
|
||||
extern char *get_tempfile_path(const char *filename);
|
||||
|
||||
/*
|
||||
/*
|
||||
* process command line option belonging to the filesystem settings
|
||||
*/
|
||||
extern int filesystem_opt(int opt, const char *optstr);
|
||||
|
@ -292,13 +292,6 @@ extern gboolean files_identical(const char *fname1, const char *fname2);
|
|||
extern gboolean copy_file_binary_mode(const char *from_filename,
|
||||
const char *to_filename);
|
||||
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
* utf8 version of getenv, needed to get win32 filename paths
|
||||
*/
|
||||
extern char *getenv_utf8(const char *varname);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
|
@ -564,7 +564,6 @@ get_tcp_port
|
|||
get_tempfile_path
|
||||
get_udp_port
|
||||
get_wspython_dir
|
||||
getenv_utf8
|
||||
golay_decode
|
||||
golay_encode
|
||||
golay_errors
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
EXPORTS
|
||||
|
||||
; file_util.c
|
||||
getenv_utf8
|
||||
ws_stdio_fopen
|
||||
ws_stdio_freopen
|
||||
ws_stdio_mkdir
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue