1 /* Return the basename of a pathname.
2 This file is in the public domain. */
6 basename -- return pointer to last component of a pathname
9 char *basename (const char *name)
12 Given a pointer to a string containing a typical pathname
13 (/usr/src/cmd/ls/ls.c for example), returns a pointer to the
14 last component of the pathname ("ls.c" in this case).
17 Presumes a UNIX or DOS/Windows style path with UNIX or DOS/Windows
22 #include "libiberty.h"
26 #define DIR_SEPARATOR '/'
29 #if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
31 #define HAVE_DOS_BASED_FILE_SYSTEM
32 #ifndef DIR_SEPARATOR_2
33 #define DIR_SEPARATOR_2 '\\'
37 /* Define IS_DIR_SEPARATOR. */
38 #ifndef DIR_SEPARATOR_2
39 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
40 #else /* DIR_SEPARATOR_2 */
41 # define IS_DIR_SEPARATOR(ch) \
42 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
43 #endif /* DIR_SEPARATOR_2 */
51 #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
52 /* Skip over the disk name in MSDOS pathnames. */
53 if (isalpha (name
[0]) && name
[1] == ':')
57 for (base
= name
; *name
; name
++)
59 if (IS_DIR_SEPARATOR (*name
))
This page took 0.055324 seconds and 4 git commands to generate.