Advertisement
Guest User

Untitled

a guest
May 23rd, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. char* indexes(const char* path)
  2. {
  3.     // open the directory
  4.     DIR* dir = opendir(path);
  5.     if (!dir)
  6.         return NULL;
  7.    
  8.     // search for index.php and index.html in the directory
  9.     struct dirent* names = NULL;
  10.        
  11.     for (names = readdir(dir); names != NULL; names = readdir(dir))
  12.     {
  13.        
  14.         if (strcmp(names->d_name, "index.html") == 0)
  15.         {
  16.             char* index = malloc(sizeof(char) * (strlen(path) + strlen(names->d_name) + 1));
  17.             if (!index)
  18.                 return NULL;
  19.                
  20.             index = strcpy(index, path);
  21.             index = strcat(index, names->d_name);
  22.             return index;
  23.         }
  24.        
  25.         else if (strcmp(names->d_name, "index.php") == 0)
  26.         {
  27.             char* index = malloc(sizeof(char) * (strlen(path) + strlen(names->d_name) + 1));
  28.             if (!index)
  29.                 return NULL;
  30.                
  31.             index = strcpy(index, path);
  32.             index = strcat(index, names->d_name);
  33.             return index;
  34.         }
  35.     }
  36.    
  37.     return NULL;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement