diff options
author | Guy Harris <guy@alum.mit.edu> | 2001-04-02 09:53:46 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2001-04-02 09:53:46 +0000 |
commit | 65dc46932669c4fb95360156a863294f51963fa8 (patch) | |
tree | 58d2550d39940bee832d3438d649188b1294cd58 | |
parent | d203637adecc1783ce9705a33e7af6e88778f5e2 (diff) |
"get_home_dir()", in "epan/filesystem.c", uses
"find_last_pathname_separator()" on Win32; move the other pathname
manipulation routines from "util.c" into "epan/filesystem.c".
Remove from "util.h" the declarations of routines not defined in
"util.c", and put them into "epan/filesystem.h" if they're not already
there.
Adjust #includes to make the above work.
svn path=/trunk/; revision=3241
-rw-r--r-- | epan/filesystem.c | 93 | ||||
-rw-r--r-- | epan/filesystem.h | 21 | ||||
-rw-r--r-- | filters.c | 4 | ||||
-rw-r--r-- | gtk/colors.c | 4 | ||||
-rw-r--r-- | gtk/main.c | 3 | ||||
-rw-r--r-- | prefs.c | 4 | ||||
-rw-r--r-- | util.c | 93 | ||||
-rw-r--r-- | util.h | 6 |
8 files changed, 122 insertions, 106 deletions
diff --git a/epan/filesystem.c b/epan/filesystem.c index 25a807db6f..0dfa42489e 100644 --- a/epan/filesystem.c +++ b/epan/filesystem.c @@ -1,7 +1,7 @@ /* filesystem.c * Filesystem utility routines * - * $Id: filesystem.c,v 1.3 2001/03/31 22:53:09 hagbard Exp $ + * $Id: filesystem.c,v 1.4 2001/04/02 09:53:44 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -41,6 +41,97 @@ #include "filesystem.h" +/* + * Given a pathname, return a pointer to the last pathname separator + * character in the pathname, or NULL if the pathname contains no + * separators. + */ +char * +find_last_pathname_separator(char *path) +{ + char *separator; + +#ifdef WIN32 + char c; + + /* + * We have to scan for '\' or '/'. + * Get to the end of the string. + */ + separator = path + strlen(path); /* points to ending '\0' */ + while (separator > path) { + c = *--separator; + if (c == '\\' || c == '/') + return separator; /* found it */ + } + + /* + * OK, we didn't find any, so no directories - but there might + * be a drive letter.... + */ + return strchr(path, ':'); +#else + separator = strrchr(path, '/'); +#endif + return separator; +} + +/* + * Given a pathname, return the last component. + */ +char * +get_basename(char *path) +{ + char *filename; + + filename = find_last_pathname_separator(path); + 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; +} + +/* + * Given a pathname, return a string containing everything but the + * last component. NOTE: this overwrites the pathname handed into + * it.... + */ +char * +get_dirname(char *path) +{ + char *separator; + + separator = find_last_pathname_separator(path); + if (separator == NULL) { + /* + * There're no directories, drive letters, etc. in the + * name; there is no directory path to return. + */ + return NULL; + } + + /* + * Get rid of the last pathname separator and the final file + * name following it. + */ + *separator = '\0'; + + /* + * "path" now contains the pathname of the directory containing + * the file/directory to which it referred. + */ + return path; +} + const char* get_home_dir(void) { diff --git a/epan/filesystem.h b/epan/filesystem.h index 8c0455549c..129bc02455 100644 --- a/epan/filesystem.h +++ b/epan/filesystem.h @@ -1,7 +1,7 @@ /* filesystem.h * Filesystem utility definitions * - * $Id: filesystem.h,v 1.2 2000/12/22 22:26:19 nneul Exp $ + * $Id: filesystem.h,v 1.3 2001/04/02 09:53:44 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -26,6 +26,25 @@ #ifndef FILESYSTEM_H #define FILESYSTEM_H +/* + * Given a pathname, return a pointer to the last pathname separator + * character in the pathname, or NULL if the pathname contains no + * separators. + */ +char *find_last_pathname_separator(char *); + +/* + * Given a pathname, return the last component. + */ +char *get_basename(char *); + +/* + * Given a pathname, return a string containing everything but the + * last component. NOTE: this overwrites the pathname handed into + * it.... + */ +char *get_dirname(char *); + /* Returns the user's home directory, via the HOME environment * variable, or a default directory if HOME is not set */ const char* get_home_dir(void); @@ -1,7 +1,7 @@ /* filters.c * Code for reading and writing the filters file. * - * $Id: filters.c,v 1.8 2001/03/15 09:50:39 guy Exp $ + * $Id: filters.c,v 1.9 2001/04/02 09:53:42 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -47,9 +47,9 @@ #include <glib.h> #include <epan.h> +#include <filesystem.h> #include "filters.h" -#include "util.h" /* * Old filter file name. diff --git a/gtk/colors.c b/gtk/colors.c index 6bbfe41ff3..14219b7db1 100644 --- a/gtk/colors.c +++ b/gtk/colors.c @@ -1,7 +1,7 @@ /* colors.c * Definitions for color structures and routines * - * $Id: colors.c,v 1.7 2001/02/01 20:21:21 gram Exp $ + * $Id: colors.c,v 1.8 2001/04/02 09:53:46 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -40,13 +40,13 @@ #endif #include <epan.h> +#include <epan/filesystem.h> #include "gtk/main.h" #include "packet.h" #include "colors.h" #include "file.h" #include "dfilter/dfilter.h" #include "simple_dialog.h" -#include "util.h" extern capture_file cf; diff --git a/gtk/main.c b/gtk/main.c index 8b1c6841fe..936555dac4 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.186 2001/04/02 00:38:36 hagbard Exp $ + * $Id: main.c,v 1.187 2001/04/02 09:53:46 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -107,6 +107,7 @@ #endif #include <epan.h> +#include <epan/filesystem.h> #include "main.h" #include "timestamp.h" @@ -1,7 +1,7 @@ /* prefs.c * Routines for handling preferences * - * $Id: prefs.c,v 1.47 2001/01/05 22:45:26 guy Exp $ + * $Id: prefs.c,v 1.48 2001/04/02 09:53:42 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -49,6 +49,7 @@ #endif #include <epan.h> +#include <filesystem.h> #include "globals.h" #include "packet.h" #include "file.h" @@ -56,7 +57,6 @@ #include "proto.h" #include "column.h" #include "print.h" -#include "util.h" #include "prefs-int.h" @@ -1,7 +1,7 @@ /* util.c * Utility routines * - * $Id: util.c,v 1.50 2001/03/22 06:14:27 guy Exp $ + * $Id: util.c,v 1.51 2001/04/02 09:53:43 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -135,97 +135,6 @@ test_for_directory(const char *path) } /* - * Given a pathname, return a pointer to the last pathname separator - * character in the pathname, or NULL if the pathname contains no - * separators. - */ -char * -find_last_pathname_separator(char *path) -{ - char *separator; - -#ifdef WIN32 - char c; - - /* - * We have to scan for '\' or '/'. - * Get to the end of the string. - */ - separator = path + strlen(path); /* points to ending '\0' */ - while (separator > path) { - c = *--separator; - if (c == '\\' || c == '/') - return separator; /* found it */ - } - - /* - * OK, we didn't find any, so no directories - but there might - * be a drive letter.... - */ - return strchr(path, ':'); -#else - separator = strrchr(path, '/'); -#endif - return separator; -} - -/* - * Given a pathname, return the last component. - */ -char * -get_basename(char *path) -{ - char *filename; - - filename = find_last_pathname_separator(path); - 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; -} - -/* - * Given a pathname, return a string containing everything but the - * last component. NOTE: this overwrites the pathname handed into - * it.... - */ -char * -get_dirname(char *path) -{ - char *separator; - - separator = find_last_pathname_separator(path); - if (separator == NULL) { - /* - * There're no directories, drive letters, etc. in the - * name; there is no directory path to return. - */ - return NULL; - } - - /* - * Get rid of the last pathname separator and the final file - * name following it. - */ - *separator = '\0'; - - /* - * "path" now contains the pathname of the directory containing - * the file/directory to which it referred. - */ - return path; -} - -/* * Collect command-line arguments as a string consisting of the arguments, * separated by spaces. */ @@ -1,7 +1,7 @@ /* util.h * Utility definitions * - * $Id: util.h,v 1.22 2000/10/11 07:35:00 guy Exp $ + * $Id: util.h,v 1.23 2001/04/02 09:53:43 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -64,10 +64,6 @@ char *get_dirname(char *); int create_tempfile(char *, int, const char *); -/* Returns the user's home directory, via the HOME environment - * variable, or a default directory if HOME is not set */ -const char* get_home_dir(void); - /* * Collect command-line arguments as a string consisting of the arguments, * separated by spaces. |