-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkdir.c
69 lines (47 loc) · 1.1 KB
/
mkdir.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <dirent.h>
#include <sys/types.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
char cwdir[1000];
int main(int argc, char* args[]){
if(args[1] != NULL && strcmp(args[1],"--help") == 0){
getcwd(cwdir,sizeof(cwdir));
strcat(cwdir,"/");
strcat(cwdir,"mkdir.txt");
FILE *fp = fopen(cwdir, "r");
if(!fp) {
perror("fopen");
exit(1);
}
char ch;
while((ch = fgetc(fp)) != EOF){
printf("%c", ch);
}
fclose(fp);
return 0;
}
if(args[1] != NULL && strcmp(args[1],"-v") == 0){
int stat = mkdir(args[2], 0777);
if(stat==-1)
{
perror("+--- Error in mkdir \n");
return 0;
}
printf("mkdir: created directory %s\n", args[2]);
return 0;
}
int stat = mkdir(args[1], 0777);
if(stat==-1)
{
perror("+--- Error in mkdir \n");
}
return 0;
}