aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-07-31 04:53:40 +0000
committerGuy Harris <guy@alum.mit.edu>2000-07-31 04:53:40 +0000
commit3d20d56999e06c024135fcbc49e894b7de1f8991 (patch)
treedc6021804e6b3c195c924db6b636d48ef0724abb /util.c
parent3b56e370433391bb050fae26a0ba1495bfa23591 (diff)
Add a routine to check whether a file is a directory or not.
To test whether a file the user selected to be opened from the file selection box is really a directory (so that we can point the file selection box at it, rather than trying to open the directory as a capture file, which wouldn't work), use the routine in question. To make the GTK+ file selection box start out in the last directory from which we opened a file, use "gtk_file_selection_complete()", rather than "chdir()"ing to that directory. Those changes keep us from "chdir()"ing all over the place; that way, if Ethereal dumps core, the core dump shows up in the directory from which it was run, rather than in the directory from which you last opened or into which you last saved a file. svn path=/trunk/; revision=2190
Diffstat (limited to 'util.c')
-rw-r--r--util.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/util.c b/util.c
index f49053c6bb..e6a2ce0611 100644
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
/* util.c
* Utility routines
*
- * $Id: util.c,v 1.39 2000/03/21 06:51:59 guy Exp $
+ * $Id: util.c,v 1.40 2000/07/31 04:53:31 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -93,6 +93,51 @@ typedef int mode_t; /* for win32 */
#endif
/*
+ * Given a pathname, return:
+ *
+ * the errno, if an attempt to "stat()" the file fails;
+ *
+ * EISDIR, if the attempt succeeded and the file turned out
+ * to be a directory;
+ *
+ * 0, if the attempt succeeded and the file turned out not
+ * to be a directory.
+ */
+
+/*
+ * Visual C++ on Win32 systems doesn't define these. (Old UNIX systems don't
+ * define them either.)
+ *
+ * Visual C++ on Win32 systems doesn't define S_IFIFO, it defines _S_IFIFO.
+ */
+#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
+
+int
+test_for_directory(const char *path)
+{
+ struct stat statb;
+
+ if (stat(path, &statb) < 0)
+ return errno;
+
+ if (S_ISDIR(statb.st_mode))
+ return EISDIR;
+ else
+ return 0;
+}
+
+/*
* Given a pathname, return a pointer to the last pathname separator
* character in the pathname, or NULL if the pathname contains no
* separators.