summaryrefslogtreecommitdiffstats
path: root/contrib/gcclibs/libiberty/basename.c
diff options
context:
space:
mode:
authorkan <kan@FreeBSD.org>2007-05-19 01:27:20 +0000
committerkan <kan@FreeBSD.org>2007-05-19 01:27:20 +0000
commit97ee9c3f29d2708e2a9383c5bfe5a3dd7dfe60dd (patch)
treee78bbacd6aa94e5c274d08bf2fa679b26cbf6b58 /contrib/gcclibs/libiberty/basename.c
parent7d2f610e8aa1acfb76e67a4f7e95319fda7f50b6 (diff)
downloadFreeBSD-src-97ee9c3f29d2708e2a9383c5bfe5a3dd7dfe60dd.zip
FreeBSD-src-97ee9c3f29d2708e2a9383c5bfe5a3dd7dfe60dd.tar.gz
GCC 4.2.0 release miscellaneous support libraries.
Diffstat (limited to 'contrib/gcclibs/libiberty/basename.c')
-rw-r--r--contrib/gcclibs/libiberty/basename.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/contrib/gcclibs/libiberty/basename.c b/contrib/gcclibs/libiberty/basename.c
new file mode 100644
index 0000000..0f2c069
--- /dev/null
+++ b/contrib/gcclibs/libiberty/basename.c
@@ -0,0 +1,62 @@
+/* Return the basename of a pathname.
+ This file is in the public domain. */
+
+/*
+
+@deftypefn Supplemental char* basename (const char *@var{name})
+
+Returns a pointer to the last component of pathname @var{name}.
+Behavior is undefined if the pathname ends in a directory separator.
+
+@end deftypefn
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "ansidecl.h"
+#include "libiberty.h"
+#include "safe-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 (const char *name)
+{
+ const char *base;
+
+#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 (IS_DIR_SEPARATOR (*name))
+ {
+ base = name + 1;
+ }
+ }
+ return (char *) base;
+}
+
OpenPOWER on IntegriCloud