-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmymkdir.c
35 lines (34 loc) · 912 Bytes
/
mymkdir.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
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
void get_cwd(char *cwd){
FILE *fp;
fp = fopen("cwd.txt", "r");
fgets(cwd, 1024, (FILE*)fp);
fclose(fp);
}
int main(int args,char **argv){
for (int i = 1; i <args ; ++i) {
if(argv[i][0]=='/') {//if path is absolute
if(mkdir(argv[i],0700)==0){
printf("Directory successfully created!\n");
}else{
perror("mkdir error");
}
}else{
char cwd[1024];
get_cwd(cwd);
strcat(cwd,"/");
strcat(cwd,argv[i]);
//appending cwd to defined directory
if(mkdir(cwd,0700)==0){
printf("Directory successfully created!\n");
}else{
perror("mkdir error");
fflush(stdout);
}
}
}
return 0;
}