replace *a lot* of file related calls by their GLib counterparts. This is necessary...
[obnox/wireshark/wip.git] / util.c
diff --git a/util.c b/util.c
index 807e5aa029449ce79d2632786fb1732147646148..6b6298c70f5cd1bf9fba8948d95c081ced349093 100644 (file)
--- a/util.c
+++ b/util.c
 #include <unistd.h>
 #endif
 
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
-#ifdef NEED_SNPRINTF_H
-# include "snprintf.h"
-#endif
-
-#ifdef NEED_MKSTEMP
-#include "mkstemp.h"
-#endif
-
-#ifdef HAVE_IO_H
-#include <io.h>
-#ifndef __MINGW32__
-typedef int mode_t;    /* for win32 */
-#endif /* __MINGW32__ */
-#endif /* HAVE_IO_H */
+#include "file_util.h"
 
+#include <epan/address.h>
 #include <epan/addr_resolv.h>
 
 /*
@@ -110,22 +94,22 @@ get_args_as_string(int argc, char **argv, int optind)
        return argstring;
 }
 
-static char *
-setup_tmpdir(char *dir)
+static const char *
+setup_tmpdir(const char *dir)
 {
-       int len = strlen(dir);
+       size_t len = strlen(dir);
        char *newdir;
 
        /* Append path separator if necessary */
-       if (dir[len - 1] == G_DIR_SEPARATOR) {
-               newdir = dir;
+       if (len != 0 && dir[len - 1] == G_DIR_SEPARATOR) {
+               return dir;
        }
        else {
                newdir = g_malloc(len + 2);
                strcpy(newdir, dir);
                strcat(newdir, G_DIR_SEPARATOR_S);
+               return newdir;
        }
-       return newdir;
 }
 
 static int
@@ -133,14 +117,14 @@ try_tempfile(char *namebuf, int namebuflen, const char *dir, const char *pfx)
 {
        static const char suffix[] = "XXXXXXXXXX";
        int namelen = strlen(dir) + strlen(pfx) + sizeof suffix;
-       mode_t old_umask;
+       int old_umask;
        int tmp_fd;
 
        if (namebuflen < namelen) {
                /* Stick in a truncated name, so that if this error is
                   reported with the file name, you at least get
                   something. */
-               snprintf(namebuf, namebuflen, "%s%s%s", dir, pfx, suffix);
+               g_snprintf(namebuf, namebuflen, "%s%s%s", dir, pfx, suffix);
                errno = ENAMETOOLONG;
                return -1;
        }
@@ -155,16 +139,16 @@ try_tempfile(char *namebuf, int namebuflen, const char *dir, const char *pfx)
           permissions, attempt to create the file, and then put
           the umask back. */
        old_umask = umask(0077);
-       tmp_fd = mkstemp(namebuf);
+       tmp_fd = eth_mkstemp(namebuf);
        umask(old_umask);
        return tmp_fd;
 }
 
-static char *tmpdir = NULL;
+static const char *tmpdir = NULL;
 #ifdef _WIN32
 static char *temp = NULL;
 #endif
-static char *E_tmpdir;
+static const char *E_tmpdir;
 
 #ifndef P_tmpdir
 #define P_tmpdir "/var/tmp"
@@ -265,7 +249,7 @@ compute_timestamp_diff(gint *diffsec, gint *diffusec,
    CLIENTNAME (terminal server): <remote name>
  */
 
-gchar *get_conn_cfilter(void) {
+const gchar *get_conn_cfilter(void) {
        static GString *filter_str = NULL;
        gchar *env, **tokens;