summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-01-25 04:31:17 +0000
committerGuy Harris <guy@alum.mit.edu>2000-01-25 04:31:17 +0000
commit8e68faf22fb36bf7c5142f5ff50f63213392fc64 (patch)
tree80c7dd86a404b6700b2b6a916ae3c71dd87c6fa2
parentb7a9eca9ba9b52243d1e6f214115a93164d3ea66 (diff)
downloadwireshark-8e68faf22fb36bf7c5142f5ff50f63213392fc64.tar.gz
Encapsulate the code to take a pointer to a pathname and return a
pointer to the name of the file to which it refers (i.e., to the last component of the pathname) in a "get_basename()" routine, and have the code in "file.c" call it. svn path=/trunk/; revision=1552
-rw-r--r--file.c17
-rw-r--r--globals.h9
-rw-r--r--util.c39
-rw-r--r--util.h4
4 files changed, 46 insertions, 23 deletions
diff --git a/file.c b/file.c
index e89fcbfa7f..079806df58 100644
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
- * $Id: file.c,v 1.158 2000/01/25 01:05:06 guy Exp $
+ * $Id: file.c,v 1.159 2000/01/25 04:31:14 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -247,10 +247,7 @@ set_display_filename(capture_file *cf)
if (!cf->is_tempfile) {
/* Get the last component of the file name, and put that in the
status bar. */
- if ((name_ptr = (gchar *) strrchr(cf->filename, PATH_SEPARATOR)) == NULL)
- name_ptr = cf->filename;
- else
- name_ptr++;
+ name_ptr = get_basename(cf->filename);
} else {
/* The file we read is a temporary file from a live capture;
we don't mention its name in the status bar. */
@@ -281,10 +278,7 @@ read_cap_file(capture_file *cf)
char errmsg_errno[1024+1];
gchar err_str[2048+1];
- if ((name_ptr = (gchar *) strrchr(cf->filename, PATH_SEPARATOR)) == NULL)
- name_ptr = cf->filename;
- else
- name_ptr++;
+ name_ptr = get_basename(cf->filename);
msg_len = strlen(name_ptr) + strlen(load_fmt) + 2;
load_msg = g_malloc(msg_len);
@@ -1324,10 +1318,7 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
struct wtap_pkthdr hdr;
guint8 pd[65536];
- if ((name_ptr = (gchar *) strrchr(fname, PATH_SEPARATOR)) == NULL)
- name_ptr = fname;
- else
- name_ptr++;
+ name_ptr = get_basename(fname);
msg_len = strlen(name_ptr) + strlen(save_fmt) + 2;
save_msg = g_malloc(msg_len);
snprintf(save_msg, msg_len, save_fmt, name_ptr);
diff --git a/globals.h b/globals.h
index c8766d9388..71e29bd526 100644
--- a/globals.h
+++ b/globals.h
@@ -1,7 +1,7 @@
/* globals.h
* Global defines, etc.
*
- * $Id: globals.h,v 1.16 2000/01/25 00:17:01 guy Exp $
+ * $Id: globals.h,v 1.17 2000/01/25 04:31:16 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -74,13 +74,6 @@
# define MIN(x, y) ((x) < (y) ? (x) : (y))
#endif
-/* Pathname separator. */
-#ifdef WIN32
-#define PATH_SEPARATOR '\\'
-#else
-#define PATH_SEPARATOR '/'
-#endif
-
extern FILE *data_out_file;
extern packet_info pi;
extern capture_file cf;
diff --git a/util.c b/util.c
index 676b055fc7..40c8635f28 100644
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
/* util.c
* Utility routines
*
- * $Id: util.c,v 1.27 2000/01/16 02:47:47 guy Exp $
+ * $Id: util.c,v 1.28 2000/01/25 04:31:16 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -88,6 +88,43 @@ typedef int mode_t; /* for win32 */
#endif
+/*
+ * Given a pathname, return the last component.
+ */
+char *
+get_basename(char *path)
+{
+ char *filename;
+
+#ifdef WIN32
+ /*
+ * XXX - do we need to search for '/' as well?
+ */
+ if ((filename = strrchr(path, '\\')) == NULL) {
+ /*
+ * OK, no directories - but there might be a drive
+ * letter....
+ */
+ filename = strchr(path, ':');
+ }
+#else
+ filename = strrchr(path, '/');
+#endif
+ if (filename == NULL) {
+ /*
+ * There're no directories, drive letters, etc. in the
+ * name; the pathname *is* the file name.
+ */
+ filename = path;
+ } else {
+ /*
+ * Skip past the pathname or drive letter separator.
+ */
+ filename++;
+ }
+ return filename;
+}
+
static char *
setup_tmpdir(char *dir)
{
diff --git a/util.h b/util.h
index 9ea2a8bfa3..f48be86a3d 100644
--- a/util.h
+++ b/util.h
@@ -1,7 +1,7 @@
/* util.h
* Utility definitions
*
- * $Id: util.h,v 1.15 2000/01/16 02:47:47 guy Exp $
+ * $Id: util.h,v 1.16 2000/01/25 04:31:17 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -30,6 +30,8 @@
extern "C" {
#endif /* __cplusplus */
+char *get_basename(char *);
+
int create_tempfile(char *, int, const char *);
void ASCII_to_EBCDIC(guint8 *buf, guint bytes);