-
Notifications
You must be signed in to change notification settings - Fork 0
/
jabberwocky_create.c
44 lines (37 loc) · 1.01 KB
/
jabberwocky_create.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include "jabberwocky_func.h"
int main(int argc, char *argv[]){
if (argc != 2){
printf("\nUsage: %s, <base name>\n", argv[0]);
exit(-1);
}
char *dbName = argv[1];
if (!isDBExist(dbName)){
printf("\nDatabase already exists or an error occurred.\n");
exit(-1);
}
char *dbPath = getDBPath();
strcat(dbPath, "/");
strcat(dbPath, dbName);
if(mkdir(dbPath, 0744)){
perror("\nError in creating database");
exit(-1);
}
strcat(dbPath, "/.");
strcat(dbPath, dbName);// expansion - solved
int fd = open(dbPath, O_WRONLY | O_CREAT | O_TRUNC, 0744);
if (fd < 0){
perror("\nError in creating database");
exit(-1);
}
free(dbPath);
close(fd);
return 0;
}