1139749Simp/* Libiberty basename. Like basename, but is not overridden by the 2121468Ssimokawa system C library. 3121468Ssimokawa Copyright (C) 2001, 2002 Free Software Foundation, Inc. 4121468Ssimokawa 5121468SsimokawaThis file is part of the libiberty library. 6121468SsimokawaLibiberty is free software; you can redistribute it and/or 7121468Ssimokawamodify it under the terms of the GNU Library General Public 8121468SsimokawaLicense as published by the Free Software Foundation; either 9121468Ssimokawaversion 2 of the License, or (at your option) any later version. 10121468Ssimokawa 11121468SsimokawaLibiberty is distributed in the hope that it will be useful, 12121468Ssimokawabut WITHOUT ANY WARRANTY; without even the implied warranty of 13121468SsimokawaMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14121468SsimokawaLibrary General Public License for more details. 15121468Ssimokawa 16121468SsimokawaYou should have received a copy of the GNU Library General Public 17121468SsimokawaLicense along with libiberty; see the file COPYING.LIB. If 18121468Ssimokawanot, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 19121468SsimokawaBoston, MA 02110-1301, USA. */ 20121468Ssimokawa 21121468Ssimokawa/* 22121468Ssimokawa 23121468Ssimokawa@deftypefn Replacement {const char*} lbasename (const char *@var{name}) 24121468Ssimokawa 25121468SsimokawaGiven a pointer to a string containing a typical pathname 26121468Ssimokawa(@samp{/usr/src/cmd/ls/ls.c} for example), returns a pointer to the 27121468Ssimokawalast component of the pathname (@samp{ls.c} in this case). The 28121468Ssimokawareturned pointer is guaranteed to lie within the original 29121468Ssimokawastring. This latter fact is not true of many vendor C 30121468Ssimokawalibraries, which return special strings or modify the passed 31121468Ssimokawastrings for particular input. 32121468Ssimokawa 33121468SsimokawaIn particular, the empty string returns the same empty string, 34121468Ssimokawaand a path ending in @code{/} returns the empty string after it. 35121468Ssimokawa 36121468Ssimokawa@end deftypefn 37121468Ssimokawa 38121468Ssimokawa*/ 39121468Ssimokawa 40129879Sphk#ifdef HAVE_CONFIG_H 41121468Ssimokawa#include "config.h" 42121468Ssimokawa#endif 43121468Ssimokawa#include "ansidecl.h" 44121468Ssimokawa#include "libiberty.h" 45121468Ssimokawa#include "safe-ctype.h" 46121468Ssimokawa#include "filenames.h" 47121468Ssimokawa 48121468Ssimokawaconst char * 49136467Ssimokawalbasename (const char *name) 50136467Ssimokawa{ 51136467Ssimokawa const char *base; 52136467Ssimokawa 53136467Ssimokawa#if defined (HAVE_DOS_BASED_FILE_SYSTEM) 54136467Ssimokawa /* Skip over a possible disk name. */ 55136467Ssimokawa if (ISALPHA (name[0]) && name[1] == ':') 56121468Ssimokawa name += 2; 57121468Ssimokawa#endif 58121468Ssimokawa 59121468Ssimokawa for (base = name; *name; name++) 60136467Ssimokawa if (IS_DIR_SEPARATOR (*name)) 61136467Ssimokawa base = name + 1; 62121468Ssimokawa 63125862Ssimokawa return base; 64125862Ssimokawa} 65170420Ssimokawa