/src/wget2/lib/basename-lgpl.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* basename.c -- return the last element in a file name  | 
2  |  |  | 
3  |  |    Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2025 Free Software  | 
4  |  |    Foundation, Inc.  | 
5  |  |  | 
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.  | 
10  |  |  | 
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.  | 
15  |  |  | 
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/>.  */  | 
18  |  |  | 
19  |  | #include <config.h>  | 
20  |  |  | 
21  |  | /* Specification.  */  | 
22  |  | #include "basename-lgpl.h"  | 
23  |  |  | 
24  |  | #include <string.h>  | 
25  |  |  | 
26  |  | #include "filename.h"  | 
27  |  |  | 
28  |  | char *  | 
29  |  | last_component (char const *name)  | 
30  | 3.20k  | { | 
31  | 3.20k  |   char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);  | 
32  | 3.20k  |   char const *p;  | 
33  | 3.20k  |   bool last_was_slash = false;  | 
34  |  |  | 
35  | 3.20k  |   while (ISSLASH (*base))  | 
36  | 0  |     base++;  | 
37  |  |  | 
38  | 25.6k  |   for (p = base; *p; p++)  | 
39  | 22.4k  |     { | 
40  | 22.4k  |       if (ISSLASH (*p))  | 
41  | 0  |         last_was_slash = true;  | 
42  | 22.4k  |       else if (last_was_slash)  | 
43  | 0  |         { | 
44  | 0  |           base = p;  | 
45  | 0  |           last_was_slash = false;  | 
46  | 0  |         }  | 
47  | 22.4k  |     }  | 
48  |  |  | 
49  | 3.20k  |   return (char *) base;  | 
50  | 3.20k  | }  | 
51  |  |  | 
52  |  | size_t  | 
53  |  | base_len (char const *name)  | 
54  | 3.20k  | { | 
55  | 3.20k  |   size_t len;  | 
56  | 3.20k  |   size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);  | 
57  |  |  | 
58  | 3.20k  |   for (len = strlen (name);  1 < len && ISSLASH (name[len - 1]);  len--)  | 
59  | 0  |     continue;  | 
60  |  |  | 
61  | 3.20k  |   if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1  | 
62  | 3.20k  |       && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])  | 
63  | 0  |     return 2;  | 
64  |  |  | 
65  | 3.20k  |   if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len  | 
66  | 3.20k  |       && len == prefix_len && ISSLASH (name[prefix_len]))  | 
67  | 0  |     return prefix_len + 1;  | 
68  |  |  | 
69  | 3.20k  |   return len;  | 
70  | 3.20k  | }  |