1 /* Extract the last component (base name) of a file name.
3 Copyright (C) 1998, 2001, 2003-2006, 2009-2023 Free Software Foundation,
6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 #ifndef _BASENAME_LGPL_H
20 #define _BASENAME_LGPL_H
24 #ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
25 # define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
33 /* Return the address of the last file name component of FILENAME.
34 If FILENAME has some trailing slash(es), they are considered to be
35 part of the last component.
36 If FILENAME has no relative file name components because it is a file
37 system root, return the empty string.
48 The return value is a tail of the given FILENAME; do NOT free() it! */
50 /* This function was traditionally called 'basename', but we avoid this
52 * Various platforms have different functions in their libc.
53 In particular, the glibc basename(), defined in <string.h>, does
54 not consider trailing slashes to be part of the component:
58 * The 'basename' command eliminates trailing slashes and for a root
59 produces a non-empty result:
66 extern char *last_component (char const *filename
) _GL_ATTRIBUTE_PURE
;
68 /* Return the length of the basename FILENAME.
69 Typically FILENAME is the value returned by base_name or last_component.
70 Act like strlen (FILENAME), except omit all trailing slashes. */
71 extern size_t base_len (char const *filename
) _GL_ATTRIBUTE_PURE
;
78 #endif /* _BASENAME_LGPL_H */