Hi I got a bit stuck on indexes and load. My parse()
and lookup()
functions seem to work fine now and also check50
is happy. But I feel I am missing something on indexes or load or maybe both. Maybe someone has an idea? Thank you!!
bool load(FILE* file, BYTE** content, size_t* length)
{
int size = 0;
BYTE* block = malloc(sizeof(BYTE));
if(block == NULL)
{
return false;
}
//read file
for(int c = fgetc(file); c !=EOF; c= fgetc(file))
{
block[size] = c;
size++;
block = realloc(block, (size+1));
}
*content = block;
*length =size;
return true;
}
char* indexes(const char* path)
{
//if index.php or index.html exist match them and give the correct output
char* directory = malloc(strlen(path)+10);
strcpy(directory,path);
directory = strcat(directory, "index.php");
directory[strlen(path) + 9] ='\0';
char* directory1 = malloc(strlen(path) + 11);
strcpy(directory1, path);
directory1 = strcat(directory, "index.html");
directory1[strlen(path) + 10] = '\0';
if (access(directory, F_OK) == 0)
{
return directory;
}
else if(access(directory1, F_OK) == 0)
{
return directory1;
}
else
{
return NULL;
}
}