#include <fcntl.h>
#endif
-#ifdef HAVE_IO_H
-# include <io.h>
-#endif
-
#include <signal.h>
#include <errno.h>
#include "capture-wpcap.h"
#endif
#include "ui_util.h"
+#include "file_util.h"
#include "log.h"
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)) {
#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
-
/*
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 {
}
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 "
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;
}
/* 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
} 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;
#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);
/* 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;
}
}
/* 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. */
* -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));
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;
}
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;
/* 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.
#include <string.h>
#include <epan/filesystem.h>
+#include "file_util.h"
#include <epan/packet.h>
#include "color.h"
/* 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,
/* 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,
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));
}
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));
{
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));
#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
#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"
/* 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);
/* 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) {
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);
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;
}
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;
}
#include "ipv6-utils.h"
#include "addr_resolv.h"
#include "filesystem.h"
+#include "file_util.h"
#include <epan/prefs.h>
#include <epan/emem.h>
if (eth_p)
rewind(eth_p);
else
- eth_p = fopen(path, "r");
+ eth_p = eth_fopen(path, "r");
}
static void end_ethent(void)
if (ipxnet_p)
rewind(ipxnet_p);
else
- ipxnet_p = fopen(path, "r");
+ ipxnet_p = eth_fopen(path, "r");
}
static void end_ipxnetent(void)
* 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) {
#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>
}
}
- 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) {
#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
{
struct stat statb;
- if (stat(path, &statb) < 0)
+ if (eth_stat(path, &statb) < 0)
return errno;
if (S_ISDIR(statb.st_mode))
{
struct stat statb;
- if (stat(path, &statb) < 0)
+ if (eth_stat(path, &statb) < 0)
return errno;
if (S_ISFIFO(statb.st_mode))
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
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 {
/*
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
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.
*/
gboolean
deletefile(const char *path)
{
- return unlink(path) == 0;
+ return eth_unlink(path) == 0;
}
/*
* 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 {
*/
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 {
#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 */
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 */
*/
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,
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
}
#include <epan/proto.h>
#include <epan/column.h>
#include "print.h"
+#include "file_util.h"
#include <epan/prefs-int.h>
* 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");
}
/*
/* 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.
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;
}
}
else
{
- if( ! ( f = fopen( argv[1], "rb" ) ) )
+ if( ! ( f = eth_fopen( argv[1], "rb" ) ) )
{
perror( "fopen" );
return( 1 );
#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;
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;
}
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 {
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,
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 */
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 */
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 */
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;
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;
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;
}
}
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;
}
#include <unistd.h>
#endif
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <glib.h>
+#include "file_util.h"
#include "globals.h"
#include <epan/filesystem.h>
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 */
set.entries = g_list_append(set.entries, entry);
}
- close(fh);
+ eth_close(fh);
}
g_free(path);
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;
/* 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 */);
#include <epan/filesystem.h>
#include "filters.h"
+#include "file_util.h"
/*
* Old filter file name.
/* 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?
*/
*/
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?
*/
/*
* 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.
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);
*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;
}
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;
}
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;
}
#ifdef HAVE_LIBPCAP
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
# include "config.h"
#endif
-#ifdef HAVE_IO_H
-#include <io.h> /* open/close on win32 */
-#endif
-
#ifdef HAVE_LIBPCAP
#include <pcap.h>
#endif
#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);
#include <string.h>
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
* "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
*/
#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>
#include "isprint.h"
+#include "file_util.h"
#include "color.h"
#include "colors.h"
#include "file.h"
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;
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,
print_mswin(print_dest);
/* trash temp file */
- remove(print_dest);
+ eth_remove(print_dest);
}
#endif
return;
#ifdef _WIN32
if (win_printer) {
/* trash temp file */
- remove(print_dest);
+ eth_remove(print_dest);
}
#endif
}
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);
#include "compat_macros.h"
#include "../color.h"
#include "epan/filesystem.h"
+#include "file_util.h"
#include <string.h>
FILE *of;
- of = fopen(user_data->dlg.save_file,"w");
+ of = eth_fopen(user_data->dlg.save_file,"w");
if (of==NULL){
return FALSE;
}
/* 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,
#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>
#include "dlg_utils.h"
#include "simple_dialog.h"
#include "webbrowser.h"
+#include "file_util.h"
#define HELP_DIR "help"
}
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));
#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"
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;
#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 */
print_mswin(args->file);
/* trash temp file */
- remove(args->file);
+ eth_remove(args->file);
}
#endif
}
#endif
#include "print_mswin.h"
+#include "file_util.h"
/*
Some thoughts about a GTK win32 printer dialog:
SetMapMode (hdc, MM_TEXT);
- fh1 = fopen( file_name, "r" );
+ fh1 = eth_fopen( file_name, "r" );
if( !fh1 )
perror( "open failed on input 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
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;
}
#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"
}
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));
/* 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);
/* 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 */
#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"
/****************************************************************************/
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;
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)
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;
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;
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;
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;
}
{
/* 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) {
*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;
}
*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;
}
}
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;
}
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;
}
}
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;
}
}
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;
}
/*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;
#include "alert_box.h"
#include "simple_dialog.h"
+#include "file_util.h"
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
{
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;
#include "compat_macros.h"
#include "simple_dialog.h"
#include "font_utils.h"
+#include "file_util.h"
#define TEXT_KEY "txt_key"
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));
#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)
{
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));
#include <errno.h>
#include <stdio.h>
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <glib.h>
-#include "mkstemp.h"
+#include "file_util.h"
#ifndef __set_errno
#define __set_errno(x) errno=(x)
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;
}
#endif
g_free(ifc.ifc_buf);
- close(sock);
+ eth_close(sock);
if (il == NULL) {
/*
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 */
#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>
(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);
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
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;
#include "mate.h"
#include "mate_util.h"
+#include "file_util.h"
/***************************************************************************
* dbg_print
state = START;
- if (( fp = fopen(filename,"r") )) {
+ if (( fp = eth_fopen(filename,"r") )) {
while(( c = (gchar) fgetc(fp) )){
if ( feof(fp) ) {
#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>
/* Open the file or command for output */
if (to_file)
- fh = fopen(dest, "w");
+ fh = eth_fopen(dest, "w");
else
fh = popen(dest, "w");
#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 {
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);
}
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;
/* 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;
/* 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;
}
/* 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);
}
}
}
#ifndef _WIN32
if (ld.from_pipe && pipe_fd >= 0)
- close(pipe_fd);
+ eth_close(pipe_fd);
else
#endif
{
#ifndef _WIN32
if (ld.from_pipe) {
if (pipe_fd >= 0)
- close(pipe_fd);
+ eth_close(pipe_fd);
} else
#endif
{
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 {
}
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 "
error:
ldat->pipe_err = PIPERR;
- close(fd);
+ eth_close(fd);
return -1;
}
#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>
{
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) {
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;
}
#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
#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/ */
#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"
return NULL;
}
} else {
- if (stat(filename, &statb) < 0) {
+ if (eth_stat(filename, &statb) < 0) {
*err = errno;
return NULL;
}
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) {
* 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);
}
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);
opening it. */
if (wdh->fh != stdout) {
wtap_dump_file_close(wdh);
- unlink(filename);
+ eth_unlink(filename);
}
g_free(wdh);
return NULL;
} else
#endif
{
- return fopen(filename, "wb");
+ return eth_fopen(filename, "wb");
}
}
--- /dev/null
+/* 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
#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
#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)))
#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
#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);
#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"
/*
{
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;