1 #include "../git-compat-util.h"
4 /* Adapted from libiberty's basename.c. */
5 char *gitbasename (char *path
)
10 skip_dos_drive_prefix(&path
);
14 * basename(3P) is mis-specified because it returns a
15 * non-constant pointer even though it is specified to return a
16 * pointer to internal memory at times. The cast is a result of
21 for (base
= path
; *path
; path
++) {
22 if (!is_dir_sep(*path
))
26 } while (is_dir_sep(*path
));
30 while (--path
!= base
&& is_dir_sep(*path
))
36 char *gitdirname(char *path
)
38 static struct strbuf buf
= STRBUF_INIT
;
39 char *p
= path
, *slash
= NULL
, c
;
44 * dirname(3P) is mis-specified because it returns a
45 * non-constant pointer even though it is specified to return a
46 * pointer to internal memory at times. The cast is a result of
51 if ((dos_drive_prefix
= skip_dos_drive_prefix(&p
)) && !*p
)
55 * POSIX.1-2001 says dirname("/") should return "/", and dirname("//")
56 * should return "//", but dirname("///") should return "/" again.
59 if (!p
[1] || (is_dir_sep(p
[1]) && !p
[2]))
65 char *tentative
= p
- 1;
67 /* POSIX.1-2001 says to ignore trailing slashes */
68 while (is_dir_sep(*p
))
81 strbuf_addf(&buf
, "%.*s.", dos_drive_prefix
, path
);