diff options
Diffstat (limited to 'epan')
-rw-r--r-- | epan/addr_resolv.c | 7 | ||||
-rw-r--r-- | epan/column.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-kerberos.c | 2 | ||||
-rw-r--r-- | epan/filesystem.c | 35 | ||||
-rw-r--r-- | epan/plugins.c | 48 | ||||
-rw-r--r-- | epan/prefs.c | 11 | ||||
-rw-r--r-- | epan/sha1.c | 2 |
7 files changed, 41 insertions, 68 deletions
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 ); |