This source file includes following definitions.
- last_component
- base_len
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21
22 #include "basename-lgpl.h"
23
24 #include <stdbool.h>
25 #include <string.h>
26
27 #include "filename.h"
28
29 char *
30 last_component (char const *name)
31 {
32 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
33 char const *p;
34 bool last_was_slash = false;
35
36 while (ISSLASH (*base))
37 base++;
38
39 for (p = base; *p; p++)
40 {
41 if (ISSLASH (*p))
42 last_was_slash = true;
43 else if (last_was_slash)
44 {
45 base = p;
46 last_was_slash = false;
47 }
48 }
49
50 return (char *) base;
51 }
52
53 size_t
54 base_len (char const *name)
55 {
56 size_t len;
57 size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
58
59 for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
60 continue;
61
62 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
63 && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
64 return 2;
65
66 if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
67 && len == prefix_len && ISSLASH (name[prefix_len]))
68 return prefix_len + 1;
69
70 return len;
71 }