annotate lib/basename-lgpl.c @ 398:7987ee447833 3.0-beta1

Added generated files for release
author lost@l-w.ca
date Fri, 23 Jul 2010 17:18:52 -0600
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
398
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
1 /* basename.c -- return the last element in a file name
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
2
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
3 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2010 Free Software
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
4 Foundation, Inc.
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
5
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
6 This program is free software: you can redistribute it and/or modify
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
8 the Free Software Foundation; either version 3 of the License, or
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
9 (at your option) any later version.
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
10
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
14 GNU General Public License for more details.
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
15
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
18
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
19 #include <config.h>
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
20
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
21 #include "dirname.h"
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
22
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
23 #include <string.h>
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
24
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
25 /* Return the address of the last file name component of NAME. If
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
26 NAME has no relative file name components because it is a file
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
27 system root, return the empty string. */
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
28
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
29 char *
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
30 last_component (char const *name)
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
31 {
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
32 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
33 char const *p;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
34 bool saw_slash = false;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
35
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
36 while (ISSLASH (*base))
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
37 base++;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
38
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
39 for (p = base; *p; p++)
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
40 {
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
41 if (ISSLASH (*p))
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
42 saw_slash = true;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
43 else if (saw_slash)
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
44 {
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
45 base = p;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
46 saw_slash = false;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
47 }
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
48 }
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
49
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
50 return (char *) base;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
51 }
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
52
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
53 /* Return the length of the basename NAME. Typically NAME is the
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
54 value returned by base_name or last_component. Act like strlen
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
55 (NAME), except omit all trailing slashes. */
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
56
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
57 size_t
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
58 base_len (char const *name)
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
59 {
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
60 size_t len;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
61 size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
62
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
63 for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
64 continue;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
65
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
66 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
67 && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
68 return 2;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
69
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
70 if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
71 && len == prefix_len && ISSLASH (name[prefix_len]))
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
72 return prefix_len + 1;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
73
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
74 return len;
7987ee447833 Added generated files for release
lost@l-w.ca
parents:
diff changeset
75 }