I'm making a simple LS command in C in a program, when I open the directory for the first time and read it, it works perfectly, but when I call the function a second time, opendir()
seems to sleep or loop infinitely:
int server_list(t_server_data *sd)
{
DIR *dir;
struct dirent *entry;
printf("In list()\n");
printf("Open directory\n");
if ((dir = opendir("./")) == NULL)
perror("Error: opendir()");
printf("Directory opened\n");
while ((entry = readdir(dir)) != NULL)
{
printf("Reading dir...\n");
/* code */
}
closedir(dir);
return (0);
}
Then this is the output I get:
In list()
Open directory
And the program does nothing (waits).