/[gnats]/gnats/libiberty/basename.c
ViewVC logotype

Diff of /gnats/libiberty/basename.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by jsm, Tue Oct 26 07:10:16 1999 UTC revision 1.3 by pdm, Mon Dec 10 23:03:27 2001 UTC
# Line 14  DESCRIPTION Line 14  DESCRIPTION
14          last component of the pathname ("ls.c" in this case).          last component of the pathname ("ls.c" in this case).
15    
16  BUGS  BUGS
17          Presumes a UNIX style path with UNIX style separators.          Presumes a UNIX or DOS/Windows style path with UNIX or DOS/Windows
18            style separators.
19  */  */
20    
21  #include "ansidecl.h"  #include "ansidecl.h"
22  #include "libiberty.h"  #include "libiberty.h"
23    #include "safe-ctype.h"
24    
25    #ifndef DIR_SEPARATOR
26    #define DIR_SEPARATOR '/'
27    #endif
28    
29    #if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
30      defined (__OS2__)
31    #define HAVE_DOS_BASED_FILE_SYSTEM
32    #ifndef DIR_SEPARATOR_2
33    #define DIR_SEPARATOR_2 '\\'
34    #endif
35    #endif
36    
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 */
44    
45  char *  char *
46  basename (name)  basename (name)
47       const char *name;       const char *name;
48  {  {
49    const char *base = name;    const char *base;
50    
51    while (*name)  #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
52      /* Skip over the disk name in MSDOS pathnames. */
53      if (ISALPHA (name[0]) && name[1] == ':')
54        name += 2;
55    #endif
56    
57      for (base = name; *name; name++)
58      {      {
59        if (*name++ == '/')        if (IS_DIR_SEPARATOR (*name))
60          {          {
61            base = name;            base = name + 1;
62          }          }
63      }      }
64    return (char *) base;    return (char *) base;
65  }  }
66    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26