/
SystemCalls.h
168 lines (146 loc) · 3.13 KB
/
SystemCalls.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef SYSTEMCALLS_H
#define SYSTEMCALLS_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#define LOG_FILE_NAME ".gatee_log"
#define CD_FILE_NAME ".gatee_cd"
#define READ R_OK
#define WRITE W_OK
#define EXECUTE X_OK
#define PARENT_DIR_NAME "< Parent Directory"
/* Possible prefixes: "< ", "> ", " " */
#define PREFIX_SIZE 1
#define DIR_ID 0
#define DIR_PREFIX ">"
#define FILE_ID 1
#define FILE_PREFIX " "
int i;
/*
* Usage:
*
* char *currentWorkingDirectory = getWorkingDirectory();
*
* printf("%s\n", currentWorkingDirectory);
*/
char * getWorkingDirectory();
/*
* Usage:
*
* changeDirectoryTo("/Users/--something--/Documents");
*/
void changeDirectoryTo(char * directory);
/*
* Usage:
*
* int dirItemCount;
* struct dirent * * directoryContents = getDirectoryContents(getWorkingDirectory(), &dirItemCount);
*
* for (int i = 0; i < dirItemCount; ++i) {
* printf("%s\n", directoryContents[i]->d_name);
* }
*/
struct dirent * * getDirectoryContents(char * directory, int * dirItemCount);
/*
* Usage:
*
* int dirItemCount;
* char * * dirContents;
* getDirectoryContentNames(currentWorkingDirectory, &dirItemCount, &dirContents);
*
* for (int i = 0; i < dirItemCount; ++i) {
* printf("%s\n", dirContents[i]);
* }
*
* Disclaimer 1: Omitting the current directory pointer and renaming the parent
* directory pointer to PARENT_DIR_NAME defined in SystemCalls.h.
*
* Disclaimer 2: If a directory content entry is a directory, it will have a
* DIR_PREFIX appended to the front of it's name. If it is a file, it will
* have a FILE_PREFIX appended to the front of it's name.
*/
void getDirectoryContentNames(char * directory, int * dirItemCount, char * * * dirContentNames);
/*
* Usage:
*
* fileOrDir(--some filename-- == DIR_ID) {
* > it's a directory
* }
*/
int fileOrDir(char * name);
/*
* Usage:
*
* logToFile(--some string--);
*
* Creates the log at the current working directory.
* More info: http://www.cprogramming.com/tutorial/cfileio.html
*/
void logToFile(char * stringToLog);
/*
* Usage:
*
* logToFileAt(--some string--, "/bin/logs");
*/
void logToFileAt(char * stringToLog, char * logFilePath);
/*
* Usage:
*
* logToFileAtRoot(--some string--);
*/
void logToFileAtRoot(char * stringToLog);
/*
* Usage:
*
* canRead("/bin/logs") == 0;
* canRead("/bin/logs/log.txt") == 0;
*/
int canRead(char * filePath);
/*
* Usage:
*
* canWriteTo("/") == 0;
* canWriteTo("/log.txt") == 0;
*/
int canWriteTo(char * filePath);
/*
* Usage:
*
* canExecute("/bin/gatee");
*/
int canExecute(char * filePath);
/*
* Usage:
*
* canAccessTo("/bin/logs/log.txt", READ);
* canAccessTo("/bin/logs/log.txt", WRITE);
* canAccessTo("/bin/gatee", EXECUTE);
*/
int canAccessTo(char * filePath, int accessType);
/*
* Usage:
*
* getNumTerminalRows();
*/
int getNumTerminalRows();
/*
* Usage:
*
* getNumTerminalColumns();
*/
int getNumTerminalColumns();
/*
* Usage:
*
* prepareToExit("/");
*/
void prepareToExit(char * dirToExit);
#endif