You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
539 B

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
void* readFile(char* path) {
path++;
if (strlen(path) <= 1) {
printf("/ converted to /index.html\n");
path = (char*)malloc(11);
path = "index.html";
}
FILE* fp = fopen(path, "rb");
if (!(access(path, F_OK) == 0)) {
errno = -1;
return "";
}
void* buf = NULL;
fseek(fp, 0, SEEK_END);
int length = ftell(fp);
rewind(fp);
buf = malloc(sizeof(char) * (length + 1));
fread(buf, sizeof(char), length, fp);
return buf;
}