-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmake_dir.c
More file actions
33 lines (27 loc) · 686 Bytes
/
make_dir.c
File metadata and controls
33 lines (27 loc) · 686 Bytes
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
// reimplementation of the mkdir linux command
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
void print_error(char *this, char *dirname){
fprintf(stderr, "%s cannot make directory %s\n%s\n",
this, dirname, strerror(errno));
exit(EXIT_FAILURE);
}
void print_usage(char *this){
fprintf(stderr, "SYNTAX ERROR:\nUsage: %s [dir_name]", this);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]){
errno = 0;
if(argc == 2){
if(mkdir(argv[1], (S_IRWXG | S_IRWXU))){
print_error(argv[0], argv[1]);
}
}
else{
print_usage(argv[0]);
}
return 0;
}