diff options
author | Ian Lance Taylor <ian@airs.com> | 2000-02-22 15:59:20 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 2000-02-22 15:59:20 +0000 |
commit | bbde8fc09912c675acb6f01bf0195f508daadcd2 (patch) | |
tree | 80ff61110b6ba30aa05932d04176fae741d8a02d /libiberty/basename.c | |
parent | 924ed2ac9c2b5d4487bc0d37c18999f6c8232ee6 (diff) | |
download | gdb-bbde8fc09912c675acb6f01bf0195f508daadcd2.tar.gz |
import libiberty from egcs
Diffstat (limited to 'libiberty/basename.c')
-rw-r--r-- | libiberty/basename.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/libiberty/basename.c b/libiberty/basename.c index f544c853910..7698f06f8ae 100644 --- a/libiberty/basename.c +++ b/libiberty/basename.c @@ -14,24 +14,53 @@ DESCRIPTION last component of the pathname ("ls.c" in this case). BUGS - Presumes a UNIX style path with UNIX style separators. + Presumes a UNIX or DOS/Windows style path with UNIX or DOS/Windows + style separators. */ #include "ansidecl.h" #include "libiberty.h" +#include <ctype.h> + +#ifndef DIR_SEPARATOR +#define DIR_SEPARATOR '/' +#endif + +#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ + defined (__OS2__) +#define HAVE_DOS_BASED_FILE_SYSTEM +#ifndef DIR_SEPARATOR_2 +#define DIR_SEPARATOR_2 '\\' +#endif +#endif + +/* Define IS_DIR_SEPARATOR. */ +#ifndef DIR_SEPARATOR_2 +# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) +#else /* DIR_SEPARATOR_2 */ +# define IS_DIR_SEPARATOR(ch) \ + (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) +#endif /* DIR_SEPARATOR_2 */ char * basename (name) const char *name; { - const char *base = name; + const char *base; - while (*name) +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + /* Skip over the disk name in MSDOS pathnames. */ + if (isalpha (name[0]) && name[1] == ':') + name += 2; +#endif + + for (base = name; *name; name++) { - if (*name++ == '/') + if (IS_DIR_SEPARATOR (*name)) { - base = name; + base = name + 1; } } return (char *) base; } + |