summaryrefslogtreecommitdiffstats
path: root/gl/basename-lgpl.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/basename-lgpl.c')
-rw-r--r--gl/basename-lgpl.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/gl/basename-lgpl.c b/gl/basename-lgpl.c
index 9307e83..6de60aa 100644
--- a/gl/basename-lgpl.c
+++ b/gl/basename-lgpl.c
@@ -1,37 +1,36 @@
1/* basename.c -- return the last element in a file name 1/* basename.c -- return the last element in a file name
2 2
3 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2013 Free Software 3 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2023 Free Software
4 Foundation, Inc. 4 Foundation, Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU Lesser General Public License as
8 the Free Software Foundation; either version 3 of the License, or 8 published by the Free Software Foundation; either version 2.1 of the
9 (at your option) any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20 20
21#include "dirname.h" 21/* Specification. */
22#include "basename-lgpl.h"
22 23
23#include <string.h> 24#include <string.h>
24 25
25/* Return the address of the last file name component of NAME. If 26#include "filename.h"
26 NAME has no relative file name components because it is a file
27 system root, return the empty string. */
28 27
29char * 28char *
30last_component (char const *name) 29last_component (char const *name)
31{ 30{
32 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); 31 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
33 char const *p; 32 char const *p;
34 bool saw_slash = false; 33 bool last_was_slash = false;
35 34
36 while (ISSLASH (*base)) 35 while (ISSLASH (*base))
37 base++; 36 base++;
@@ -39,21 +38,17 @@ last_component (char const *name)
39 for (p = base; *p; p++) 38 for (p = base; *p; p++)
40 { 39 {
41 if (ISSLASH (*p)) 40 if (ISSLASH (*p))
42 saw_slash = true; 41 last_was_slash = true;
43 else if (saw_slash) 42 else if (last_was_slash)
44 { 43 {
45 base = p; 44 base = p;
46 saw_slash = false; 45 last_was_slash = false;
47 } 46 }
48 } 47 }
49 48
50 return (char *) base; 49 return (char *) base;
51} 50}
52 51
53/* Return the length of the basename NAME. Typically NAME is the
54 value returned by base_name or last_component. Act like strlen
55 (NAME), except omit all trailing slashes. */
56
57size_t 52size_t
58base_len (char const *name) 53base_len (char const *name)
59{ 54{