vtools_genesis 1 #include "dirname.h"
vtools_genesis 2 #include <string.h>
vtools_genesis 3 #include <stdbool.h>
vtools_genesis 4
vtools_genesis 5
vtools_genesis 6 |name| has no relative file name components because it is a file
vtools_genesis 7 system root, return the empty string. */
vtools_genesis 8
vtools_genesis 9 char *
vtools_genesis 10 last_component(char const *name) {
vtools_genesis 11 char const *base = name + 0;
vtools_genesis 12 char const *p;
vtools_genesis 13 bool saw_slash = false;
vtools_genesis 14
vtools_genesis 15 while (((*base) == '/'))
vtools_genesis 16 base++;
vtools_genesis 17
vtools_genesis 18 for (p = base; *p; p++) {
vtools_genesis 19 if (((*p) == '/'))
vtools_genesis 20 saw_slash = true;
vtools_genesis 21 else if (saw_slash) {
vtools_genesis 22 base = p;
vtools_genesis 23 saw_slash = false;
vtools_genesis 24 }
vtools_genesis 25 }
vtools_genesis 26
vtools_genesis 27 return (char *) base;
vtools_genesis 28 }
vtools_genesis 29
vtools_genesis 30
vtools_genesis 31 value returned by |base_name| or |last_component|. Act like
vtools_genesis 32 |strlen(name)|, except omit all trailing slashes. */
vtools_genesis 33
vtools_genesis 34 size_t
vtools_genesis 35 base_len(char const *name) {
vtools_genesis 36 size_t len;
vtools_genesis 37
vtools_genesis 38 for (len = strlen(name); 1 < len && ((name[len - 1]) == '/'); len--)
vtools_genesis 39 continue;
vtools_genesis 40 return len;
vtools_genesis 41 }