diff options
-rw-r--r-- | file.c | 17 | ||||
-rw-r--r-- | globals.h | 9 | ||||
-rw-r--r-- | util.c | 39 | ||||
-rw-r--r-- | util.h | 4 |
4 files changed, 46 insertions, 23 deletions
@@ -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); @@ -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; @@ -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) { @@ -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); |