aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/file.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-07-31 04:19:54 +0000
committerGuy Harris <guy@alum.mit.edu>2000-07-31 04:19:54 +0000
commita459c2bea7c239ede03f03dd817d71d5857c8bf8 (patch)
tree0fbc64de92ec4c6acb3a23b68ef7708280a87efd /wiretap/file.c
parent0b406c38ba81e8e76af239ecd15ac8b31a198639 (diff)
downloadwireshark-a459c2bea7c239ede03f03dd817d71d5857c8bf8.tar.gz
wireshark-a459c2bea7c239ede03f03dd817d71d5857c8bf8.tar.bz2
wireshark-a459c2bea7c239ede03f03dd817d71d5857c8bf8.zip
It appears that, at least with Visual C++ 6.0, the "stat()" supplied in
the C run-time library sets "statb.st_mode" appropriately, at least for plain files and directories; it just doesn't offer the POSIX "S_ISxxx()" macros to test the file type. If those macros aren't defined (which might also be the case on really ancient UNIX systems), define them appropriately, and use them even on Win32 systems, so that we can properly report attempts by a user to read from a directory on Win32, just as we do on UNIX. svn path=/trunk/; revision=2188
Diffstat (limited to 'wiretap/file.c')
-rw-r--r--wiretap/file.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/wiretap/file.c b/wiretap/file.c
index c95eee5cef..d2bbfd91d5 100644
--- a/wiretap/file.c
+++ b/wiretap/file.c
@@ -1,6 +1,6 @@
/* file.c
*
- * $Id: file.c,v 1.56 2000/07/26 06:04:32 guy Exp $
+ * $Id: file.c,v 1.57 2000/07/31 04:19:54 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -96,6 +96,8 @@ static int (*open_routines[])(wtap *, int *) = {
i4btrace_open,
};
+#define N_FILE_TYPES (sizeof open_routines / sizeof open_routines[0])
+
int wtap_def_seek_read(wtap *wth, int seek_off,
union wtap_pseudo_header *pseudo_header, guint8 *pd, int len)
{
@@ -104,7 +106,18 @@ int wtap_def_seek_read(wtap *wth, int seek_off,
return file_read(pd, sizeof(guint8), len, wth->random_fh);
}
-#define N_FILE_TYPES (sizeof open_routines / sizeof open_routines[0])
+#ifndef S_ISREG
+#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+#ifndef S_IFIFO
+#define S_IFIFO _S_IFIFO
+#endif
+#ifndef S_ISFIFO
+#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
+#endif
+#ifndef S_ISDIR
+#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
/* Opens a file and prepares a wtap struct.
If "do_random" is TRUE, it opens the file twice; the second open
@@ -124,7 +137,6 @@ wtap* wtap_open_offline(const char *filename, int *err, gboolean do_random)
*err = errno;
return NULL;
}
-#ifndef WIN32
if (! S_ISREG(statb.st_mode) && ! S_ISFIFO(statb.st_mode)) {
if (S_ISDIR(statb.st_mode))
*err = EISDIR;
@@ -132,7 +144,6 @@ wtap* wtap_open_offline(const char *filename, int *err, gboolean do_random)
*err = WTAP_ERR_NOT_REGULAR_FILE;
return NULL;
}
-#endif
errno = ENOMEM;
wth = g_malloc(sizeof(wtap));