blob: a6da86b0aa94a4800f294f3af56fa8f8109dceea (
plain)
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
|
int fileSize(FILE* fp)
{
//Size of file in bytes
int sz;
fseek(fp, 0L, SEEK_END);
sz = ftell(fp);
fseek(fp, 0L, SEEK_SET);
return sz;
}
char* fileContents(char* fname)
{
//Contents of a file
FILE* fp = fopen(fname, "r");
int sz = fileSize(fp);
char* buffer = malloc(sz);
fread(buffer, sz, 1, fp);
fclose(fp);
return buffer;
}
int exists(char* filename)
{
return access(filename, F_OK) != -1;
}
void touch(char* filename)
{
if (exists(filename))
return;
FILE *fp;
fp = fopen(filename, "w");
fclose(fp);
}
|