home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / libg++-2.6-fsf.lha / libg++-2.6 / libiberty / basename.c < prev    next >
C/C++ Source or Header  |  1994-02-10  |  1KB  |  60 lines

  1. /* Return the basename of a pathname.
  2.    Copyright (C) 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of the libiberty library.
  5. Libiberty is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10. Libiberty is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with libiberty; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. /*
  21.  
  22. NAME
  23.  
  24.     basename -- return pointer to last component of a pathname
  25.  
  26. SYNOPSIS
  27.  
  28.     char *basename (char *name)
  29.  
  30. DESCRIPTION
  31.  
  32.     Given a pointer to a string containing a typical pathname
  33.     (/usr/src/cmd/ls/ls.c for example), returns a pointer to the
  34.     last component of the pathname ("ls.c" in this case).
  35.  
  36. BUGS
  37.  
  38.     Presumes a UNIX style path with UNIX style separators.
  39. */
  40.  
  41.  
  42. #include "ansidecl.h"
  43. #include "libiberty.h"
  44.  
  45. char *
  46. basename (name)
  47.   char *name;
  48. {
  49.   char *base = name;
  50.  
  51.   while (*name)
  52.     {
  53.       if (*name++ == '/')
  54.     {
  55.       base = name;
  56.     }
  57.     }
  58.   return (base);
  59. }
  60.