-
-
Save anonymous/d8e90334032d3a4deffa9db36d4deead to your computer and use it in GitHub Desktop.
server.c - shared from CS50 IDE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks, in order, whether index.php or index.html exists inside of path. | |
* Returns path to first match if so, else NULL. | |
*/ | |
char* indexes(const char* path) | |
{ | |
char path1[strlen(path) + 1]; | |
char path2[strlen(path) + 1]; | |
strcpy(path1, path); | |
strcpy(path2, path); | |
char array[10] = "index.php"; | |
array[9] = '\0'; | |
char array2[11] = "index.html"; | |
array2[10] = '\0'; | |
char try1[strlen(path) + 11]; | |
char try2[strlen(path) + 11]; | |
strcpy(try1 , strcat(path1, array)); | |
strcpy(try2 , strcat(path2, array2)); | |
if(access(try1, F_OK )) | |
{ | |
char* ptr_best = try1; | |
return ptr_best; | |
} | |
else if(access(try2, F_OK )) | |
{ | |
char* ptr_best = try2; | |
return ptr_best; | |
} | |
else | |
{ | |
return NULL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment