1 /* basename.c -- return the last element in a path */
7 #ifndef FILESYSTEM_PREFIX_LEN
8 # define FILESYSTEM_PREFIX_LEN(f) 0
12 # define ISSLASH(c) ((c) == '/')
15 /* In general, we can't use the builtin `basename' function if available,
16 since it has different meanings in different environments.
17 In some environments the builtin `basename' modifies its argument. */
23 char const *base = name += FILESYSTEM_PREFIX_LEN (name);
39 base_name_strip_trailing_slashes (name)
42 char const *end_p = name += FILESYSTEM_PREFIX_LEN (name);
43 char const *first, *p;
47 /* Make END_P point to the byte after the last non-slash character
48 in NAME if one exists. */
49 for (p = name; *p; p++)
60 while (first > name && !ISSLASH (*(first - 1)))
64 length = end_p - first;
65 base = (char *) malloc (length + 1);
69 memcpy (base, first, length);
79 # define CHECK(a,b) assert (strcmp (base_name_strip_trailing_slashes(a), b) \
89 CHECK ("/ab/c/", "c");
90 CHECK ("/ab/c////", "c");