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.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@1552
f5534014-38df-0310-8fa8-
9805f1628bb7
/* 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>
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. */
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);
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);
/* 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>
# 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;
/* 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>
#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)
{
/* 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>
extern "C" {
#endif /* __cplusplus */
+char *get_basename(char *);
+
int create_tempfile(char *, int, const char *);
void ASCII_to_EBCDIC(guint8 *buf, guint bytes);