Skip to content

Instantly share code, notes, and snippets.

/server.c Secret

Created August 31, 2016 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d8e90334032d3a4deffa9db36d4deead to your computer and use it in GitHub Desktop.
Save anonymous/d8e90334032d3a4deffa9db36d4deead to your computer and use it in GitHub Desktop.
server.c - shared from CS50 IDE
/**
* 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