1 #include "../git-compat-util.h"
4 /* Adapted from libiberty's basename.c. */
5 char *gitbasename (char *path)
10 skip_dos_drive_prefix(&path);
15 for (base = path; *path; path++) {
16 if (!is_dir_sep(*path))
20 } while (is_dir_sep(*path));
24 while (--path != base && is_dir_sep(*path))
30 char *gitdirname(char *path)
32 static struct strbuf buf = STRBUF_INIT;
33 char *p = path, *slash = NULL, c;
39 if ((dos_drive_prefix = skip_dos_drive_prefix(&p)) && !*p)
43 * POSIX.1-2001 says dirname("/") should return "/", and dirname("//")
44 * should return "//", but dirname("///") should return "/" again.
47 if (!p[1] || (is_dir_sep(p[1]) && !p[2]))
53 char *tentative = p - 1;
55 /* POSIX.1-2001 says to ignore trailing slashes */
56 while (is_dir_sep(*p))
69 strbuf_addf(&buf, "%.*s.", dos_drive_prefix, path);