1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* basename.c -- return the last element in a file name
5 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2013 Free Software
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 base_name (char const *name)
32 char const *base = last_component (name);
35 /* If there is no last component, then name is a file system root or the
38 return xstrndup (name, base_len (name));
40 /* Collapse a sequence of trailing slashes into one. */
41 length = base_len (base);
42 if (ISSLASH (base[length]))
45 /* On systems with drive letters, "a/b:c" must return "./b:c" rather
46 than "b:c" to avoid confusion with a drive letter. On systems
47 with pure POSIX semantics, this is not an issue. */
48 if (FILE_SYSTEM_PREFIX_LEN (base))
50 char *p = xmalloc (length + 3);
53 memcpy (p + 2, base, length);
58 /* Finally, copy the basename. */
59 return xstrndup (base, length);