-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileManager.c
48 lines (41 loc) · 961 Bytes
/
fileManager.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
#include "fileManager.h"
int openFile(char filename[], bool inCurrentDir, int right){
int fd_file;
if(inCurrentDir){
char dir[256] = "";
getcwd(dir, sizeof(dir));
strcat(dir, "/");
strcat(dir, filename);
switch(right){
case 0:
fd_file = open(dir, O_RDONLY | O_CREAT | O_NONBLOCK);
case 1:
fd_file = open(dir, O_WRONLY | O_CREAT | O_NONBLOCK);
case 2:
fd_file = open(dir, O_RDWR | O_CREAT | O_NONBLOCK);
}
}else{
switch(right){
case 0:
fd_file = open(dir, O_RDONLY | O_CREAT | O_NONBLOCK);
case 1:
fd_file = open(dir, O_WRONLY | O_CREAT | O_NONBLOCK);
case 2:
fd_file = open(dir, O_RDWR | O_CREAT | O_NONBLOCK);
}
}
return fd_file;
}
void closeFile(int fd_file){
close(fd_file);
}
int initDebug(char debugFile[]){
int fd_debug = openFile(debugFile, false);
if(fd_debug < 0){
perror("File not charged");
exit(0);
}
//Checkpoint
write(fd_debug, "..........", 10);
return fd_debug;
}