2999
|
1 /* basename.c: return the last element in a path. |
|
2 |
|
3 Copyright (C) 1992, 94, 95, 96 Free Software Foundation, Inc. |
|
4 |
|
5 This library 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 This library 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 this library; if not, write to the Free Software |
|
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
|
18 |
|
19 /* Have to include this first to get c-auto.h. */ |
|
20 #include <kpathsea/config.h> |
|
21 |
|
22 #ifndef HAVE_BASENAME /* rest of file */ |
|
23 |
|
24 #include <kpathsea/c-pathch.h> |
|
25 |
|
26 /* Return NAME with any leading path stripped off. This returns a |
|
27 pointer into NAME. For example, `basename ("/foo/bar.baz")' |
|
28 returns "bar.baz". */ |
|
29 |
|
30 const_string |
|
31 basename P1C(const_string, name) |
|
32 { |
|
33 const_string base = NULL; |
|
34 unsigned len = strlen (name); |
|
35 |
|
36 for (len = strlen (name); len > 0; len--) { |
|
37 if (IS_DIR_SEP (name[len - 1]) || IS_DEVICE_SEP (name[len - 1])) { |
|
38 base = name + len; |
|
39 break; |
|
40 } |
|
41 } |
|
42 |
|
43 if (!base) |
|
44 base = name; |
|
45 |
|
46 return base; |
|
47 } |
|
48 |
|
49 #endif /* not HAVE_BASENAME */ |