Advertisement
DragonOsman

indexes() in server.c

Dec 1st, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. char* indexes(const char* path)
  2. {
  3.     char* html_path = realloc((char*)path, strlen("index.html") + strlen(path) + 1);
  4.     char* php_path = realloc((char*)path, strlen("index.php") + strlen(path) + 1);
  5.     char* index_html = "index.html";
  6.     char* index_php = "index.php";
  7.     if (access(index_html, F_OK) == 0)
  8.     {
  9.         strcpy((char*)path, html_path);
  10.         free(html_path);
  11.         free(php_path);
  12.         return strcat((char*)path, index_html);
  13.     }
  14.     else if (access(index_php, F_OK) == 0)
  15.     {
  16.         strcpy((char*)path, php_path);
  17.         free(html_path);
  18.         free(php_path);
  19.         return strcat((char*)path, index_php);
  20.     }
  21.     free(php_path);
  22.     free(html_path);
  23.     return NULL;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement