1 /* Extract the last component (base name) of a file name.
3 Copyright (C) 1998, 2001, 2003-2006, 2009-2024 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
22 /* This file uses _GL_ATTRIBUTE_PURE. */
23 #if !_GL_CONFIG_H_INCLUDED
24 #error "Please include config.h first."
29 #ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
30 # define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
38 /* Return the address of the last file name component of FILENAME.
39 If FILENAME has some trailing slash(es), they are considered to be
40 part of the last component.
41 If FILENAME has no relative file name components because it is a file
42 system root, return the empty string.
53 The return value is a tail of the given FILENAME; do NOT free() it! */
55 /* This function was traditionally called 'basename', but we avoid this
57 * Various platforms have different functions in their libc.
58 In particular, the glibc basename(), defined in <string.h>, does
59 not consider trailing slashes to be part of the component:
63 * The 'basename' command eliminates trailing slashes and for a root
64 produces a non-empty result:
71 extern char *last_component (char const *filename
) _GL_ATTRIBUTE_PURE
;
73 /* Return the length of the basename FILENAME.
74 Typically FILENAME is the value returned by base_name or last_component.
75 Act like strlen (FILENAME), except omit all trailing slashes. */
76 extern size_t base_len (char const *filename
) _GL_ATTRIBUTE_PURE
;
83 #endif /* _BASENAME_LGPL_H */