diff options
author | Guy Harris <guy@alum.mit.edu> | 2000-01-25 04:31:17 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2000-01-25 04:31:17 +0000 |
commit | 8e68faf22fb36bf7c5142f5ff50f63213392fc64 (patch) | |
tree | 80c7dd86a404b6700b2b6a916ae3c71dd87c6fa2 /util.c | |
parent | b7a9eca9ba9b52243d1e6f214115a93164d3ea66 (diff) | |
download | wireshark-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
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 39 |
1 files changed, 38 insertions, 1 deletions
@@ -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) { |