10 #include <sys/types.h>
13 #define WIN_SEPARATOR_CHAR '\\'
14 #define WIN_SEPARATOR_STRING "\\"
15 #define NIX_SEPARATOR_CHAR '/'
16 #define NIX_SEPARATOR_STRING "/"
19 #define DIR_SEPARATOR_CHAR WIN_SEPARATOR_CHAR
20 #define DIR_SEPARATOR_STRING WIN_SEPARATOR_STRING
21 #define BAD_SEPARATOR_CHAR NIX_SEPARATOR_CHAR
22 #define MKDIR(s) mkdir(s)
24 #define DIR_SEPARATOR_CHAR NIX_SEPARATOR_CHAR
25 #define DIR_SEPARATOR_STRING NIX_SEPARATOR_STRING
26 #define BAD_SEPARATOR_CHAR WIN_SEPARATOR_CHAR
27 #define MKDIR(s) mkdir(s,0755)
31 convert_path(char* origpath
)
36 newpath
=malloc(strlen(origpath
)+1);
37 strcpy(newpath
,origpath
);
40 while (newpath
[i
] != 0)
42 if (newpath
[i
] == BAD_SEPARATOR_CHAR
)
44 newpath
[i
] = DIR_SEPARATOR_CHAR
;
51 #define TRANSFER_SIZE (65536)
53 int mkdir_p(char* path
)
61 perror("Failed to create directory");
66 perror("Failed to change directory");
72 int main(int argc
, char* argv
[])
80 fprintf(stderr
, "Too many arguments\n");
84 path1
= convert_path(argv
[1]);
86 if (isalpha(path1
[0]) && path1
[1] == ':' && path1
[2] == DIR_SEPARATOR_CHAR
)
88 csec
= strtok(path1
, DIR_SEPARATOR_STRING
);
89 sprintf(buf
, "%s\\", csec
);
91 csec
= strtok(NULL
, DIR_SEPARATOR_STRING
);
93 else if (path1
[0] == DIR_SEPARATOR_CHAR
)
95 chdir(DIR_SEPARATOR_STRING
);
96 csec
= strtok(path1
, DIR_SEPARATOR_STRING
);
100 csec
= strtok(path1
, DIR_SEPARATOR_STRING
);
106 csec
= strtok(NULL
, DIR_SEPARATOR_STRING
);