15 #define PATH_SEPARATOR '/'
17 #define PATH_SEPARATOR '/'
19 #define PATH_SEPARATOR '/'
21 #define PATH_SEPARATOR '\\'
23 #define PATH_SEPARATOR '/'
27 #define isslash(c) ((c) == '/' || (c) == '\\')
29 #define isslash(c) ((c) == '/' || (c) == '\\')
31 #define isslash(c) ((c) == '/')
36 static int has_drive(
const char *path) {
39 if (path ==
NULL)
return 0;
40 if (!*p || !isalpha(*p))
return 0;
46 if (path ==
NULL)
return 0;
49 if (*path &&
isslash(*path))
return 1;
50 return has_drive(path);
52 if (*path &&
isslash(*path))
return 1;
53 return has_drive(path);
55 return (*path &&
isslash(*path));
59 static char *dir_name(
const char *path) {
63 if (path ==
NULL || strlen(path) == 0) {
68 p = path + strlen(path) - 1;
69 while (p > path &&
isslash(*p)) {
73 while (p > path && !
isslash(*p)) {
83 }
while (p > path &&
isslash(*p));
90 strncpy(dname, path, p - path + 1);
91 dname[p - path + 1] =
'\0';
96 static char *base_name(
const char *path) {
100 if (path ==
NULL || strlen(path) == 0) {
105 ep = path + strlen(path) - 1;
106 while (ep > path &&
isslash(*ep)) {
110 if (ep == path &&
isslash(*ep)) {
116 while (sp > path && !
isslash(*(sp - 1))) {
121 errno = ENAMETOOLONG;
124 strncpy(bname, sp, ep - sp + 1);
125 bname[ep - sp + 1] =
'\0';
130 static char *get_bdname(
const char *path,
int type) {
135 if (has_drive(path)) {
137 sprintf(drive,
"%.2s", path);
147 if (strlen(drive) > 0 &&
isslash(*q)) {
149 errno = ENAMETOOLONG;
152 sprintf(bname,
"%s%s", drive, q);
154 sprintf(bname,
"%s", q);
160 char *bname = get_bdname(path,
'B');
168 char *dname = get_bdname(path,
'D');