aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--capture.c7
-rw-r--r--capture_loop.c18
-rw-r--r--capture_sync.c30
-rw-r--r--color_filters.c11
-rw-r--r--config.h.win323
-rw-r--r--disabled_protos.c17
-rw-r--r--epan/addr_resolv.c7
-rw-r--r--epan/column.c4
-rw-r--r--epan/dissectors/packet-kerberos.c2
-rw-r--r--epan/filesystem.c35
-rw-r--r--epan/plugins.c48
-rw-r--r--epan/prefs.c11
-rw-r--r--epan/sha1.c2
-rw-r--r--file.c45
-rw-r--r--fileset.c42
-rw-r--r--filters.c21
-rw-r--r--gtk/capture_if_dlg.c4
-rw-r--r--gtk/drag_and_drop.c4
-rw-r--r--gtk/file_dlg.c4
-rw-r--r--gtk/fileset_dlg.c4
-rw-r--r--gtk/filter_dlg.h1
-rw-r--r--gtk/follow_dlg.c16
-rw-r--r--gtk/graph_analysis.c5
-rw-r--r--gtk/gui_utils.c4
-rw-r--r--gtk/help_dlg.c3
-rw-r--r--gtk/main.c11
-rw-r--r--gtk/print_dlg.c4
-rw-r--r--gtk/print_mswin.c3
-rw-r--r--gtk/proto_draw.c18
-rw-r--r--gtk/recent.c7
-rw-r--r--gtk/rtp_analysis.c149
-rw-r--r--gtk/rtp_stream.c3
-rw-r--r--gtk/text_page.c3
-rw-r--r--mergecap.c12
-rw-r--r--mkstemp.c8
-rw-r--r--pcap-util-unix.c4
-rw-r--r--plugins/asn1/packet-asn1.c7
-rw-r--r--plugins/mate/mate_util.c3
-rw-r--r--print.c3
-rw-r--r--ringbuffer.c21
-rw-r--r--tethereal.c10
-rw-r--r--util.c19
-rw-r--r--wiretap/ascend.c5
-rw-r--r--wiretap/config.h.win323
-rw-r--r--wiretap/file_access.c27
-rw-r--r--wiretap/file_util.h127
-rw-r--r--wiretap/file_wrappers.c22
-rw-r--r--wiretap/file_wrappers.h4
-rw-r--r--wiretap/k12.c2
-rw-r--r--wiretap/wtap.c11
50 files changed, 412 insertions, 422 deletions
diff --git a/capture.c b/capture.c
index 624975e7d3..762ae3838c 100644
--- a/capture.c
+++ b/capture.c
@@ -40,10 +40,6 @@
#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)) {
diff --git a/capture_loop.c b/capture_loop.c
index 5853043d7f..1eae074d23 100644
--- a/capture_loop.c
+++ b/capture_loop.c
@@ -87,6 +87,7 @@
#include "util.h"
#include "alert_box.h"
#include "log.h"
+#include "file_util.h"
#include <epan/dissectors/packet-ap1394.h>
@@ -107,11 +108,6 @@
#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;
diff --git a/capture_sync.c b/capture_sync.c
index 9e02b26c44..124e6ad446 100644
--- a/capture_sync.c
+++ b/capture_sync.c
@@ -87,21 +87,13 @@
#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.
diff --git a/color_filters.c b/color_filters.c
index 8ee7e50752..8d7fcbb4c7 100644
--- a/color_filters.c
+++ b/color_filters.c
@@ -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));
diff --git a/config.h.win32 b/config.h.win32
index 492ae8bc51..9bda22e3bf 100644
--- a/config.h.win32
+++ b/config.h.win32
@@ -200,7 +200,6 @@
#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
@@ -208,8 +207,6 @@
#define snprintf _snprintf
#define strcasecmp stricmp
#define strncasecmp strnicmp
-#define open _open
-#define close _close
#define popen _popen
#define pclose _pclose
diff --git a/disabled_protos.c b/disabled_protos.c
index d8fbdf11b8..4ce7e73c12 100644
--- a/disabled_protos.c
+++ b/disabled_protos.c
@@ -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;
}
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c
index 1d257f091a..9d43d04caa 100644
--- a/epan/addr_resolv.c
+++ b/epan/addr_resolv.c
@@ -117,6 +117,7 @@
#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) {
diff --git a/epan/column.c b/epan/column.c
index 90dae76709..17993bd7df 100644
--- a/epan/column.c
+++ b/epan/column.c
@@ -35,10 +35,6 @@
#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>
diff --git a/epan/dissectors/packet-kerberos.c b/epan/dissectors/packet-kerberos.c
index e1b339c0ca..ea922d37a5 100644
--- a/epan/dissectors/packet-kerberos.c
+++ b/epan/dissectors/packet-kerberos.c
@@ -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) {
diff --git a/epan/filesystem.c b/epan/filesystem.c
index d042e426c6..b77c7d0793 100644
--- a/epan/filesystem.c
+++ b/epan/filesystem.c
@@ -37,23 +37,16 @@
#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 {
diff --git a/epan/plugins.c b/epan/plugins.c
index 9d606376b8..806488fd7d 100644
--- a/epan/plugins.c
+++ b/epan/plugins.c
@@ -44,15 +44,12 @@
#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
}
diff --git a/epan/prefs.c b/epan/prefs.c
index 09151b04a3..70711e7609 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -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;
}
diff --git a/epan/sha1.c b/epan/sha1.c
index 9b8fef4576..52e95c132e 100644
--- a/epan/sha1.c
+++ b/epan/sha1.c
@@ -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 5a9ef277b4..b2cd598325 100644
--- a/file.c
+++ b/file.c
@@ -32,10 +32,6 @@
#include <time.h>
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -77,12 +73,9 @@
#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;
}
diff --git a/fileset.c b/fileset.c
index b7d71d5471..b023d2b146 100644
--- a/fileset.c
+++ b/fileset.c
@@ -30,10 +30,6 @@
#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 */);
diff --git a/filters.c b/filters.c
index f24f1d30c8..cdecc51691 100644
--- 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;
}
diff --git a/gtk/capture_if_dlg.c b/gtk/capture_if_dlg.c
index b1fa9b14ef..cfac902365 100644
--- a/gtk/capture_if_dlg.c
+++ b/gtk/capture_if_dlg.c
@@ -28,10 +28,6 @@
#ifdef HAVE_LIBPCAP
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
diff --git a/gtk/drag_and_drop.c b/gtk/drag_and_drop.c
index ca282f4422..d868de3e61 100644
--- a/gtk/drag_and_drop.c
+++ b/gtk/drag_and_drop.c
@@ -26,10 +26,6 @@
# include "config.h"
#endif
-#ifdef HAVE_IO_H
-#include <io.h> /* open/close on win32 */
-#endif
-
#ifdef HAVE_LIBPCAP
#include <pcap.h>
#endif
diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c
index a4735722d2..3d60e7fd94 100644
--- a/gtk/file_dlg.c
+++ b/gtk/file_dlg.c
@@ -63,10 +63,6 @@
#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);
diff --git a/gtk/fileset_dlg.c b/gtk/fileset_dlg.c
index 4ee09596c3..1cb519604b 100644
--- a/gtk/fileset_dlg.c
+++ b/gtk/fileset_dlg.c
@@ -28,10 +28,6 @@
#include <string.h>
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
diff --git a/gtk/filter_dlg.h b/gtk/filter_dlg.h
index f6049c5b6c..2d1417e090 100644
--- a/gtk/filter_dlg.h
+++ b/gtk/filter_dlg.h
@@ -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
*/
diff --git a/gtk/follow_dlg.c b/gtk/follow_dlg.c
index 8765363952..23535c1a05 100644
--- a/gtk/follow_dlg.c
+++ b/gtk/follow_dlg.c
@@ -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);
diff --git a/gtk/graph_analysis.c b/gtk/graph_analysis.c
index 624debaa7b..ff4716a56f 100644
--- a/gtk/graph_analysis.c
+++ b/gtk/graph_analysis.c
@@ -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,
diff --git a/gtk/gui_utils.c b/gtk/gui_utils.c
index 725dcfcb08..0f927c0cd3 100644
--- a/gtk/gui_utils.c
+++ b/gtk/gui_utils.c
@@ -34,13 +34,11 @@
#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>
diff --git a/gtk/help_dlg.c b/gtk/help_dlg.c
index 3d4884afd3..464b998334 100644
--- a/gtk/help_dlg.c
+++ b/gtk/help_dlg.c
@@ -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));
diff --git a/gtk/main.c b/gtk/main.c
index 584e9292a9..67757b674c 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -39,10 +39,6 @@
#include <unistd.h>
#endif
-#ifdef HAVE_IO_H
-#include <io.h> /* open/close on win32 */
-#endif
-
#ifdef NEED_STRERROR_H
#include "strerror.h"
#endif
@@ -140,6 +136,7 @@
#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;
diff --git a/gtk/print_dlg.c b/gtk/print_dlg.c
index 61caec2883..0478bbc525 100644
--- a/gtk/print_dlg.c
+++ b/gtk/print_dlg.c
@@ -43,12 +43,12 @@
#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
}
diff --git a/gtk/print_mswin.c b/gtk/print_mswin.c
index f61bd7c503..8e772628fa 100644
--- a/gtk/print_mswin.c
+++ b/gtk/print_mswin.c
@@ -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" );
diff --git a/gtk/proto_draw.c b/gtk/proto_draw.c
index 8cb6bf513d..0d0c8a47f9 100644
--- a/gtk/proto_draw.c
+++ b/gtk/proto_draw.c
@@ -31,10 +31,6 @@
#include <ctype.h>
-#ifdef HAVE_IO_H
-#include <io.h> /* open/close on win32 */
-#endif
-
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
@@ -73,11 +69,7 @@
#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;
}
diff --git a/gtk/recent.c b/gtk/recent.c
index 85e505cdb3..7e7c09ef6d 100644
--- a/gtk/recent.c
+++ b/gtk/recent.c
@@ -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 */
diff --git a/gtk/rtp_analysis.c b/gtk/rtp_analysis.c
index 4ec79d7dd5..4489869b0f 100644
--- a/gtk/rtp_analysis.c
+++ b/gtk/rtp_analysis.c
@@ -91,14 +91,7 @@
#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;
diff --git a/gtk/rtp_stream.c b/gtk/rtp_stream.c
index 7d93a3b1a1..75b82fc65f 100644
--- a/gtk/rtp_stream.c
+++ b/gtk/rtp_stream.c
@@ -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;
diff --git a/gtk/text_page.c b/gtk/text_page.c
index eb4d415682..a51c8a10d8 100644
--- a/gtk/text_page.c
+++ b/gtk/text_page.c
@@ -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));
diff --git a/mergecap.c b/mergecap.c
index 9136e64930..a74039cfe2 100644
--- a/mergecap.c
+++ b/mergecap.c
@@ -33,20 +33,12 @@
#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));
diff --git a/mkstemp.c b/mkstemp.c
index 4d1ffcde1e..dc847f68cc 100644
--- a/mkstemp.c
+++ b/mkstemp.c
@@ -25,10 +25,6 @@
#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;
}
diff --git a/pcap-util-unix.c b/pcap-util-unix.c
index 9f4a6798d7..c377e91657 100644
--- a/pcap-util-unix.c
+++ b/pcap-util-unix.c
@@ -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 */
diff --git a/plugins/asn1/packet-asn1.c b/plugins/asn1/packet-asn1.c
index 090e62e654..43135fc5e4 100644
--- a/plugins/asn1/packet-asn1.c
+++ b/plugins/asn1/packet-asn1.c
@@ -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;
diff --git a/plugins/mate/mate_util.c b/plugins/mate/mate_util.c
index fa3f16e5b9..89349317e4 100644
--- a/plugins/mate/mate_util.c
+++ b/plugins/mate/mate_util.c
@@ -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 63adb1f9c6..892438caa4 100644
--- 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");
diff --git a/ringbuffer.c b/ringbuffer.c
index 4f1d5fe0da..0c1e7f4b75 100644
--- a/ringbuffer.c
+++ b/ringbuffer.c
@@ -48,10 +48,6 @@
#ifdef HAVE_LIBPCAP
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
@@ -67,11 +63,8 @@
#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);
}
}
}
diff --git a/tethereal.c b/tethereal.c
index b78250a88a..cc2fd6cf22 100644
--- a/tethereal.c
+++ b/tethereal.c
@@ -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 f6ed670b13..6b6298c70f 100644
--- a/util.c
+++ b/util.c
@@ -37,20 +37,7 @@
#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;
}
diff --git a/wiretap/ascend.c b/wiretap/ascend.c
index 2ff4794a01..85694f6732 100644
--- a/wiretap/ascend.c
+++ b/wiretap/ascend.c
@@ -28,13 +28,10 @@
#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
diff --git a/wiretap/config.h.win32 b/wiretap/config.h.win32
index 2ed6192394..6d00ecba08 100644
--- a/wiretap/config.h.win32
+++ b/wiretap/config.h.win32
@@ -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/ */
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index 08b4d72384..abc147afaf 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -32,19 +32,13 @@
#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
index 0000000000..25509a9d33
--- /dev/null
+++ b/wiretap/file_util.h
@@ -0,0 +1,127 @@
+/* file_util.h
+ * File utility definitions
+ *
+ * $Id: file_util.h 15244 2005-08-06 14:03:14Z jmayer $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __FILE_UTIL_H__
+#define __FILE_UTIL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <glib.h>
+#include <glib/gstdio.h> /* XXX - is this file GLib 2.6 only? */
+
+#ifdef _WIN32
+#include <io.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+
+/* Since GLib2.6, wrappers were added around functions which provides filenames to library functions,
+ like open() does. */
+#if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 6)
+
+/* GLib2.6 or above, using new wrapper functions */
+#define eth_mkstemp g_mkstemp
+#define eth_open g_open
+#define eth_rename g_rename
+#define eth_mkdir g_mkdir
+#define eth_stat g_stat
+#define eth_unlink g_unlink
+#define eth_remove g_remove
+#define eth_fopen g_fopen
+#define eth_freopen g_freopen
+
+#else /* GLIB_MAJOR_VERSION */
+
+/* GLib 2.4 or below, using "old school" functions */
+#ifdef _WIN32
+#define eth_open _open
+#define eth_stat _stat
+#define eth_unlink _unlink
+#else
+#define eth_open open
+#define eth_stat stat
+#define eth_unlink unlink
+#endif
+
+#include "mkstemp.h"
+#define eth_mkstemp mkstemp
+#define eth_rename rename
+#define eth_mkdir mkdir
+#define eth_remove remove
+#define eth_fopen fopen
+#define eth_freopen freopen
+
+#endif /* GLIB_MAJOR_VERSION */
+
+
+/* some common differences between UNIX and WIN32 */
+#ifdef _WIN32
+/* the Win32 API prepends underscores for whatever reasons */
+#define eth_read _read
+#define eth_write _write
+#define eth_close _close
+#define eth_dup _dup
+#define eth_lseek _lseek
+#else
+#define eth_read read
+#define eth_write write
+#define eth_close close
+#define eth_dup dup
+#define eth_lseek lseek
+#define O_BINARY 0 /* Win32 needs the O_BINARY flag for open() */
+#endif
+
+#if GLIB_MAJOR_VERSION >= 2
+#define ETH_DIR GDir
+#define ETH_DIRENT const char
+#define eth_dir_open g_dir_open
+#define eth_dir_read_name g_dir_read_name
+#define eth_dir_get_name(dirent) dirent
+#define eth_dir_rewind g_dir_rewind
+#define eth_dir_close g_dir_close
+#else
+#define ETH_DIR DIR
+#define ETH_DIRENT struct dirent
+#define eth_dir_open(name,flags,error) opendir(name)
+#define eth_dir_read_name readdir
+#define eth_dir_get_name(dirent) (gchar *)file->d_name
+#define eth_dir_rewind g_dir_rewind
+#define eth_dir_close close_dir
+#endif
+
+/* XXX - remove include "dirent.h" */
+/* XXX - remove include "direct.h" */
+/* XXX - remove include "sys/stat.h" */
+/* XXX - remove O_BINARY */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __FILE_UTIL_H__ */
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c
index eda7717a3c..1b02038577 100644
--- a/wiretap/file_wrappers.c
+++ b/wiretap/file_wrappers.c
@@ -101,6 +101,28 @@
#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
diff --git a/wiretap/file_wrappers.h b/wiretap/file_wrappers.h
index ef88fd0896..3d9af8bdcf 100644
--- a/wiretap/file_wrappers.h
+++ b/wiretap/file_wrappers.h
@@ -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
diff --git a/wiretap/k12.c b/wiretap/k12.c
index a80327697c..4c9a67e525 100644
--- a/wiretap/k12.c
+++ b/wiretap/k12.c
@@ -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);
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 151d294d31..c79faf51f0 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -31,22 +31,15 @@
#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;