#pragma once #include #include #include #include #include #include #ifdef NO_GC #include #define malloc(n) GC_malloc(n) #else #include #endif char* 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 ""; } char* buf; fseek(fp, 0, SEEK_END); int length = ftell(fp); rewind(fp); buf = (char*)malloc(sizeof(char) * (length + 1)); fread(buf, sizeof(char), length, fp); fclose(fp); char* tmp = buf; return tmp; } void* readFileBin(int* len, 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; struct stat st; stat(path, &st); int length = st.st_size; *len = length; buf = (void*)malloc(sizeof(int) * (length + 1)); fread(buf, sizeof(int), length, fp); fclose(fp); void* tmp = buf; return tmp; }