-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrmfs.c
More file actions
39 lines (35 loc) · 1 KB
/
rmfs.c
File metadata and controls
39 lines (35 loc) · 1 KB
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
#include <stdio.h>
#include <getopt.h>
#include "filesystem.h"
int main(int argc, char *argv[]){
if(argc != 2) {
puts("Not valid no of arguments! Check \"./rmfs --help\" for proper use.");
return INCORRECT_ARG;
}
static struct option long_opt[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
char ch;
while((ch = getopt_long(argc, argv, "", long_opt, NULL)) != -1) {
switch(ch){
case 'h':
printf("Usage:\n");
printf("./rmfs --help to show this message\n");
printf("./rmfs your_filesys_name to remove file system\n");
return 0;
case '?':
break;
}
}
FILE *fp;
char *name = argv[1];
if(fp = fopen(name, "r")) {
fclose(fp);
remove(name);
printf("Successfully removed %s!\n", name);
return 0;
}
puts("There's no such file system!");
return FILE_NOT_EXISTING;
}