If we have pcap_open, call it instead of pcap_open_live, otherwise we might
[obnox/wireshark/wip.git] / tempfile.c
index b8711082b4adbf5ce297f0f9dde3ece96302ffba..af922b6d416b30ecfa573b76e2d8e575165b00ea 100644 (file)
 
 #include "file_util.h"
 
-#if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 6)
-#include <glib/gstdio.h>       /* available since GLib 2.6 only! */
-
-/* GLib2.6 or above, using new wrapper functions */
-#define eth_mkstemp g_mkstemp
-#else
-#define eth_mkstemp mkstemp
-#endif
-
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
 #endif
 
 #include "tempfile.h"
+#include "mkstemp.h"
 
 static const char *
 setup_tmpdir(const char *dir)
@@ -65,9 +57,7 @@ setup_tmpdir(const char *dir)
                return dir;
        }
        else {
-               newdir = g_malloc(len + 2);
-               strcpy(newdir, dir);
-               strcat(newdir, G_DIR_SEPARATOR_S);
+               newdir = g_strdup_printf("%s%s", dir, G_DIR_SEPARATOR_S);
                return newdir;
        }
 }
@@ -80,17 +70,14 @@ try_tempfile(char *namebuf, int namebuflen, const char *dir, const char *pfx)
        int old_umask;
        int tmp_fd;
 
+       g_snprintf(namebuf, namebuflen, "%s%s%s", dir, pfx, suffix);
        if (namebuflen < namelen) {
-               /* Stick in a truncated name, so that if this error is
+               /* Stick with the truncated name, so that if this error is
                   reported with the file name, you at least get
                   something. */
-               g_snprintf(namebuf, namebuflen, "%s%s%s", dir, pfx, suffix);
                errno = ENAMETOOLONG;
                return -1;
        }
-       strcpy(namebuf, dir);
-       strcat(namebuf, pfx);
-       strcat(namebuf, suffix);
 
        /* The Single UNIX Specification doesn't say that "mkstemp()"
           creates the temporary file with mode rw-------, so we
@@ -99,7 +86,7 @@ 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 = eth_mkstemp(namebuf);
+       tmp_fd = mkstemp(namebuf);
        umask(old_umask);
        return tmp_fd;
 }