Regardless of what I do, I can't seem to get the indexes function working. It always seems to return null.
char* indexes(const char* path) {
char* inPHP = malloc(sizeof(char) * strlen(path) + 11);
char* inHTML = malloc(sizeof(char) * strlen(path) + 11);
strcpy(inPHP, path);
strcat(inPHP, "/index.php");
strcpy(inHTML, path);
strcat(inHTML, "/index.html");
if (access(inPHP, R_OK) != -1 ) {
return inPHP;
free(inPHP);
free(inHTML);
} else if (access(inHTML, R_OK) != -1) {
return inHTML;
free(inPHP);
free(inHTML);
} else {
free(inHTML);
free(inPHP);
return NULL;
}
}
Also could someone please explain to me how I could more efficiently free my malloc'd memory? From my understanding the program will stop running after the return function and my free functions are after I return inPHP and inHTML. How could I free those functions while still being able to return those paths?
EDIT: By the way - I have a folder named test with a "index.html" in the directory my c file is in. I am inputting my "path" as "/test".