\r processing.
[reactos.git] / reactos / rmkdir.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 char* convert_path(char* origpath)
6 {
7 char* newpath;
8 int i;
9
10 newpath = strdup(origpath);
11
12 i = 0;
13 while (newpath[i] != 0)
14 {
15 #ifdef UNIX_PATHS
16 if (newpath[i] == '\\')
17 {
18 newpath[i] = '/';
19 }
20 #else
21 #ifdef DOS_PATHS
22 if (newpath[i] == '/')
23 {
24 newpath[i] = '\\';
25 }
26 #endif
27 #endif
28 i++;
29 }
30 return(newpath);
31 }
32
33 #define TRANSFER_SIZE (65536)
34
35 int mkdir_p(char* path)
36 {
37 if (chdir(path) == 0)
38 {
39 return(0);
40 }
41 #ifdef UNIX_PATHS
42 if (mkdir(path, 0755) != 0)
43 {
44 perror("Failed to create directory");
45 exit(1);
46 }
47 #else
48 if (mkdir(path) != 0)
49 {
50 perror("Failed to create directory");
51 exit(1);
52 }
53 #endif
54
55 if (chdir(path) != 0)
56 {
57 perror("Failed to change directory");
58 exit(1);
59 }
60 return(0);
61 }
62
63 int main(int argc, char* argv[])
64 {
65 char* path1;
66 FILE* in;
67 FILE* out;
68 char* csec;
69 int is_abs_path;
70
71 if (argc != 2)
72 {
73 fprintf(stderr, "Too many arguments\n");
74 exit(1);
75 }
76
77 path1 = convert_path(argv[1]);
78
79 if (isalpha(path1[0]) && path1[1] == ':' && path1[2] == '/')
80 {
81 csec = strtok(path1, "/");
82 chdir(csec);
83 csec = strtok(NULL, "/");
84 }
85 else if (path1[0] == '/')
86 {
87 chdir("/");
88 csec = strtok(path1, "/");
89 }
90 else
91 {
92 csec = strtok(path1, "/");
93 }
94
95 while (csec != NULL)
96 {
97 mkdir_p(csec);
98 csec = strtok(NULL, "/");
99 }
100
101 exit(0);
102 }