Move getenv_utf8() to wsutil.
authorJeff Morriss <jeff.morriss@ulticom.com>
Tue, 7 Dec 2010 20:24:57 +0000 (20:24 -0000)
committerJeff Morriss <jeff.morriss@ulticom.com>
Tue, 7 Dec 2010 20:24:57 +0000 (20:24 -0000)
svn path=/trunk/; revision=35148

epan/filesystem.c
epan/filesystem.h
epan/libwireshark.def
wsutil/file_util.c
wsutil/file_util.h
wsutil/libwsutil.def
wsutil/unicode-utils.c

index 59be94627b426a967dbbe8b0fef957e8671e12e7..a662c796c4b3edbcb9af1cd83a7c9535594085e8 100644 (file)
@@ -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)
 {
index 165159218ff2106f619abcd615225dd4a35e81f7..065fe2fbceef87c5df3faa031b64bf609b0e1c70 100644 (file)
@@ -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 */
index 2baf52fe20c4e9da3a73dd851f6989ea16ad37b4..ec7e3f120fb5ebcd4bdfd354b3ddb5b523e489bd 100644 (file)
@@ -564,7 +564,6 @@ get_tcp_port
 get_tempfile_path
 get_udp_port
 get_wspython_dir
-getenv_utf8
 golay_decode
 golay_encode
 golay_errors
index f901c99b8be2498fcc0ca5c75269bd5fddb68532..6968bdd2367f25410f4d59fea0b18f775baab9c3 100644 (file)
@@ -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;
+}
+
index 798cea9261203cc694be7e1705329c1c85536727..4225fe5933779b6c9026eca4eaa872289517ab4f 100644 (file)
@@ -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
index a0d4ed1b47175cdb2a72cdc1b5a9c1b7cf2bb416..a2c3e26a5ee4630346de4fb3b889aa77205db9d2 100644 (file)
@@ -10,6 +10,7 @@
 EXPORTS
 
 ; file_util.c
+getenv_utf8
 ws_stdio_fopen
 ws_stdio_freopen
 ws_stdio_mkdir
index f011d462922259d77bdfb9cd1244832690ec5068..80541a57840d598ac530d899b43d766c2c139e1b 100644 (file)
@@ -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;