Back to index

tetex-bin  3.0
xbasename.c
Go to the documentation of this file.
00001 /* basename.c: return the last element in a path.
00002 
00003 Copyright (C) 1992, 94, 95, 96 Free Software Foundation, Inc.
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Library General Public
00007 License as published by the Free Software Foundation; either
00008 version 2 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Library General Public License for more details.
00014 
00015 You should have received a copy of the GNU Library General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00018 
00019 /* Have to include this first to get c-auto.h.  */
00020 #include <kpathsea/config.h>
00021 
00022 #include <kpathsea/c-pathch.h>
00023 
00024 /* Return NAME with any leading path stripped off.  This returns a
00025    pointer into NAME.  For example, `basename ("/foo/bar.baz")'
00026    returns "bar.baz".  */
00027 
00028 const_string
00029 xbasename P1C(const_string, name)
00030 {
00031   const_string base = NULL;
00032   unsigned len;
00033   
00034   for (len = strlen (name); len > 0; len--) {
00035     if (IS_DIR_SEP (name[len - 1]) || IS_DEVICE_SEP (name[len - 1])) {
00036       base = name + len;
00037       break;
00038     }
00039   }
00040 
00041   if (!base)
00042     base = name;
00043   
00044   return base;
00045 }