replace *a lot* of file related calls by their GLib counterparts. This is necessary...
authorulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 6 Nov 2005 22:43:25 +0000 (22:43 +0000)
committerulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 6 Nov 2005 22:43:25 +0000 (22:43 +0000)
to do this, I've added file_util.h to wiretap (would file_compat.h be a better name?), and provide compat_macros like eth_open() instead of open(). While at it, move other file related things there, like #include <io.h>, definition of O_BINARY and alike, so it's all in one place.

deleted related things from config.h.win32

As of these massive changes, I'm almost certain that this will break the Unix build. I'll keep an eye on the buildbot so hopefully everything is working again soon.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@16403 f5534014-38df-0310-8fa8-9805f1628bb7

50 files changed:
capture.c
capture_loop.c
capture_sync.c
color_filters.c
config.h.win32
disabled_protos.c
epan/addr_resolv.c
epan/column.c
epan/dissectors/packet-kerberos.c
epan/filesystem.c
epan/plugins.c
epan/prefs.c
epan/sha1.c
file.c
fileset.c
filters.c
gtk/capture_if_dlg.c
gtk/drag_and_drop.c
gtk/file_dlg.c
gtk/fileset_dlg.c
gtk/filter_dlg.h
gtk/follow_dlg.c
gtk/graph_analysis.c
gtk/gui_utils.c
gtk/help_dlg.c
gtk/main.c
gtk/print_dlg.c
gtk/print_mswin.c
gtk/proto_draw.c
gtk/recent.c
gtk/rtp_analysis.c
gtk/rtp_stream.c
gtk/text_page.c
mergecap.c
mkstemp.c
pcap-util-unix.c
plugins/asn1/packet-asn1.c
plugins/mate/mate_util.c
print.c
ringbuffer.c
tethereal.c
util.c
wiretap/ascend.c
wiretap/config.h.win32
wiretap/file_access.c
wiretap/file_util.h [new file with mode: 0644]
wiretap/file_wrappers.c
wiretap/file_wrappers.h
wiretap/k12.c
wiretap/wtap.c

index 624975e7d37df27820fb1a399f2cd8366535a335..762ae3838ccfb9d0d4f88d3df87671df7bd52c53 100644 (file)
--- a/capture.c
+++ b/capture.c
 #include <fcntl.h>
 #endif
 
-#ifdef HAVE_IO_H
-# include <io.h>
-#endif
-
 #include <signal.h>
 #include <errno.h>
 
@@ -69,6 +65,7 @@
 #include "capture-wpcap.h"
 #endif
 #include "ui_util.h"
+#include "file_util.h"
 #include "log.h"
 
 
@@ -404,7 +401,7 @@ capture_input_closed(capture_options *capture_opts)
     if(capture_opts->restart) {
         capture_opts->restart = FALSE;
 
-        unlink(capture_opts->save_file);
+        eth_unlink(capture_opts->save_file);
 
         /* if it was a tempfile, throw away the old filename (so it will become a tempfile again) */
         if(cf_is_tempfile(capture_opts->cf)) {
index 5853043d7f4b28cedd3f7f8539fb54df4ad8c9ad..1eae074d23f0da26d4d07c4f4da7ee8a0a8f3018 100644 (file)
@@ -87,6 +87,7 @@
 #include "util.h"
 #include "alert_box.h"
 #include "log.h"
+#include "file_util.h"
 
 
 #include <epan/dissectors/packet-ap1394.h>
 #include <epan/dissectors/packet-ipfc.h>
 #include <epan/dissectors/packet-arcnet.h>
 
-/* Win32 needs the O_BINARY flag for open() */
-#ifndef O_BINARY
-#define O_BINARY       0
-#endif
-
 
 
 /*
@@ -251,7 +247,7 @@ cap_pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ld,
   if (strcmp(pipename, "-") == 0)
     fd = 0; /* read from stdin */
   else {
-    if (stat(pipename, &pipe_stat) < 0) {
+    if (eth_stat(pipename, &pipe_stat) < 0) {
       if (errno == ENOENT || errno == ENOTDIR)
         ld->cap_pipe_err = PIPNEXIST;
       else {
@@ -277,7 +273,7 @@ cap_pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ld,
       }
       return -1;
     }
-    fd = open(pipename, O_RDONLY | O_NONBLOCK);
+    fd = eth _open(pipename, O_RDONLY | O_NONBLOCK, 0000 /* no creation so don't matter */);
     if (fd == -1) {
       g_snprintf(errmsg, errmsgl,
           "The capture session could not be initiated "
@@ -394,7 +390,7 @@ cap_pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ld,
 error:
   g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "cap_pipe_open_live: error %s", errmsg);
   ld->cap_pipe_err = PIPERR;
-  close(fd);
+  eth_close(fd);
   return -1;
 
 }
@@ -719,7 +715,7 @@ static void capture_loop_close_input(loop_data *ld) {
   /* if open, close the capture pipe "input file" */
   if (ld->cap_pipe_fd >= 0) {
     g_assert(ld->from_cap_pipe);
-    close(ld->cap_pipe_fd);
+    eth_close(ld->cap_pipe_fd);
   }
 #endif
 
@@ -1523,11 +1519,11 @@ error:
   } else {
     /* We can't use the save file, and we have no wtap_dump stream
        to close in order to close it, so close the FD directly. */
-    close(save_file_fd);
+    eth_close(save_file_fd);
 
     /* We couldn't even start the capture, so get rid of the capture
        file. */
-    unlink(capture_opts->save_file); /* silently ignore error */
+    eth_unlink(capture_opts->save_file); /* silently ignore error */
     g_free(capture_opts->save_file);
   }
   capture_opts->save_file = NULL;
index 9e02b26c4448a9ffa0a80427c225e2f7ed8eadd8..124e6ad4465895b7d7fa28ee043b1593156db7b1 100644 (file)
 #include "capture-wpcap.h"
 #endif
 #include "ui_util.h"
+#include "file_util.h"
 #include "log.h"
 
-#ifdef HAVE_IO_H
-# include <io.h>
-#endif
-
 #ifdef _WIN32
 #include <process.h>    /* For spawning child process */
 #endif
 
-/* Win32 needs the O_BINARY flag for open() */
-#ifndef O_BINARY
-#define O_BINARY       0
-#endif
-
 
 #ifndef _WIN32
 static const char *sync_pipe_signame(int);
@@ -435,8 +427,8 @@ sync_pipe_start(capture_options *capture_opts) {
       /* Couldn't create the signal pipe between parent and child. */
       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't create signal pipe: %s",
                         strerror(errno));
-      close(sync_pipe[PIPE_READ]);
-      close(sync_pipe[PIPE_WRITE]);
+      eth_close(sync_pipe[PIPE_READ]);
+      eth_close(sync_pipe[PIPE_WRITE]);
       g_free( (gpointer) argv);
       return FALSE;
     }
@@ -489,7 +481,7 @@ sync_pipe_start(capture_options *capture_opts) {
     }
 
     /* child own's the read side now, close our handle */
-    close(signal_pipe[PIPE_READ]);
+    eth_close(signal_pipe[PIPE_READ]);
 #else
     if (pipe(sync_pipe) < 0) {
       /* Couldn't create the pipe between parent and child. */
@@ -526,9 +518,9 @@ sync_pipe_start(capture_options *capture_opts) {
        * -m / -b fonts
        * -f "filter expression"
        */
-      close(1);
+      eth_close(1);
       dup(sync_pipe[PIPE_WRITE]);
-      close(sync_pipe[PIPE_READ]);
+      eth_close(sync_pipe[PIPE_READ]);
       execvp(ethereal_path, argv);
       g_snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
                ethereal_path, strerror(errno));
@@ -550,15 +542,15 @@ sync_pipe_start(capture_options *capture_opts) {
        open, and thus it completely closes, and thus returns to us
        an EOF indication, if the child closes it (either deliberately
        or by exiting abnormally). */
-    close(sync_pipe[PIPE_WRITE]);
+    eth_close(sync_pipe[PIPE_WRITE]);
 
     if (capture_opts->fork_child == -1) {
       /* We couldn't even create the child process. */
       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Couldn't create child process: %s", strerror(errno));
-      close(sync_pipe[PIPE_READ]);
+      eth_close(sync_pipe[PIPE_READ]);
 #ifdef _WIN32
-      close(signal_pipe[PIPE_WRITE]);
+      eth_close(signal_pipe[PIPE_WRITE]);
 #endif
       return FALSE;
     }
@@ -601,7 +593,7 @@ sync_pipe_input_cb(gint source, gpointer user_data)
     sync_pipe_wait_for_child(capture_opts);
 
 #ifdef _WIN32
-    close(capture_opts->signal_pipe_fd);
+    eth_close(capture_opts->signal_pipe_fd);
 #endif
     capture_input_closed(capture_opts);
     return FALSE;
@@ -615,7 +607,7 @@ sync_pipe_input_cb(gint source, gpointer user_data)
         /* We weren't able to open the new capture file; user has been
            alerted. Close the sync pipe. */
         /* XXX - is it safe to close the pipe inside this callback? */
-        close(source);
+        eth_close(source);
 
         /* the child has send us a filename which we couldn't open.
            this probably means, the child is creating files faster than we can handle it.
index 8ee7e50752853429d3b81ab1a6903430f8ba6d4f..8d7fcbb4c7561865f6c800c1e7437cdd1f6ce2e6 100644 (file)
@@ -34,6 +34,7 @@
 #include <string.h>
 
 #include <epan/filesystem.h>
+#include "file_util.h"
 
 #include <epan/packet.h>
 #include "color.h"
@@ -365,7 +366,7 @@ read_filters(void)
 
        /* decide what file to open (from dfilter code) */
        path = get_persconffile_path("colorfilters", FALSE);
-       if ((f = fopen(path, "r")) == NULL) {
+       if ((f = eth_fopen(path, "r")) == NULL) {
                if (errno != ENOENT) {
                        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                            "Could not open filter file\n\"%s\": %s.", path,
@@ -392,7 +393,7 @@ read_global_filters(void)
 
        /* decide what file to open (from dfilter code) */
        path = get_datafile_path("colorfilters");
-       if ((f = fopen(path, "r")) == NULL) {
+       if ((f = eth_fopen(path, "r")) == NULL) {
                if (errno != ENOENT) {
                        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                            "Could not open global filter file\n\"%s\": %s.", path,
@@ -416,7 +417,7 @@ color_filters_import(gchar *path, gpointer arg)
        FILE *f;
        gboolean ret;
 
-       if ((f = fopen(path, "r")) == NULL) {
+       if ((f = eth_fopen(path, "r")) == NULL) {
                simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                    "Could not open\n%s\nfor reading: %s.",
                    path, strerror(errno));
@@ -488,7 +489,7 @@ color_filters_write(void)
        }
 
        path = get_persconffile_path("colorfilters", TRUE);
-       if ((f = fopen(path, "w+")) == NULL) {
+       if ((f = eth_fopen(path, "w+")) == NULL) {
                simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                    "Could not open\n%s\nfor writing: %s.",
                    path, strerror(errno));
@@ -525,7 +526,7 @@ color_filters_export(gchar *path, gboolean only_marked)
 {
        FILE *f;
 
-       if ((f = fopen(path, "w+")) == NULL) {
+       if ((f = eth_fopen(path, "w+")) == NULL) {
                simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                    "Could not open\n%s\nfor writing: %s.",
                    path, strerror(errno));
index 492ae8bc515c9b61df31db3f0bf78819e050ab55..9bda22e3bf450a0fe1070687e5522061a40d988b 100644 (file)
 #define HAVE_WINDOWS_H         1
 #define HAVE_WINSOCK2_H                1
 #define HAVE_DIRECT_H          1
-#define HAVE_IO_H              1
 #define NEED_INET_ATON_H       1
 #define NEED_INET_V6DEFS_H     1
 #define NEED_GETOPT_H          1
 #define snprintf               _snprintf
 #define strcasecmp             stricmp
 #define strncasecmp            strnicmp
-#define open                   _open
-#define close                  _close
 #define popen                  _popen
 #define pclose                 _pclose
 
index d8fbdf11b8a04dff96a149e9a6f7cf45b6aa03a0..4ce7e73c12dbd14ed3b9e92fad2be561a7306c2e 100644 (file)
@@ -41,6 +41,7 @@
 #include <epan/proto.h>
 
 #include "disabled_protos.h"
+#include "file_util.h"
 
 #define GLOBAL_PROTOCOLS_FILE_NAME     "disabled_protos"
 #define PROTOCOLS_FILE_NAME            "disabled_protos"
@@ -81,7 +82,7 @@ read_disabled_protos_list(char **gpath_return, int *gopen_errno_return,
 
   /* Read the global disabled protocols file, if it exists. */
   *gpath_return = NULL;
-  if ((ff = fopen(gff_path, "r")) != NULL) {
+  if ((ff = eth_fopen(gff_path, "r")) != NULL) {
     /* We succeeded in opening it; read it. */
     err = read_disabled_protos_list_file(gff_path, ff,
                                         &global_disabled_protos);
@@ -111,7 +112,7 @@ read_disabled_protos_list(char **gpath_return, int *gopen_errno_return,
 
   /* Read the user's disabled protocols file, if it exists. */
   *path_return = NULL;
-  if ((ff = fopen(ff_path, "r")) != NULL) {
+  if ((ff = eth_fopen(ff_path, "r")) != NULL) {
     /* We succeeded in opening it; read it. */
     err = read_disabled_protos_list_file(ff_path, ff, &disabled_protos);
     if (err != 0) {
@@ -335,7 +336,7 @@ save_disabled_protos_list(char **pref_path_return, int *errno_return)
      completely. */
   ff_path_new = g_strdup_printf("%s.new", ff_path);
 
-  if ((ff = fopen(ff_path_new, "w")) == NULL) {
+  if ((ff = eth_fopen(ff_path_new, "w")) == NULL) {
     *pref_path_return = ff_path;
     *errno_return = errno;
     g_free(ff_path_new);
@@ -363,7 +364,7 @@ save_disabled_protos_list(char **pref_path_return, int *errno_return)
   if (fclose(ff) == EOF) {
     *pref_path_return = ff_path;
     *errno_return = errno;
-    unlink(ff_path_new);
+    eth_unlink(ff_path_new);
     g_free(ff_path_new);
     return;
   }
@@ -373,22 +374,22 @@ save_disabled_protos_list(char **pref_path_return, int *errno_return)
      exists; the Win32 call to rename files doesn't do so, which I
      infer is the reason why the MSVC++ "rename()" doesn't do so.
      We must therefore remove the target file first, on Windows. */
-  if (remove(ff_path) < 0 && errno != ENOENT) {
+  if (eth_remove(ff_path) < 0 && errno != ENOENT) {
     /* It failed for some reason other than "it's not there"; if
        it's not there, we don't need to remove it, so we just
        drive on. */
     *pref_path_return = ff_path;
     *errno_return = errno;
-    unlink(ff_path_new);
+    eth_unlink(ff_path_new);
     g_free(ff_path_new);
     return;
   }
 #endif
 
-  if (rename(ff_path_new, ff_path) < 0) {
+  if (eth_rename(ff_path_new, ff_path) < 0) {
     *pref_path_return = ff_path;
     *errno_return = errno;
-    unlink(ff_path_new);
+    eth_unlink(ff_path_new);
     g_free(ff_path_new);
     return;
   }
index 1d257f091a6b8de1b25cfd66e8376c9f89dd8ebf..9d43d04caa723ebc1a1225e70cdfbd0442c7a7fb 100644 (file)
 #include "ipv6-utils.h"
 #include "addr_resolv.h"
 #include "filesystem.h"
+#include "file_util.h"
 #include <epan/prefs.h>
 #include <epan/emem.h>
 
@@ -764,7 +765,7 @@ static void set_ethent(char *path)
   if (eth_p)
     rewind(eth_p);
   else
-    eth_p = fopen(path, "r");
+    eth_p = eth_fopen(path, "r");
 }
 
 static void end_ethent(void)
@@ -1330,7 +1331,7 @@ static void set_ipxnetent(char *path)
   if (ipxnet_p)
     rewind(ipxnet_p);
   else
-    ipxnet_p = fopen(path, "r");
+    ipxnet_p = eth_fopen(path, "r");
 }
 
 static void end_ipxnetent(void)
@@ -1557,7 +1558,7 @@ read_hosts_file (const char *hostspath)
    *  See the hosts(4) or hosts(5) man page for hosts file format
    *  (not available on all systems).
    */
-  if ((hf = fopen(hostspath, "r")) == NULL)
+  if ((hf = eth_fopen(hostspath, "r")) == NULL)
     return FALSE;
 
   while (fgetline(&line, &size, hf) >= 0) {
index 90dae767092aad59c589e5d16b1f9a388456d6ca..17993bd7df0c891019cbde8aabbb369e01475788 100644 (file)
 #include <unistd.h>
 #endif
 
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
 #include <epan/timestamp.h>
 #include <epan/prefs.h>
 #include <epan/column.h>
index e1b339c0ca17562b0b9572f84b4c895576be8c5d..ea922d37a56a752a87734580f800b16c63f917fd 100644 (file)
@@ -679,7 +679,7 @@ read_keytab_file(const char *service_key_file)
                        }
                }
 
-               skf = fopen(service_key_file, "rb");
+               skf = eth_fopen(service_key_file, "rb");
                if (! skf) return;
 
                while (fread(buf, SERVICE_KEY_SIZE, 1, skf) == 1) {
index d042e426c67b7b1a767051a3bf6b4cd81dc5c744..b77c7d07933aef6eab08ce92806b101bbdbe62da 100644 (file)
 #include <unistd.h>
 #endif
 
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
 #endif
 
-#ifdef HAVE_DIRECT_H
-#include <direct.h>            /* to declare "mkdir()" on Windows */
-#endif
-
 #ifndef _WIN32
 #include <pwd.h>
 #endif
 
 #include "filesystem.h"
+#include "file_util.h"
 
 /*
  * Given a pathname, return a pointer to the last pathname separator
@@ -184,7 +177,7 @@ test_for_directory(const char *path)
 {
        struct stat statb;
 
-       if (stat(path, &statb) < 0)
+       if (eth_stat(path, &statb) < 0)
                return errno;
 
        if (S_ISDIR(statb.st_mode))
@@ -198,7 +191,7 @@ test_for_fifo(const char *path)
 {
        struct stat statb;
 
-       if (stat(path, &statb) < 0)
+       if (eth_stat(path, &statb) < 0)
                return errno;
 
        if (S_ISFIFO(statb.st_mode))
@@ -439,7 +432,7 @@ create_persconffile_dir(char **pf_dir_path_return)
        int ret;
 
        pf_dir_path = get_persconffile_dir();
-       if (stat(pf_dir_path, &s_buf) != 0 && errno == ENOENT) {
+       if (eth_stat(pf_dir_path, &s_buf) != 0 && errno == ENOENT) {
 #ifdef _WIN32
                /*
                 * Does the parent directory of that directory
@@ -457,20 +450,20 @@ create_persconffile_dir(char **pf_dir_path_return)
                pf_dir_parent_path_len = strlen(pf_dir_parent_path);
                if (pf_dir_parent_path_len > 0
                    && pf_dir_parent_path[pf_dir_parent_path_len - 1] != ':'
-                   && stat(pf_dir_parent_path, &s_buf) != 0) {
+                   && eth_stat(pf_dir_parent_path, &s_buf) != 0) {
                        /*
                         * No, it doesn't exist - make it first.
                         */
-                       ret = mkdir(pf_dir_parent_path);
+                       ret = eth_mkdir(pf_dir_parent_path, 0755);
                        if (ret == -1) {
                                *pf_dir_path_return = pf_dir_parent_path;
                                return -1;
                        }
                }
                g_free(pf_dir_path_copy);
-               ret = mkdir(pf_dir_path);
+               ret = eth_mkdir(pf_dir_path, 0755);
 #else
-               ret = mkdir(pf_dir_path, 0755);
+               ret = eth_mkdir(pf_dir_path, 0755);
 #endif
        } else {
                /*
@@ -572,7 +565,7 @@ get_persconffile_path(const char *filename, gboolean for_writing
            filename);
 #ifdef _WIN32
        if (!for_writing) {
-               if (stat(path, &s_buf) != 0 && errno == ENOENT) {
+               if (eth_stat(path, &s_buf) != 0 && errno == ENOENT) {
                        /*
                         * OK, it's not in the personal configuration file
                         * directory; is it in the ".ethereal" subdirectory
@@ -581,7 +574,7 @@ get_persconffile_path(const char *filename, gboolean for_writing
                        old_path = g_strdup_printf(
                            "%s" G_DIR_SEPARATOR_S ".ethereal" G_DIR_SEPARATOR_S "%s",
                            get_home_dir(), filename);
-                       if (stat(old_path, &s_buf) == 0) {
+                       if (eth_stat(old_path, &s_buf) == 0) {
                                /*
                                 * OK, it exists; return it instead.
                                 */
@@ -611,7 +604,7 @@ get_datafile_path(const char *filename)
 gboolean
 deletefile(const char *path)
 {
-       return unlink(path) == 0;
+       return eth_unlink(path) == 0;
 }
 
 /*
@@ -721,7 +714,7 @@ file_exists(const char *fname)
    * so this is working, but maybe not quite the way expected. ULFL
    */
    file_stat.st_ino = 1;   /* this will make things work if an error occured */
-   stat(fname, &file_stat);
+   eth_stat(fname, &file_stat);
    if (file_stat.st_ino == 0) {
        return TRUE;
    } else {
@@ -774,8 +767,8 @@ files_identical(const char *fname1, const char *fname2)
    */
    infile.st_ino = 1;   /* These prevent us from getting equality         */
    outfile.st_ino = 2;  /* If one or other of the files is not accessible */
-   stat(fname1, &infile);
-   stat(fname2, &outfile);
+   eth_stat(fname1, &infile);
+   eth_stat(fname2, &outfile);
    if (infile.st_ino == outfile.st_ino) {
        return TRUE;
    } else {
index 9d606376b8a004ddc25b7839f227022f3544e857..806488fd7d31447c64031700b1b414bda91c0bdb 100644 (file)
 #include <stdlib.h>
 #include <errno.h>
 
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
 #include "filesystem.h"
+#include "file_util.h"
 #include "report_err.h"
 
 /* linked list of all plugins */
@@ -129,16 +126,12 @@ static void
 plugins_scan_dir(const char *dirname)
 {
 #define FILENAME_LEN   1024
+    ETH_DIR       *dir;             /* scanned directory */
+    ETH_DIRENT    *file;            /* current file */
+    const char    *name;
 #if GLIB_MAJOR_VERSION < 2
     gchar         *hack_path;       /* pathname used to construct lt_lib_ext */
     gchar         *lt_lib_ext;      /* extension for loadable modules */
-    DIR           *dir;             /* scanned directory */
-    struct dirent *file;            /* current file */
-    gchar         *name;
-#else /* GLIB 2 */
-    GDir          *dir;             /* scanned directory */
-    GError        **dummy;
-    const gchar   *name;
 #endif
     gchar          filename[FILENAME_LEN];   /* current file name */
     GModule       *handle;          /* handle returned by dlopen */
@@ -170,40 +163,34 @@ plugins_scan_dir(const char *dirname)
         */
        lt_lib_ext = "";
     }
+#endif
 
-    if ((dir = opendir(dirname)) != NULL)
+    if ((dir = g_dir_open(dirname, 0, NULL)) != NULL)
     {
-       while ((file = readdir(dir)) != NULL)
+    while ((file = eth_dir_read_name(dir)) != NULL)
        {
+           name = eth_dir_get_name(file);
+#if GLIB_MAJOR_VERSION < 2
            /* don't try to open "." and ".." */
-           if (!(strcmp(file->d_name, "..") &&
-                 strcmp(file->d_name, "."))) continue;
+           if (!(strcmp(name, "..") &&
+                 strcmp(name, "."))) continue;
 
             /* skip anything but files with lt_lib_ext */
-            dot = strrchr(file->d_name, '.');
+            dot = strrchr(name, '.');
             if (dot == NULL || strcmp(dot, lt_lib_ext) != 0) continue;
 
-           g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
-               dirname, file->d_name);
-           name = (gchar *)file->d_name;
 #else /* GLIB 2 */
     /*
      * GLib 2.x defines G_MODULE_SUFFIX as the extension used on this
      * platform for loadable modules.
      */
-    dummy = g_malloc(sizeof(GError *));
-    *dummy = NULL;
-    if ((dir = g_dir_open(dirname, 0, dummy)) != NULL)
-    {
-       while ((name = g_dir_read_name(dir)) != NULL)
-       {
            /* skip anything but files with G_MODULE_SUFFIX */
             dot = strrchr(name, '.');
             if (dot == NULL || strcmp(dot+1, G_MODULE_SUFFIX) != 0) continue;
 
+#endif
            g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
                dirname, name);
-#endif
            if ((handle = g_module_open(filename, 0)) == NULL)
            {
                report_failure("Couldn't load module %s: %s", filename,
@@ -343,15 +330,10 @@ plugins_scan_dir(const char *dirname)
                    register_protoinfo();
 
        }
+       eth_dir_close(dir);
+       }
 #if GLIB_MAJOR_VERSION < 2
-       closedir(dir);
-    }
     g_free(hack_path);
-#else /* GLIB 2 */
-       g_dir_close(dir);
-    }
-    g_clear_error(dummy);
-    g_free(dummy);
 #endif
 }
 
index 09151b04a3e1d1d5fc140f7e22fdec8a1ead0929..70711e7609158c353c9029daf9f93da517a0c66a 100644 (file)
@@ -45,6 +45,7 @@
 #include <epan/proto.h>
 #include <epan/column.h>
 #include "print.h"
+#include "file_util.h"
 
 #include <epan/prefs-int.h>
 
@@ -1084,19 +1085,19 @@ read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
      * file doesn't exist, try the old path.
      */
     gpf_path = get_datafile_path(PF_NAME);
-    if ((pf = fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
+    if ((pf = eth_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
       /*
        * It doesn't exist by the new name; try the old name.
        */
       g_free(gpf_path);
       gpf_path = get_datafile_path(OLD_GPF_NAME);
-      pf = fopen(gpf_path, "r");
+      pf = eth_fopen(gpf_path, "r");
     }
   } else {
     /*
      * We have the path; try it.
      */
-    pf = fopen(gpf_path, "r");
+    pf = eth_fopen(gpf_path, "r");
   }
 
   /*
@@ -1139,7 +1140,7 @@ read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
 
   /* Read the user's preferences file, if it exists. */
   *pf_path_return = NULL;
-  if ((pf = fopen(pf_path, "r")) != NULL) {
+  if ((pf = eth_fopen(pf_path, "r")) != NULL) {
     /*
      * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
      * seen.
@@ -2235,7 +2236,7 @@ write_prefs(char **pf_path_return)
 
   if (pf_path_return != NULL) {
     pf_path = get_persconffile_path(PF_NAME, TRUE);
-    if ((pf = fopen(pf_path, "w")) == NULL) {
+    if ((pf = eth_fopen(pf_path, "w")) == NULL) {
       *pf_path_return = pf_path;
       return errno;
     }
index 9b8fef45768c00506659bf9666a51629e137ed8e..52e95c132e24a1d4305a32c40a9c01d0cac1bfb5 100644 (file)
@@ -364,7 +364,7 @@ int main( int argc, char *argv[] )
     }
     else
     {
-        if( ! ( f = fopen( argv[1], "rb" ) ) )
+        if( ! ( f = eth_fopen( argv[1], "rb" ) ) )
         {
             perror( "fopen" );
             return( 1 );
diff --git a/file.c b/file.c
index 5a9ef277b466013fb37f8d35e949a3b630b54aa9..b2cd59832538fa064cb85a10e73590653caffbf0 100644 (file)
--- a/file.c
+++ b/file.c
 
 #include <time.h>
 
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include "tap_dfilter_dlg.h"
 #include <epan/dissectors/packet-data.h>
 #include <epan/timestamp.h>
+#include "file_util.h"
 
 
-/* Win32 needs the O_BINARY flag for open() */
-#ifndef O_BINARY
-#define O_BINARY       0
-#endif
 
 #ifdef HAVE_LIBPCAP
 gboolean auto_scroll_live;
@@ -301,7 +294,7 @@ cf_reset_state(capture_file *cf)
   if (cf->filename != NULL) {
     /* If it's a temporary file, remove it. */
     if (cf->is_tempfile)
-      unlink(cf->filename);
+      eth_unlink(cf->filename);
     g_free(cf->filename);
     cf->filename = NULL;
   }
@@ -987,7 +980,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
 
   if (*out_filenamep != NULL) {
     out_filename = *out_filenamep;
-    out_fd = open(out_filename, O_CREAT|O_TRUNC|O_BINARY, 0600);
+    out_fd = eth_open(out_filename, O_CREAT|O_TRUNC|O_BINARY, 0600);
     if (out_fd == -1)
       open_err = errno;
   } else {
@@ -1010,7 +1003,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
       merge_max_snapshot_length(in_file_count, in_files), 
          FALSE /* compressed */, &open_err);
   if (pdh == NULL) {
-    close(out_fd);
+    eth_close(out_fd);
     merge_close_in_files(in_file_count, in_files);
     free(in_files);
     cf_open_failure_alert_box(out_filename, open_err, err_info, TRUE,
@@ -2018,7 +2011,7 @@ cf_write_pdml_packets(capture_file *cf, print_args_t *print_args)
   FILE        *fh;
   psp_return_t ret;
 
-  fh = fopen(print_args->file, "w");
+  fh = eth_fopen(print_args->file, "w");
   if (fh == NULL)
     return CF_PRINT_OPEN_ERROR;        /* attempt to open destination failed */
 
@@ -2089,7 +2082,7 @@ cf_write_psml_packets(capture_file *cf, print_args_t *print_args)
   FILE        *fh;
   psp_return_t ret;
 
-  fh = fopen(print_args->file, "w");
+  fh = eth_fopen(print_args->file, "w");
   if (fh == NULL)
     return CF_PRINT_OPEN_ERROR;        /* attempt to open destination failed */
 
@@ -2160,7 +2153,7 @@ cf_write_csv_packets(capture_file *cf, print_args_t *print_args)
   FILE        *fh;
   psp_return_t ret;
 
-  fh = fopen(print_args->file, "w");
+  fh = eth_fopen(print_args->file, "w");
   if (fh == NULL)
     return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */
 
@@ -3175,7 +3168,7 @@ cf_save(capture_file *cf, const char *fname, packet_range_t *range, guint save_f
          capture, so it doesn't need to stay around under that name;
         first, try renaming the capture buffer file to the new name. */
 #ifndef _WIN32
-      if (rename(cf->filename, fname) == 0) {
+      if (eth_rename(cf->filename, fname) == 0) {
        /* That succeeded - there's no need to copy the source file. */
        from_filename = NULL;
        do_copy = FALSE;
@@ -3605,7 +3598,7 @@ copy_binary_file(const char *from_filename, const char *to_filename)
   guint8        pd[65536];
 
   /* Copy the raw bytes of the file. */
-  from_fd = open(from_filename, O_RDONLY | O_BINARY);
+  from_fd = eth_open(from_filename, O_RDONLY | O_BINARY, 0000 /* no creation so don't matter */);
   if (from_fd < 0) {
     open_failure_alert_box(from_filename, errno, FALSE);
     goto done;
@@ -3616,23 +3609,23 @@ copy_binary_file(const char *from_filename, const char *to_filename)
      may open the file in text mode, not binary mode, but we want
      to copy the raw bytes of the file, so we need the output file
      to be open in binary mode. */
-  to_fd = open(to_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
+  to_fd = eth_open(to_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
   if (to_fd < 0) {
     open_failure_alert_box(to_filename, errno, TRUE);
-    close(from_fd);
+    eth_close(from_fd);
     goto done;
   }
 
-  while ((nread = read(from_fd, pd, sizeof pd)) > 0) {
-    nwritten = write(to_fd, pd, nread);
+  while ((nread = eth_read(from_fd, pd, sizeof pd)) > 0) {
+    nwritten = eth_write(to_fd, pd, nread);
     if (nwritten < nread) {
       if (nwritten < 0)
        err = errno;
       else
        err = WTAP_ERR_SHORT_WRITE;
       write_failure_alert_box(to_filename, err);
-      close(from_fd);
-      close(to_fd);
+      eth_close(from_fd);
+      eth_close(to_fd);
       goto done;
     }
   }
@@ -3641,12 +3634,12 @@ copy_binary_file(const char *from_filename, const char *to_filename)
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                  "An error occurred while reading from the file \"%s\": %s.",
                  from_filename, strerror(err));
-    close(from_fd);
-    close(to_fd);
+    eth_close(from_fd);
+    eth_close(to_fd);
     goto done;
   }
-  close(from_fd);
-  if (close(to_fd) < 0) {
+  eth_close(from_fd);
+  if (eth_close(to_fd) < 0) {
     write_failure_alert_box(to_filename, errno);
     goto done;
   }
index b7d71d54719a693e8eb0cc0aff795a0e54759056..b023d2b14681c9a19e6e04951391206017fb8c03 100644 (file)
--- a/fileset.c
+++ b/fileset.c
 #include <unistd.h>
 #endif
 
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
@@ -55,6 +51,7 @@
 
 #include <glib.h>
 
+#include "file_util.h"
 #include "globals.h"
 
 #include <epan/filesystem.h>
@@ -183,7 +180,7 @@ fileset_add_file(const char *dirname, const char *fname, gboolean current)
 
     path = g_strdup_printf("%s%s", dirname, fname);
 
-    fh = open( path, O_RDONLY );
+    fh = eth_open( path, O_RDONLY, 0000 /* no creation so don't matter */);
     if(fh !=  -1) {
 
         /* Get statistics */
@@ -203,7 +200,7 @@ fileset_add_file(const char *dirname, const char *fname, gboolean current)
             set.entries = g_list_append(set.entries, entry);
         }
 
-        close(fh);
+        eth_close(fh);
     }
 
     g_free(path);
@@ -242,15 +239,9 @@ void fileset_update_dlg(void)
 void
 fileset_add_dir(const char *fname)
 {
-#if GLIB_MAJOR_VERSION < 2
-    DIR           *dir;             /* scanned directory */
-    struct dirent *file;            /* current file */
-    gchar         *name;
-#else /* GLIB 2 */
-    GDir          *dir;             /* scanned directory */
-    GError        **dummy;
+    ETH_DIR       *dir;             /* scanned directory */
+    ETH_DIRENT    *file;            /* current file */
     const char    *name;
-#endif
     fileset_entry *entry;
     GString       *dirname;
     gchar         *fname_dup;
@@ -268,31 +259,16 @@ fileset_add_dir(const char *fname)
     /* is the current file probably a part of any fileset? */
     if(fileset_filename_match_pattern(fname)) {
         /* yes, go through the files in the directory and check if the file in question is part of the current file set */
-#if GLIB_MAJOR_VERSION < 2
-        if ((dir = opendir(dirname->str)) != NULL) {
-               while ((file = readdir(dir)) != NULL) {
-                   name = (gchar *)file->d_name;
-#else
-        dummy = g_malloc(sizeof(GError *));
-        *dummy = NULL;
-
-        if ((dir = g_dir_open(dirname->str, 0, dummy)) != NULL) {
-            while ((name = g_dir_read_name(dir)) != NULL) {
-#endif
+        if ((dir = g_dir_open(dirname->str, 0, NULL)) != NULL) {
+               while ((file = eth_dir_read_name(dir)) != NULL) {
+                   name = eth_dir_get_name(file);
                 if(fileset_filename_match_pattern(name) && fileset_is_file_in_set(name, get_basename(fname))) {
                     fileset_add_file(dirname->str, name, strcmp(name, get_basename(fname))== 0 /* current */);
                 }
             } /* while */
 
-#if GLIB_MAJOR_VERSION < 2
-            closedir(dir);
-#else
-            g_dir_close(dir);
-#endif
+            eth_dir_close(dir);
         } /* if */
-#if GLIB_MAJOR_VERSION >= 2
-        g_free(dummy);
-#endif
     } else {
         /* no, this is a "standalone file", just add this one */
         entry = fileset_add_file(dirname->str, get_basename(fname), TRUE /* current */);
index f24f1d30c801ffbdcf41c6e4b22ca8969c2581a0..cdecc516913692d56ac32a54b86285d90ef7f073 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -40,6 +40,7 @@
 #include <epan/filesystem.h>
 
 #include "filters.h"
+#include "file_util.h"
 
 /*
  * Old filter file name.
@@ -114,7 +115,7 @@ read_filter_list(filter_list_type_t list, char **pref_path_return,
 
   /* try to open personal "cfilters"/"dfilters" file */
   ff_path = get_persconffile_path(ff_name, FALSE);
-  if ((ff = fopen(ff_path, "r")) == NULL) {
+  if ((ff = eth_fopen(ff_path, "r")) == NULL) {
     /*
      * Did that fail because the file didn't exist?
      */
@@ -137,7 +138,7 @@ read_filter_list(filter_list_type_t list, char **pref_path_return,
      */
     g_free(ff_path);
     ff_path = get_persconffile_path(FILTER_FILE_NAME, FALSE);
-    if ((ff = fopen(ff_path, "r")) == NULL) {
+    if ((ff = eth_fopen(ff_path, "r")) == NULL) {
     /*
      * Did that fail because the file didn't exist?
      */
@@ -153,7 +154,7 @@ read_filter_list(filter_list_type_t list, char **pref_path_return,
     /*
      * Try to open the global "cfilters/dfilters" file */
     ff_path = get_datafile_path(ff_name);
-    if ((ff = fopen(ff_path, "r")) == NULL) {
+    if ((ff = eth_fopen(ff_path, "r")) == NULL) {
 
       /*
        * Well, that didn't work, either.  Just give up.
@@ -460,7 +461,7 @@ save_filter_list(filter_list_type_t list, char **pref_path_return,
      completely. */
   ff_path_new = g_strdup_printf("%s.new", ff_path);
 
-  if ((ff = fopen(ff_path_new, "w")) == NULL) {
+  if ((ff = eth_fopen(ff_path_new, "w")) == NULL) {
     *pref_path_return = ff_path;
     *errno_return = errno;
     g_free(ff_path_new);
@@ -489,7 +490,7 @@ save_filter_list(filter_list_type_t list, char **pref_path_return,
       *pref_path_return = ff_path;
       *errno_return = errno;
       fclose(ff);
-      unlink(ff_path_new);
+      eth_unlink(ff_path_new);
       g_free(ff_path_new);
       return;
     }
@@ -498,7 +499,7 @@ save_filter_list(filter_list_type_t list, char **pref_path_return,
   if (fclose(ff) == EOF) {
     *pref_path_return = ff_path;
     *errno_return = errno;
-    unlink(ff_path_new);
+    eth_unlink(ff_path_new);
     g_free(ff_path_new);
     return;
   }
@@ -508,22 +509,22 @@ save_filter_list(filter_list_type_t list, char **pref_path_return,
      exists; the Win32 call to rename files doesn't do so, which I
      infer is the reason why the MSVC++ "rename()" doesn't do so.
      We must therefore remove the target file first, on Windows. */
-  if (remove(ff_path) < 0 && errno != ENOENT) {
+  if (eth_remove(ff_path) < 0 && errno != ENOENT) {
     /* It failed for some reason other than "it's not there"; if
        it's not there, we don't need to remove it, so we just
        drive on. */
     *pref_path_return = ff_path;
     *errno_return = errno;
-    unlink(ff_path_new);
+    eth_unlink(ff_path_new);
     g_free(ff_path_new);
     return;
   }
 #endif
 
-  if (rename(ff_path_new, ff_path) < 0) {
+  if (eth_rename(ff_path_new, ff_path) < 0) {
     *pref_path_return = ff_path;
     *errno_return = errno;
-    unlink(ff_path_new);
+    eth_unlink(ff_path_new);
     g_free(ff_path_new);
     return;
   }
index b1fa9b14eff21a6735102b1ffee6eb3cfd2b5784..cfac902365367c34e94531cb858e3ddb32fc0449 100644 (file)
 
 #ifdef HAVE_LIBPCAP
 
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-
 #ifdef HAVE_SYS_WAIT_H
 # include <sys/wait.h>
 #endif
index ca282f4422d64c338839493fe3a6308523e68675..d868de3e613a996d8eea92dd7b932b5a1cb635e6 100644 (file)
 # include "config.h"
 #endif
 
-#ifdef HAVE_IO_H
-#include <io.h> /* open/close on win32 */
-#endif
-
 #ifdef HAVE_LIBPCAP
 #include <pcap.h>
 #endif
index a4735722d2ae9ae349ef9bc91245704e120573a9..3d60e7fd94210d533356cb9b9348671d17414728 100644 (file)
 #include <unistd.h>
 #endif
 
-#ifdef HAVE_IO_H
-#include <io.h> /* open/close on win32 */
-#endif
-
 static void file_open_ok_cb(GtkWidget *w, gpointer fs);
 static void file_open_destroy_cb(GtkWidget *win, gpointer user_data);
 static void file_merge_ok_cb(GtkWidget *w, gpointer fs);
index 4ee09596c3bbbbf6c56b2416a6583deec4c5e9a1..1cb519604b661b60554462ade10a4786bc2f2403 100644 (file)
 
 #include <string.h>
 
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
index f6049c5b6ca1cc57a04730d4046f5203a059c1f1..2d1417e0902a4063ad9162300ac1ecf9dd6236ec 100644 (file)
@@ -29,7 +29,6 @@
  * "Capture Filter" / "Display Filter" / "Add expression" dialog boxes.
  * (This used to be a notebook page under "Preferences", hence the
  * "prefs" in the file name.)
- * @todo rename this and the corresponding .c file to filter_dlg to reflect current implementation
  * @ingroup dialog_group
  */
 
index 8765363952516594745875cf730aaf5478125109..23535c1a0562a95d9cb0d14d8560a9a20e9f4ea4 100644 (file)
@@ -30,9 +30,6 @@
 #include <stdio.h>
 #include <string.h>
 
-#ifdef HAVE_IO_H
-#include <io.h>                        /* open/close on win32 */
-#endif
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -42,6 +39,7 @@
 
 #include "isprint.h"
 
+#include "file_util.h"
 #include "color.h"
 #include "colors.h"
 #include "file.h"
@@ -203,7 +201,7 @@ follow_stream_cb(GtkWidget * w, gpointer data _U_)
            simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                          "Could not create temporary file %s: %s",
                          follow_info->data_out_filename, strerror(errno));
-           close(tmp_fd);
+           eth_close(tmp_fd);
            unlink(follow_info->data_out_filename);
            g_free(follow_info);
            return;
@@ -601,7 +599,7 @@ follow_read_stream(follow_info_t *follow_info,
 
     iplen = (follow_info->is_ipv6) ? 16 : 4;
 
-    data_out_file = fopen(follow_info->data_out_filename, "rb");
+    data_out_file = eth_fopen(follow_info->data_out_filename, "rb");
     if (data_out_file == NULL) {
        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                      "Could not open temporary file %s: %s", follow_info->data_out_filename,
@@ -931,7 +929,7 @@ follow_print_stream(GtkWidget * w _U_, gpointer data)
         print_mswin(print_dest);
 
         /* trash temp file */
-        remove(print_dest);
+        eth_remove(print_dest);
     }
 #endif
     return;
@@ -949,7 +947,7 @@ print_error:
 #ifdef _WIN32
     if (win_printer) {
         /* trash temp file */
-        remove(print_dest);
+        eth_remove(print_dest);
     }
 #endif
 }
@@ -1138,10 +1136,10 @@ follow_save_as_ok_cb(GtkWidget * w _U_, gpointer fs)
     follow_info = OBJECT_GET_DATA(fs, E_FOLLOW_INFO_KEY);
     if (follow_info->show_type == SHOW_RAW) {
         /* Write the data out as raw binary data */
-        fh = fopen(to_name, "wb");
+        fh = eth_fopen(to_name, "wb");
     } else {
         /* Write it out as text */
-        fh = fopen(to_name, "w");
+        fh = eth_fopen(to_name, "w");
     }
     if (fh == NULL) {
         open_failure_alert_box(to_name, errno, TRUE);
index 624debaa7b617fd1f78583b249eee5d143dc3290..ff4716a56ff0b8b0f071b5fb1101560ca5103d7c 100644 (file)
@@ -57,6 +57,7 @@
 #include "compat_macros.h"
 #include "../color.h"
 #include "epan/filesystem.h"
+#include "file_util.h"
 
 #include <string.h>
 
@@ -294,7 +295,7 @@ static gboolean dialog_graph_dump_to_file(graph_analysis_data_t* user_data)
 
        FILE *of;
 
-       of = fopen(user_data->dlg.save_file,"w");
+       of = eth_fopen(user_data->dlg.save_file,"w");
        if (of==NULL){
                return FALSE;
        }
@@ -526,7 +527,7 @@ static void save_to_file_ok_cb(GtkWidget *ok_bt _U_, gpointer user_data _U_)
 
 
        /* check whether the file exists */
-       file_test = fopen(user_data_p->dlg.save_file,"r");
+       file_test = eth_fopen(user_data_p->dlg.save_file,"r");
        if (file_test!=NULL){
 
                dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO,
index 725dcfcb08f240d131930631594b50c73b7b9515..0f927c0cd39355c81ba4213f0faaa3741761f776 100644 (file)
 #include <windows.h>
 #endif
 
-#ifdef HAVE_IO_H
-# include <io.h>
-#endif
 
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
+#include "file_util.h"
 #include "gtkglobals.h"
 #include "gui_utils.h"
 #include <epan/prefs.h>
index 3d4884afd321412f731a7dafe696d56fc7a1745d..464b9983342f08cf22cbdb370acb3e6e2ae670e4 100644 (file)
@@ -42,6 +42,7 @@
 #include "dlg_utils.h"
 #include "simple_dialog.h"
 #include "webbrowser.h"
+#include "file_util.h"
 
 #define HELP_DIR       "help"
 
@@ -116,7 +117,7 @@ void help_dialog(void)
   }
 
   help_toc_file_path = get_datafile_path(HELP_DIR G_DIR_SEPARATOR_S "toc");
-  help_toc_file = fopen(help_toc_file_path, "r");
+  help_toc_file = eth_fopen(help_toc_file_path, "r");
   if (help_toc_file == NULL) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not open file \"%s\": %s",
                   help_toc_file_path, strerror(errno));
index 584e9292a955987e582997fc8ad83ddb970b1cd5..67757b674c563abd8539df0cc1e6f3e5201fc23c 100644 (file)
 #include <unistd.h>
 #endif
 
-#ifdef HAVE_IO_H
-#include <io.h> /* open/close on win32 */
-#endif
-
 #ifdef NEED_STRERROR_H
 #include "strerror.h"
 #endif
 #include "capture_ui_utils.h"
 #include "log.h"
 #include "../epan/emem.h"
+#include "file_util.h"
 
 
 
@@ -2690,9 +2687,9 @@ create_console(void)
        create one and make it the standard input, output, and error. */
     if (!AllocConsole())
       return;   /* couldn't create console */
-    freopen("CONIN$", "r", stdin);
-    freopen("CONOUT$", "w", stdout);
-    freopen("CONOUT$", "w", stderr);
+    eth_freopen("CONIN$", "r", stdin);
+    eth_freopen("CONOUT$", "w", stdout);
+    eth_freopen("CONOUT$", "w", stderr);
 
     /* Well, we have a console now. */
     has_console = TRUE;
index 61caec2883a49cbc1454c41e6a9a425115307983..0478bbc525cc436c806e38b5c94d3d2be6d3f106 100644 (file)
 #include <epan/epan_dissect.h>
 #include <epan/filesystem.h>
 #ifdef _WIN32
-#include <io.h>
 #include "print_mswin.h"
 #endif
 #include "compat_macros.h"
 #include "range_utils.h"
 #include "help_dlg.h"
+#include "file_util.h"
 
 
 /* dialog output action */
@@ -988,7 +988,7 @@ print_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
     print_mswin(args->file);
 
     /* trash temp file */
-    remove(args->file);
+    eth_remove(args->file);
   }
 #endif
 }
index f61bd7c503d25da579e9f15174213d3dadbdaab3..8e772628faf0411edc9e6b1e316229b16e75f35d 100644 (file)
@@ -38,6 +38,7 @@
 #endif
 
 #include "print_mswin.h"
+#include "file_util.h"
 
 /*
 Some thoughts about a GTK win32 printer dialog:
@@ -187,7 +188,7 @@ void print_file( char *file_name, HDC hdc) {
     SetMapMode (hdc, MM_TEXT);
 
 
-    fh1 = fopen( file_name, "r" );
+    fh1 = eth_fopen( file_name, "r" );
     if( !fh1 )
         perror( "open failed on input file" );
 
index 8cb6bf513d03fe25929e2855fbf313e8fd5d25fc..0d0c8a47f98bcfc32a7924455f69e650ec0115d7 100644 (file)
 
 #include <ctype.h>
 
-#ifdef HAVE_IO_H
-#include <io.h>                        /* open/close on win32 */
-#endif
-
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
 #include "font_utils.h"
 
 #include "../ui_util.h"
-
-/* Win32 needs the O_BINARY flag for open() */
-#ifndef O_BINARY
-#define O_BINARY       0
-#endif
+#include "file_util.h"
 
 #define BYTE_VIEW_WIDTH    16
 #define BYTE_VIEW_SEP      8
@@ -886,17 +878,17 @@ savehex_save_clicked_cb(GtkWidget * w _U_, gpointer data _U_)
                return;
        }
 
-       fd = open(file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
+       fd = eth_open(file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
        if (fd == -1) {
                open_failure_alert_box(file, errno, TRUE);
                return;
        }
-       if (write(fd, data_p + start, end - start) < 0) {
+       if (eth_write(fd, data_p + start, end - start) < 0) {
                write_failure_alert_box(file, errno);
-               close(fd);
+               eth_close(fd);
                return;
        }
-       if (close(fd) < 0) {
+       if (eth_close(fd) < 0) {
                write_failure_alert_box(file, errno);
                return;
        }
index 85e505cdb34113b54893259f32ece3516ec367c3..7e7c09ef6dd790ab9f212f560e95ff01cdf89e38 100644 (file)
@@ -43,6 +43,7 @@
 #include "dlg_utils.h"
 #include "cfilter_combo_utils.h"
 #include "simple_dialog.h"
+#include "file_util.h"
 
 #define RECENT_KEY_MAIN_TOOLBAR_SHOW        "gui.toolbar_main_show"
 #define RECENT_KEY_FILTER_TOOLBAR_SHOW      "gui.filter_toolbar_show"
@@ -121,7 +122,7 @@ write_recent(void)
   }
 
   rf_path = get_persconffile_path(RECENT_FILE_NAME, TRUE);
-  if ((rf = fopen(rf_path, "w")) == NULL) {
+  if ((rf = eth_fopen(rf_path, "w")) == NULL) {
      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
       "Can't open recent file\n\"%s\": %s.", rf_path,
       strerror(errno));
@@ -522,7 +523,7 @@ recent_read_static(char **rf_path_return, int *rf_errno_return)
 
   /* Read the user's recent file, if it exists. */
   *rf_path_return = NULL;
-  if ((rf = fopen(rf_path, "r")) != NULL) {
+  if ((rf = eth_fopen(rf_path, "r")) != NULL) {
     /* We succeeded in opening it; read it. */
     read_prefs_file(rf_path, rf, read_set_recent_pair_static);
     fclose(rf);
@@ -554,7 +555,7 @@ recent_read_dynamic(char **rf_path_return, int *rf_errno_return)
 
   /* Read the user's recent file, if it exists. */
   *rf_path_return = NULL;
-  if ((rf = fopen(rf_path, "r")) != NULL) {
+  if ((rf = eth_fopen(rf_path, "r")) != NULL) {
     /* We succeeded in opening it; read it. */
     read_prefs_file(rf_path, rf, read_set_recent_pair_dynamic);
        /* set dfilter combobox to have an empty line */
index 4ec79d7dd5d859b17af87e1230ab7e3084873d7b..4489869b0fb507481d57b771883482b422b52e83 100644 (file)
 #include <fcntl.h>
 #endif
 
-#ifdef HAVE_IO_H
-#include <io.h> /* open/close on win32 */
-#endif
-
-/* Win32 needs the O_BINARY flag for open() */
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
+#include "file_util.h"
 
 /****************************************************************************/
 
@@ -477,10 +470,10 @@ rtp_reset(void *user_data_arg)
                fclose(user_data->forward.saveinfo.fp); 
        if (user_data->reversed.saveinfo.fp != NULL)
                fclose(user_data->reversed.saveinfo.fp); 
-       user_data->forward.saveinfo.fp = fopen(user_data->f_tempname, "wb"); 
+       user_data->forward.saveinfo.fp = eth_fopen(user_data->f_tempname, "wb"); 
        if (user_data->forward.saveinfo.fp == NULL)
                user_data->forward.saveinfo.error_type = TAP_RTP_FILE_OPEN_ERROR;
-       user_data->reversed.saveinfo.fp = fopen(user_data->r_tempname, "wb");
+       user_data->reversed.saveinfo.fp = eth_fopen(user_data->r_tempname, "wb");
        if (user_data->reversed.saveinfo.fp == NULL)
                user_data->reversed.saveinfo.error_type = TAP_RTP_FILE_OPEN_ERROR;
        return;
@@ -1006,8 +999,8 @@ static void on_destroy(GtkWidget *win _U_, user_data_t *user_data _U_)
        if (user_data->reversed.saveinfo.fp != NULL)
                fclose(user_data->reversed.saveinfo.fp);
        /*XXX: test for error **/
-       remove(user_data->f_tempname);
-       remove(user_data->r_tempname);
+       eth_remove(user_data->f_tempname);
+       eth_remove(user_data->r_tempname);
 
        /* destroy save_voice_as window if open */
        if (user_data->dlg.save_voice_as_w != NULL)
@@ -2274,7 +2267,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
        user_data = (user_data_t*)OBJECT_GET_DATA(bt, "user_data");
        
        if (GTK_TOGGLE_BUTTON(forw)->active || GTK_TOGGLE_BUTTON(both)->active) {
-               fp = fopen(g_dest, "w");
+               fp = eth_fopen(g_dest, "w");
                if (fp == NULL) {
                        open_failure_alert_box(g_dest, errno, TRUE);
                        return;
@@ -2328,7 +2321,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
        if (GTK_TOGGLE_BUTTON(rev)->active || GTK_TOGGLE_BUTTON(both)->active) {
                
                if (GTK_TOGGLE_BUTTON(both)->active) {
-                       fp = fopen(g_dest, "a");
+                       fp = eth_fopen(g_dest, "a");
                        if (fp == NULL) {
                                open_failure_alert_box(g_dest, errno, TRUE);
                                return;
@@ -2340,7 +2333,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
                                return;
                        }
                } else {
-                       fp = fopen(g_dest, "w");
+                       fp = eth_fopen(g_dest, "w");
                        if (fp == NULL) {
                                open_failure_alert_box(g_dest, errno, TRUE);
                                return;
@@ -2503,20 +2496,20 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t *
        guint32 progbar_count, progbar_quantum, progbar_nextstep = 0, count = 0;
        gboolean stop_flag = FALSE;
 
-       forw_fd = open(user_data->f_tempname, O_RDONLY | O_BINARY);
+       forw_fd = eth_open(user_data->f_tempname, O_RDONLY | O_BINARY, 0000 /* no creation so don't matter */);
        if (forw_fd < 0) 
                return FALSE;
-       rev_fd = open(user_data->r_tempname, O_RDONLY | O_BINARY);
+       rev_fd = eth_open(user_data->r_tempname, O_RDONLY | O_BINARY, 0000 /* no creation so don't matter */);
        if (rev_fd < 0) {
-               close(forw_fd); 
+               eth_close(forw_fd); 
                return FALSE;
        }
 
        /* open file for saving */
-       to_fd = open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
+       to_fd = eth_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
        if (to_fd < 0) {
-               close(forw_fd);
-               close(rev_fd);
+               eth_close(forw_fd);
+               eth_close(rev_fd);
                return FALSE;
        }
 
@@ -2526,35 +2519,35 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t *
        {
                /* First we write the .au header. XXX Hope this is endian independant */
                /* the magic word 0x2e736e64 == .snd */
-               *pd = (unsigned char)0x2e; write(to_fd, pd, 1);
-               *pd = (unsigned char)0x73; write(to_fd, pd, 1);
-               *pd = (unsigned char)0x6e; write(to_fd, pd, 1);
-               *pd = (unsigned char)0x64; write(to_fd, pd, 1);
+               *pd = (unsigned char)0x2e; eth_write(to_fd, pd, 1);
+               *pd = (unsigned char)0x73; eth_write(to_fd, pd, 1);
+               *pd = (unsigned char)0x6e; eth_write(to_fd, pd, 1);
+               *pd = (unsigned char)0x64; eth_write(to_fd, pd, 1);
                /* header offset == 24 bytes */
-               *pd = (unsigned char)0x00; write(to_fd, pd, 1);
-               write(to_fd, pd, 1);
-               write(to_fd, pd, 1);
-               *pd = (unsigned char)0x18; write(to_fd, pd, 1);
+               *pd = (unsigned char)0x00; eth_write(to_fd, pd, 1);
+               eth_write(to_fd, pd, 1);
+               eth_write(to_fd, pd, 1);
+               *pd = (unsigned char)0x18; eth_write(to_fd, pd, 1);
                /* total length, it is permited to set this to 0xffffffff */
-               *pd = (unsigned char)0xff; write(to_fd, pd, 1); 
-               write(to_fd, pd, 1); 
-               write(to_fd, pd, 1); 
-               write(to_fd, pd, 1);
+               *pd = (unsigned char)0xff; eth_write(to_fd, pd, 1); 
+               eth_write(to_fd, pd, 1); 
+               eth_write(to_fd, pd, 1); 
+               eth_write(to_fd, pd, 1);
                /* encoding format == 8 bit ulaw */
-               *pd = (unsigned char)0x00; write(to_fd, pd, 1);
-               write(to_fd, pd, 1);
-               write(to_fd, pd, 1);
-               *pd = (unsigned char)0x01; write(to_fd, pd, 1);
+               *pd = (unsigned char)0x00; eth_write(to_fd, pd, 1);
+               eth_write(to_fd, pd, 1);
+               eth_write(to_fd, pd, 1);
+               *pd = (unsigned char)0x01; eth_write(to_fd, pd, 1);
                /* sample rate == 8000 Hz */
-               *pd = (unsigned char)0x00; write(to_fd, pd, 1);
-               write(to_fd, pd, 1);
-               *pd = (unsigned char)0x1f; write(to_fd, pd, 1);
-               *pd = (unsigned char)0x40; write(to_fd, pd, 1);
+               *pd = (unsigned char)0x00; eth_write(to_fd, pd, 1);
+               eth_write(to_fd, pd, 1);
+               *pd = (unsigned char)0x1f; eth_write(to_fd, pd, 1);
+               *pd = (unsigned char)0x40; eth_write(to_fd, pd, 1);
                /* channels == 1 */
-               *pd = (unsigned char)0x00; write(to_fd, pd, 1);
-               write(to_fd, pd, 1);
-               write(to_fd, pd, 1);
-               *pd = (unsigned char)0x01; write(to_fd, pd, 1);
+               *pd = (unsigned char)0x00; eth_write(to_fd, pd, 1);
+               eth_write(to_fd, pd, 1);
+               eth_write(to_fd, pd, 1);
+               *pd = (unsigned char)0x01; eth_write(to_fd, pd, 1);
        
        
                switch (channels) {
@@ -2580,18 +2573,18 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t *
                                                *pd = (unsigned char)linear2ulaw(tmp);
                                        }
                                        else{
-                                               close(forw_fd);
-                                               close(rev_fd);
-                                               close(to_fd);
+                                               eth_close(forw_fd);
+                                               eth_close(rev_fd);
+                                               eth_close(to_fd);
                                                destroy_progress_dlg(progbar);
                                                return FALSE;
                                        }
                                        
-                                       fwritten = write(to_fd, pd, 1);
+                                       fwritten = eth_write(to_fd, pd, 1);
                                        if ((fwritten < fread) || (fwritten < 0) || (fread < 0)) {
-                                               close(forw_fd);
-                                               close(rev_fd);
-                                               close(to_fd);
+                                               eth_close(forw_fd);
+                                               eth_close(rev_fd);
+                                               eth_close(to_fd);
                                                destroy_progress_dlg(progbar);
                                                return FALSE;
                                        }
@@ -2620,18 +2613,18 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t *
                                                *pd = (unsigned char)linear2ulaw(tmp);
                                        }
                                        else{
-                                               close(forw_fd);
-                                               close(rev_fd);
-                                               close(to_fd);
+                                               eth_close(forw_fd);
+                                               eth_close(rev_fd);
+                                               eth_close(to_fd);
                                                destroy_progress_dlg(progbar);
                                                return FALSE;
                                        }
                                        
-                                       rwritten = write(to_fd, pd, 1);
+                                       rwritten = eth_write(to_fd, pd, 1);
                                        if ((rwritten < rread) || (rwritten < 0) || (rread < 0)) {
-                                               close(forw_fd);
-                                               close(rev_fd);
-                                               close(to_fd);
+                                               eth_close(forw_fd);
+                                               eth_close(rev_fd);
+                                               eth_close(to_fd);
                                                destroy_progress_dlg(progbar);
                                                return FALSE;
                                        }
@@ -2707,19 +2700,19 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t *
                                        }
                                        else
                                        {
-                                               close(forw_fd);
-                                               close(rev_fd);
-                                               close(to_fd);
+                                               eth_close(forw_fd);
+                                               eth_close(rev_fd);
+                                               eth_close(to_fd);
                                                destroy_progress_dlg(progbar);
                                                return FALSE;
                                        }
                                        
                                        
-                                       rwritten = write(to_fd, pd, 1);
+                                       rwritten = eth_write(to_fd, pd, 1);
                                        if ((rwritten < 0) || (rread < 0) || (fread < 0)) {
-                                               close(forw_fd);
-                                               close(rev_fd);
-                                               close(to_fd);
+                                               eth_close(forw_fd);
+                                               eth_close(rev_fd);
+                                               eth_close(to_fd);
                                                destroy_progress_dlg(progbar);
                                                return FALSE;
                                        }
@@ -2746,9 +2739,9 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t *
                                break;
                        }
                        default: {
-                               close(forw_fd);
-                               close(rev_fd);
-                               close(to_fd);
+                               eth_close(forw_fd);
+                               eth_close(rev_fd);
+                               eth_close(to_fd);
                                destroy_progress_dlg(progbar);
                                return FALSE;
                        }
@@ -2767,12 +2760,12 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t *
                        }
                        count++;
 
-                       rwritten = write(to_fd, pd, 1);
+                       rwritten = eth_write(to_fd, pd, 1);
 
                        if ((rwritten < rread) || (rwritten < 0) || (rread < 0)) {
-                               close(forw_fd);
-                               close(rev_fd);
-                               close(to_fd);
+                               eth_close(forw_fd);
+                               eth_close(rev_fd);
+                               eth_close(to_fd);
                                destroy_progress_dlg(progbar);
                                return FALSE;
                        }
@@ -2780,9 +2773,9 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t *
        }
 
        destroy_progress_dlg(progbar);
-       close(forw_fd);
-       close(rev_fd);
-       close(to_fd);
+       eth_close(forw_fd);
+       eth_close(rev_fd);
+       eth_close(to_fd);
        return TRUE;
 }
 
@@ -3687,10 +3680,10 @@ void rtp_analysis(
        /*XXX: check for errors*/
        fd = create_tempfile(user_data->f_tempname, sizeof(user_data->f_tempname),
                "ether_rtp_f");
-       close(fd);
+       eth_close(fd);
        fd = create_tempfile(user_data->r_tempname, sizeof(user_data->r_tempname),
                "ether_rtp_r");
-       close(fd);
+       eth_close(fd);
        user_data->forward.saveinfo.fp = NULL;
        user_data->reversed.saveinfo.fp = NULL;
        user_data->dlg.save_voice_as_w = NULL;
index 7d93a3b1a157344f2c0f87a083851dd20f7430a5..75b82fc65f1439542d20022239d7b14ffee505fd 100644 (file)
@@ -41,6 +41,7 @@
 
 #include "alert_box.h"
 #include "simple_dialog.h"
+#include "file_util.h"
 
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
@@ -337,7 +338,7 @@ gboolean rtpstream_save(rtp_stream_info_t* stream, const gchar *filename)
 {
        gboolean was_registered = the_tapinfo_struct.is_registered;
        /* open file for saving */
-       the_tapinfo_struct.save_file = fopen(filename, "wb");
+       the_tapinfo_struct.save_file = eth_fopen(filename, "wb");
        if (the_tapinfo_struct.save_file==NULL) {
                open_failure_alert_box(filename, errno, TRUE);
                return FALSE;
index eb4d415682a29d308dc983f4c7569d06b9b5cbaa..a51c8a10d8a16a50f1e5aea20e102a38458058de 100644 (file)
@@ -38,6 +38,7 @@
 #include "compat_macros.h"
 #include "simple_dialog.h"
 #include "font_utils.h"
+#include "file_util.h"
 
 #define TEXT_KEY        "txt_key"
 
@@ -129,7 +130,7 @@ static void text_page_set_text(GtkWidget *page, const char *absolute_path)
   gtk_text_freeze(txt);
 #endif
 
-  text_file = fopen(absolute_path, "r");
+  text_file = eth_fopen(absolute_path, "r");
   if (text_file != NULL) {
     while (fgets(line, sizeof line, text_file) != NULL) {
       text_page_insert(page, line, strlen(line));
index 9136e64930b6a249810709ba2a08e8f283b336cb..a74039cfe295973236ffdc06afca7002e1fc601c 100644 (file)
 
 #include "svnversion.h"
 #include "merge.h"
-
-#ifdef HAVE_IO_H
-# include <io.h>
-#endif
+#include "file_util.h"
 
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
 
-/* Win32 needs the O_BINARY flag for open() */
-#ifndef O_BINARY
-#define O_BINARY       0
-#endif
-
 static int
 get_natural_int(const char *string, const char *name)
 {
@@ -292,7 +284,7 @@ main(int argc, char *argv[])
     out_fd = 1 /*stdout*/;
   } else {
     /* open the outfile */
-    out_fd = open(out_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
+    out_fd = eth_open(out_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
     if (out_fd == -1) {
       fprintf(stderr, "mergecap: Couldn't open output file %s: %s\n",
               out_filename, strerror(errno));
index 4d1ffcde1e85eb92f4f9846cbacaf08bcf11863c..dc847f68cc9a42361901f396322ebfa3c6328cc9 100644 (file)
--- a/mkstemp.c
+++ b/mkstemp.c
 #include <errno.h>
 #include <stdio.h>
 
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
@@ -43,7 +39,7 @@
 
 #include <glib.h>
 
-#include "mkstemp.h"
+#include "file_util.h"
 
 #ifndef __set_errno
 #define __set_errno(x) errno=(x)
@@ -80,7 +76,7 @@ mkstemp (template)
 
       template[len - 6] = letters[i];
 
-      fd = open (template, O_RDWR|O_BINARY|O_CREAT|O_EXCL, 0600);
+      fd = eth_open (template, O_RDWR|O_BINARY|O_CREAT|O_EXCL, 0600);
       if (fd >= 0)
        return fd;
     }
index 9f4a6798d74cffda07c42f7d0e7edcfcdf6a8b90..c377e91657cc6ff9762f083cb5b1e21b9b41d7b5 100644 (file)
@@ -243,7 +243,7 @@ get_interface_list(int *err, char *err_str)
 #endif
 
        g_free(ifc.ifc_buf);
-       close(sock);
+       eth_close(sock);
 
        if (il == NULL) {
                /*
@@ -257,7 +257,7 @@ fail:
        if (il != NULL)
                free_interface_list(il);
        g_free(ifc.ifc_buf);
-       close(sock);
+       eth_close(sock);
        *err = CANT_GET_INTERFACE_LIST;
        return NULL;
 #endif /* HAVE_PCAP_FINDALLDEVS */
index 090e62e654469ac9e750c5c0e19a80aee3cd363d..43135fc5e49528f2a8d6faf3a6a5144a00bebdd0 100644 (file)
@@ -83,6 +83,7 @@
 #include <epan/report_err.h>
 #include <epan/dissectors/packet-tcp.h>
 #include <epan/asn1.h>
+#include "file_util.h"
 
 #ifdef DISSECTOR_WITH_GUI
 #include <gtk/gtk.h>
@@ -2729,7 +2730,7 @@ static char eol[] = "\r\n";
        (void) log_domain; (void) log_level; (void) user_data; /* make references */
 
        if (logf == NULL && asn1_logfile) {
-               logf = fopen(asn1_logfile, "w");
+               logf = eth_fopen(asn1_logfile, "w");
        }
        if (logf) {
        fputs(message, logf);
@@ -2749,7 +2750,7 @@ read_asn1_type_table(const char *filename)
        if ((filename == 0) || (strlen(filename) == 0))
                return;         /* no filename provided */
 
-       f = fopen(filename, "rb");
+       f = eth_fopen(filename, "rb");
        if (f == 0) {
                /*
                 * Ignore "file not found" errors if it's the old default
@@ -3858,7 +3859,7 @@ create_message_window(void)
        model = gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT,
                                   G_TYPE_STRING, G_TYPE_STRING);
 
-       namelist = fopen("namelist.txt", "w");
+       namelist = eth_fopen("namelist.txt", "w");
        build_tree_view(model, PDUtree, NULL);
        fclose(namelist);
        namelist = 0;
index fa3f16e5b90ca35171d6d06988bfd55b8cdcdebb..89349317e4768e3f8614880816a763f3802b7fec 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "mate.h"
 #include "mate_util.h"
+#include "file_util.h"
 
 /***************************************************************************
 *  dbg_print
@@ -1668,7 +1669,7 @@ extern LoAL* loal_from_file(gchar* filename) {
 
        state = START;
 
-       if (( fp = fopen(filename,"r") )) {
+       if (( fp = eth_fopen(filename,"r") )) {
                while(( c = (gchar) fgetc(fp) )){
 
                        if ( feof(fp) ) {
diff --git a/print.c b/print.c
index 63adb1f9c6c3d19e08c5304194a62074b915f14b..892438caa464c696b0bdb4250273fc146c016c8f 100644 (file)
--- a/print.c
+++ b/print.c
@@ -39,6 +39,7 @@
 #include "packet-range.h"
 #include "print.h"
 #include "ps.h"
+#include "file_util.h"
 #include <epan/charsets.h>
 #include <epan/dissectors/packet-data.h>
 #include <epan/dissectors/packet-frame.h>
@@ -83,7 +84,7 @@ open_print_dest(int to_file, const char *dest)
 
        /* Open the file or command for output */
        if (to_file)
-               fh = fopen(dest, "w");
+               fh = eth_fopen(dest, "w");
        else
                fh = popen(dest, "w");
 
index 4f1d5fe0da2c40c2f15b84f450fc5d7cac11326f..0c1e7f4b759a1def7cf8d621bf084a10cd33f8ed 100644 (file)
 
 #ifdef HAVE_LIBPCAP
 
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
 
 #include <wiretap/wtap.h>
 #include "ringbuffer.h"
+#include "file_util.h"
 
-/* Win32 needs the O_BINARY flag for open() */
-#ifndef O_BINARY
-#define O_BINARY       0
-#endif
 
 /* Ringbuffer file structure */
 typedef struct _rb_file {
@@ -109,7 +102,7 @@ static int ringbuf_open_file(rb_file *rfile, int *err)
   if (rfile->name != NULL) {
     if (rb_data.unlimited == FALSE) {
       /* remove old file (if any, so ignore error) */
-      unlink(rfile->name);
+      eth_unlink(rfile->name);
     }
     g_free(rfile->name);
   }
@@ -129,7 +122,7 @@ static int ringbuf_open_file(rb_file *rfile, int *err)
     return -1;
   }
 
-  rb_data.fd = open(rfile->name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT, 0600);
+  rb_data.fd = eth_open(rfile->name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT, 0600);
 
   if (rb_data.fd == -1 && err != NULL) {
     *err = errno;
@@ -258,7 +251,7 @@ ringbuf_switch_file(wtap_dumper **pdh, gchar **save_file, int *save_file_fd, int
   /* close current file */
 
   if (!wtap_dump_close(rb_data.pdh, err)) {
-    close(rb_data.fd); /* XXX - the above should have closed this already */
+    eth_close(rb_data.fd);     /* XXX - the above should have closed this already */
     rb_data.pdh = NULL;        /* it's still closed, we just got an error while closing */
     rb_data.fd = -1;
     return FALSE;
@@ -301,7 +294,7 @@ ringbuf_wtap_dump_close(gchar **save_file, int *err)
   /* close current file, if it's open */
   if (rb_data.pdh != NULL) {
     if (!wtap_dump_close(rb_data.pdh, err)) {
-      close(rb_data.fd);
+      eth_close(rb_data.fd);
       ret_val = FALSE;
     }
 
@@ -362,14 +355,14 @@ ringbuf_error_cleanup(void)
   /* XXX - it shouldn't still be open; "wtap_dump_close()" should leave the
      file closed even if it fails */
   if (rb_data.fd != -1) {
-    close(rb_data.fd);
+    eth_close(rb_data.fd);
     rb_data.fd = -1;
   }
 
   if (rb_data.files != NULL) {
     for (i=0; i < rb_data.num_files; i++) {
       if (rb_data.files[i].name != NULL) {
-        unlink(rb_data.files[i].name);
+        eth_unlink(rb_data.files[i].name);
       }
     }
   }
index b78250a88a5f678449489a42de2109a28d68f6a2..cc2fd6cf229380cd66467af37f36d57e3d75774b 100644 (file)
@@ -1923,7 +1923,7 @@ capture(char *save_file, int out_file_type)
 
 #ifndef _WIN32
   if (ld.from_pipe && pipe_fd >= 0)
-    close(pipe_fd);
+    eth_close(pipe_fd);
   else
 #endif
   {
@@ -1956,7 +1956,7 @@ error:
 #ifndef _WIN32
   if (ld.from_pipe) {
     if (pipe_fd >= 0)
-      close(pipe_fd);
+      eth_close(pipe_fd);
   } else
 #endif
   {
@@ -3100,7 +3100,7 @@ pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ldat,
   if (strcmp(pipename, "-") == 0)
     fd = 0; /* read from stdin */
   else {
-    if (stat(pipename, &pipe_stat) < 0) {
+    if (eth_stat(pipename, &pipe_stat) < 0) {
       if (errno == ENOENT || errno == ENOTDIR)
         ldat->pipe_err = PIPNEXIST;
       else {
@@ -3126,7 +3126,7 @@ pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ldat,
       }
       return -1;
     }
-    fd = open(pipename, O_RDONLY);
+    fd = eth_open(pipename, O_RDONLY, 0000 /* no creation so don't matter */);
     if (fd == -1) {
       g_snprintf(errmsg, errmsgl,
           "The capture session could not be initiated "
@@ -3221,7 +3221,7 @@ pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ldat,
 
 error:
   ldat->pipe_err = PIPERR;
-  close(fd);
+  eth_close(fd);
   return -1;
 
 }
diff --git a/util.c b/util.c
index f6ed670b13be13d003cade19dee5da1d35194208..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_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>
@@ -130,7 +117,7 @@ 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) {
@@ -152,7 +139,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 = mkstemp(namebuf);
+       tmp_fd = eth_mkstemp(namebuf);
        umask(old_umask);
        return tmp_fd;
 }
index 2ff4794a01bb970eae06615a1405c03e6e68e487..85694f6732eb2e1a7af47668b038606f6ddd9d47 100644 (file)
 #include "ascend.h"
 #include "ascend-int.h"
 #include "file_wrappers.h"
+#include "file_util.h"
 
 #include <errno.h>
 
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
index 2ed61923942508946efef2768ae4f5ebc8ede313..6d00ecba0859d202ae407234bfd817de56013b9e 100644 (file)
@@ -45,9 +45,6 @@
 #define VERSION "@VERSION@"
 
 #define HAVE_WINSOCK2_H                1
-#define HAVE_IO_H              1
-#define open                    _open
-#define close                   _close
 #define HAVE_PCAP_H     1
 
 /* Needed for zlib, according to http://www.winimage.com/zLibDll/ */
index 08b4d72384c5b09ed8423ef7d075f0c8348c0ffe..abc147afaffb9d4e5e325287e8a05bce3f6dced4 100644 (file)
 #include <fcntl.h>
 #endif
 
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
 #include <errno.h>
 
-#ifdef HAVE_IO_H
-#include <io.h>        /* open/close on win32 */
-#endif
+#include "file_util.h"
 
 #include "wtap-int.h"
 #include "file_wrappers.h"
@@ -179,7 +173,7 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
                        return NULL;
                }
        } else {
-               if (stat(filename, &statb) < 0) {
+               if (eth_stat(filename, &statb) < 0) {
                        *err = errno;
                        return NULL;
                }
@@ -233,11 +227,6 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
                return NULL;
        }
 
-/* Win32 needs the O_BINARY flag for open() */
-#ifndef O_BINARY
-#define O_BINARY       0
-#endif
-
        /* Open the file */
        errno = WTAP_ERR_CANT_OPEN;
        if (use_stdin) {
@@ -246,12 +235,12 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
                 * an fclose or gzclose of wth->fh closing the standard
                 * input of the process.
                 */
-               wth->fd = dup(0);
+               wth->fd = eth_dup(0);
 #ifdef _WIN32
                _setmode(wth->fd, O_BINARY);
 #endif
        } else
-               wth->fd = open(filename, O_RDONLY|O_BINARY);
+               wth->fd = eth_open(filename, O_RDONLY|O_BINARY, 0000 /* no creation so don't matter */);
        if (wth->fd < 0) {
                *err = errno;
                g_free(wth);
@@ -259,13 +248,13 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
        }
        if (!(wth->fh = filed_open(wth->fd, "rb"))) {
                *err = errno;
-               close(wth->fd);
+               eth_close(wth->fd);
                g_free(wth);
                return NULL;
        }
 
        if (do_random) {
-               if (!(wth->random_fh = file_open(filename, "rb"))) {
+               if (!(wth->random_fh = file_open(filename, O_RDONLY|O_BINARY, "rb"))) {
                        *err = errno;
                        file_close(wth->fh);
                        g_free(wth);
@@ -631,7 +620,7 @@ wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap,
                   opening it. */
                if (wdh->fh != stdout) {
                        wtap_dump_file_close(wdh);
-                       unlink(filename);
+                       eth_unlink(filename);
                }
                g_free(wdh);
                return NULL;
@@ -820,7 +809,7 @@ static FILE *wtap_dump_file_open(wtap_dumper *wdh, const char *filename)
        } else 
 #endif
        {
-               return fopen(filename, "wb");
+               return eth_fopen(filename, "wb");
        }
 }
 
diff --git a/wiretap/file_util.h b/wiretap/file_util.h
new file mode 100644 (file)
index 0000000..25509a9
--- /dev/null
@@ -0,0 +1,127 @@
+/* file_util.h\r
+ * File utility definitions\r
+ *\r
+ * $Id: file_util.h 15244 2005-08-06 14:03:14Z jmayer $\r
+ *\r
+ * Ethereal - Network traffic analyzer\r
+ * By Gerald Combs <gerald@ethereal.com>\r
+ * Copyright 1998 Gerald Combs\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
+ */\r
+\r
+#ifndef __FILE_UTIL_H__\r
+#define __FILE_UTIL_H__\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif /* __cplusplus */\r
+\r
+#include <glib.h>\r
+#include <glib/gstdio.h>       /* XXX - is this file GLib 2.6 only? */\r
+\r
+#ifdef _WIN32\r
+#include <io.h>\r
+#endif\r
+\r
+#ifdef HAVE_SYS_STAT_H\r
+#include <sys/stat.h>\r
+#endif\r
+\r
+\r
+/* Since GLib2.6, wrappers were added around functions which provides filenames to library functions, \r
+       like open() does. */\r
+#if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 6)\r
+\r
+/* GLib2.6 or above, using new wrapper functions */\r
+#define eth_mkstemp g_mkstemp\r
+#define eth_open       g_open\r
+#define eth_rename     g_rename\r
+#define eth_mkdir      g_mkdir\r
+#define eth_stat       g_stat\r
+#define eth_unlink     g_unlink\r
+#define eth_remove     g_remove\r
+#define eth_fopen      g_fopen\r
+#define eth_freopen    g_freopen\r
+\r
+#else  /* GLIB_MAJOR_VERSION */\r
+\r
+/* GLib 2.4 or below, using "old school" functions */\r
+#ifdef _WIN32\r
+#define eth_open       _open\r
+#define eth_stat       _stat\r
+#define eth_unlink     _unlink\r
+#else\r
+#define eth_open       open\r
+#define eth_stat       stat\r
+#define eth_unlink     unlink\r
+#endif\r
+\r
+#include "mkstemp.h"\r
+#define eth_mkstemp mkstemp\r
+#define eth_rename     rename\r
+#define eth_mkdir      mkdir\r
+#define eth_remove     remove\r
+#define eth_fopen      fopen\r
+#define eth_freopen    freopen\r
+\r
+#endif /* GLIB_MAJOR_VERSION */\r
+\r
+\r
+/* some common differences between UNIX and WIN32 */\r
+#ifdef _WIN32\r
+/* the Win32 API prepends underscores for whatever reasons */\r
+#define eth_read  _read\r
+#define eth_write _write\r
+#define eth_close _close\r
+#define eth_dup   _dup\r
+#define eth_lseek _lseek\r
+#else\r
+#define eth_read  read\r
+#define eth_write write\r
+#define eth_close close\r
+#define eth_dup   dup\r
+#define eth_lseek lseek\r
+#define O_BINARY       0               /* Win32 needs the O_BINARY flag for open() */\r
+#endif\r
+\r
+#if GLIB_MAJOR_VERSION >= 2\r
+#define ETH_DIR                                                        GDir\r
+#define ETH_DIRENT                                             const char\r
+#define eth_dir_open                                   g_dir_open\r
+#define eth_dir_read_name                              g_dir_read_name\r
+#define eth_dir_get_name(dirent)               dirent\r
+#define eth_dir_rewind                                 g_dir_rewind\r
+#define eth_dir_close                                  g_dir_close\r
+#else\r
+#define ETH_DIR                                                        DIR\r
+#define ETH_DIRENT                                             struct dirent\r
+#define eth_dir_open(name,flags,error) opendir(name)\r
+#define eth_dir_read_name                              readdir\r
+#define eth_dir_get_name(dirent)               (gchar *)file->d_name\r
+#define eth_dir_rewind                                 g_dir_rewind\r
+#define eth_dir_close                                  close_dir\r
+#endif\r
+\r
+/* XXX - remove include "dirent.h" */\r
+/* XXX - remove include "direct.h" */\r
+/* XXX - remove include "sys/stat.h" */\r
+/* XXX - remove O_BINARY */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif /* __cplusplus */\r
+\r
+#endif /* __FILE_UTIL_H__ */\r
index eda7717a3c431cf10e258d59a9fd066a743a89c3..1b02038577b7e3170fee22becf48371560757936 100644 (file)
 #include <stdio.h>
 #include "wtap-int.h"
 #include "file_wrappers.h"
+#include "file_util.h"
+
+FILE_T
+file_open(const char *path, int oflag, const char *mode)
+{
+       int fd;
+       FILE_T ft;
+
+       /* open file and do correct filename conversions */
+       if( (fd = eth_open( path, oflag, 0000 /* no creation so don't matter */)) == NULL )
+      return NULL;
+
+       /* open zlib file handle */
+       ft = gzdopen(fd, mode );
+       if(ft == NULL) {
+               eth_close(fd);
+               return NULL;
+       }
+
+       return ft;
+}
+
 
 #ifdef HAVE_LIBZ
 long
index ef88fd08965b42a739092ebb4053853d73236461..3d9af8bdcf03f8f570fb50c78782d37fbda822ca 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifdef HAVE_LIBZ
 
-#define file_open gzopen
+extern FILE_T file_open(const char *path, int oflag, const char *mode);
 #define filed_open gzdopen
 extern long file_seek(void *stream, long offset, int whence, int *err);
 #define file_read(buf, bsize, count, file) gzread((file),(buf),((count)*(bsize)))
@@ -39,7 +39,7 @@ extern int file_error(void *fh);
 #define file_eof gzeof
 
 #else /* No zLib */
-#define file_open fopen
+#define file_open(path, oflag, mode) fopen(path, mode)
 #define filed_open fdopen
 extern long file_seek(void *stream, long offset, int whence, int *err);
 #define file_read fread
index a80327697c248b0c362fbfa98725d63bdec1ff53..4c9a67e525182637749b84e1b14ba00f74e94f06 100644 (file)
@@ -551,7 +551,7 @@ int k12_open(wtap *wth, int *err, gchar **err_info _U_) {
 #ifdef DEBUG_K12
     gchar* env_level = getenv("K12_DEBUG_LEVEL");
     env_file = getenv("K12_DEBUG_FILENAME");
-    if ( env_file ) dbg_out = fopen(env_file,"w");
+    if ( env_file ) dbg_out = eth_fopen(env_file,"w");
     else dbg_out = stderr;
     if ( env_level ) debug_level = strtoul(env_level,NULL,10);
     k12_dbg(1,"k12_open: ENTER debug_level=%u",debug_level);
index 151d294d31bfeb2bb5ca7bf9d2563d8dff6bff45..c79faf51f06d833035f343c50c539f89e1f56aa8 100644 (file)
 #include <sys/types.h>
 #endif
 
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
 #include "wtap-int.h"
 #include "wtap.h"
 
 #include "file_wrappers.h"
+#include "file_util.h"
 #include "buffer.h"
 
 /*
@@ -520,7 +513,7 @@ wtap_read_so_far(wtap *wth, int *err)
 {
        off_t file_pos;
 
-       file_pos = lseek(wth->fd, 0, SEEK_CUR);
+       file_pos = eth_lseek(wth->fd, 0, SEEK_CUR);
        if (file_pos == -1) {
                if (err != NULL)
                        *err = errno;