-
Notifications
You must be signed in to change notification settings - Fork 0
/
files.c
45 lines (35 loc) · 904 Bytes
/
files.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
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
//eventuall move all file related code into here
void read_file();
int main()
{
read_file();
return 0;
}
void read_file()
{
//route requested resource = file name inside of files dir
struct stat sbuf;
char files[] = "./files/pdf1.pdf";
printf("File path %s\n", files);
if (stat(files, &sbuf) < 0)
{
perror("Error locating file");
return;
}
printf("File length of : %s\n\n----------------------------\n%d bytes\n", files, (int)sbuf.st_size);
fflush(stdout);
unsigned char *buffer = calloc(sbuf.st_size, sizeof(unsigned char)); //TODO free
FILE *fp = fopen(files, "r");
if (fp < 0)
perror("Cannot open file");
fread(buffer, sizeof(unsigned char), sbuf.st_size, fp);
fflush(stdout);
free(buffer);
}
void parse_file_type()
{
}