Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char* indexes(const char* path)
- {
- // open the directory
- DIR* dir = opendir(path);
- if (!dir)
- return NULL;
- // search for index.php and index.html in the directory
- struct dirent* names = NULL;
- for (names = readdir(dir); names != NULL; names = readdir(dir))
- {
- if (strcmp(names->d_name, "index.html") == 0)
- {
- char* index = malloc(sizeof(char) * (strlen(path) + strlen(names->d_name) + 1));
- if (!index)
- return NULL;
- index = strcpy(index, path);
- index = strcat(index, names->d_name);
- return index;
- }
- else if (strcmp(names->d_name, "index.php") == 0)
- {
- char* index = malloc(sizeof(char) * (strlen(path) + strlen(names->d_name) + 1));
- if (!index)
- return NULL;
- index = strcpy(index, path);
- index = strcat(index, names->d_name);
- return index;
- }
- }
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement