disable the custom rules for Winebuild for now
[reactos.git] / reactos / tools / rmkdir.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <ctype.h>
5 #ifdef WIN32
6 #include <direct.h>
7 #else
8 #include <unistd.h>
9 #include <sys/stat.h>
10 #include <sys/types.h>
11 #endif
12
13 #define WIN_SEPARATOR_CHAR '\\'
14 #define WIN_SEPARATOR_STRING "\\"
15 #define NIX_SEPARATOR_CHAR '/'
16 #define NIX_SEPARATOR_STRING "/"
17
18 #ifdef WIN32
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)
23 #else
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)
28 #endif
29
30 char*
31 convert_path(char* origpath)
32 {
33 char* newpath;
34 int i;
35
36 newpath=malloc(strlen(origpath)+1);
37 strcpy(newpath,origpath);
38
39 i = 0;
40 while (newpath[i] != 0)
41 {
42 if (newpath[i] == BAD_SEPARATOR_CHAR)
43 {
44 newpath[i] = DIR_SEPARATOR_CHAR;
45 }
46 i++;
47 }
48 return(newpath);
49 }
50
51 #define TRANSFER_SIZE (65536)
52
53 int mkdir_p(char* path)
54 {
55 if (chdir(path) == 0)
56 {
57 return(0);
58 }
59 if (MKDIR(path) != 0)
60 {
61 perror("Failed to create directory");
62 exit(1);
63 }
64 if (chdir(path) != 0)
65 {
66 perror("Failed to change directory");
67 exit(1);
68 }
69 return(0);
70 }
71
72 int main(int argc, char* argv[])
73 {
74 char* path1;
75 char* csec;
76 char buf[256];
77
78 if (argc != 2)
79 {
80 fprintf(stderr, "Too many arguments\n");
81 exit(1);
82 }
83
84 path1 = convert_path(argv[1]);
85
86 if (isalpha(path1[0]) && path1[1] == ':' && path1[2] == DIR_SEPARATOR_CHAR)
87 {
88 csec = strtok(path1, DIR_SEPARATOR_STRING);
89 sprintf(buf, "%s\\", csec);
90 chdir(buf);
91 csec = strtok(NULL, DIR_SEPARATOR_STRING);
92 }
93 else if (path1[0] == DIR_SEPARATOR_CHAR)
94 {
95 chdir(DIR_SEPARATOR_STRING);
96 csec = strtok(path1, DIR_SEPARATOR_STRING);
97 }
98 else
99 {
100 csec = strtok(path1, DIR_SEPARATOR_STRING);
101 }
102
103 while (csec != NULL)
104 {
105 mkdir_p(csec);
106 csec = strtok(NULL, DIR_SEPARATOR_STRING);
107 }
108
109 exit(0);
110 }