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

Diff of /gnats/libiberty/lbasename.c

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

revision 1.1 by pdm, Mon Dec 10 23:03:26 2001 UTC revision 1.2 by chewie, Sat Nov 13 05:14:17 2004 UTC
# Line 1  Line 1 
1  /* Libiberty basename.  Like basename, but is not overridden by the  /* Libiberty basename.  Like basename, but is not overridden by the
2     system C library.     system C library.
3     Copyright (C) 2001 Free Software Foundation, Inc.     Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4    
5  This file is part of the libiberty library.  This file is part of the libiberty library.
6  Libiberty is free software; you can redistribute it and/or  Libiberty is free software; you can redistribute it and/or
# Line 19  not, write to the Free Software Foundati Line 19  not, write to the Free Software Foundati
19  Boston, MA 02111-1307, USA.  */  Boston, MA 02111-1307, USA.  */
20    
21  /*  /*
 NAME  
         lbasename -- return pointer to last component of a pathname  
22    
23  SYNOPSIS  @deftypefn Replacement {const char*} lbasename (const char *@var{name})
         char *lbasename (const char *name)  
24    
25  DESCRIPTION  Given a pointer to a string containing a typical pathname
26          Given a pointer to a string containing a typical pathname  (@samp{/usr/src/cmd/ls/ls.c} for example), returns a pointer to the
27          (/usr/src/cmd/ls/ls.c for example), returns a pointer to the  last component of the pathname (@samp{ls.c} in this case).  The
28          last component of the pathname ("ls.c" in this case).  The  returned pointer is guaranteed to lie within the original
29          returned pointer is guaranteed to lie within the original  string.  This latter fact is not true of many vendor C
30          string.  This latter fact is not true of many vendor C  libraries, which return special strings or modify the passed
31          libraries, which return special strings or modify the passed  strings for particular input.
32          strings for particular input.  
33    In particular, the empty string returns the same empty string,
34    and a path ending in @code{/} returns the empty string after it.
35    
36    @end deftypefn
37    
         In particular, the empty string returns the same empty string,  
         and a path ending in '/' returns the empty string after it.  
38  */  */
39    
40  #include "ansidecl.h"  #include "ansidecl.h"
41  #include "libiberty.h"  #include "libiberty.h"
42  #include "safe-ctype.h"  #include "safe-ctype.h"
43    #include "filenames.h"
44    
45  #ifndef DIR_SEPARATOR  const char *
 #  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. VMS uses '::', ':', '[...]' and '<...>' to  
    separate the different components of a file specification.  It's a  
    bit of a stretch to call ':', ']' and '>' directory separators, so  
    just define the test to find the file name component.  */  
 #ifdef VMS  
 #  define IS_DIR_SEPARATOR(ch) ((ch) == ':' || (ch) == ']' || (ch) == '>')  
 #else  
 #  ifndef DIR_SEPARATOR_2  
 #    define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)  
 #  else  
 #    define IS_DIR_SEPARATOR(ch) \  
         (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))  
 #  endif  
 #endif  
   
 char *  
46  lbasename (name)  lbasename (name)
47       const char *name;       const char *name;
48  {  {
# Line 85  lbasename (name) Line 58  lbasename (name)
58      if (IS_DIR_SEPARATOR (*name))      if (IS_DIR_SEPARATOR (*name))
59        base = name + 1;        base = name + 1;
60    
61    return (char *) base;    return base;
62  }  }

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

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