Hello,
I do recursive dir scanning for .c files in tree on linux but that one don't work on windows because of that:
So I have to change code and now I have this:Code:if (entry->d_type & DT_DIR)
That code crashes after several loops when come to first file...Code:static void
list_dir(const char *dir_name)
{
DIR *d;
d = opendir(dir_name);
while (1)
{
struct dirent *entry;
struct stat statbuf;
const char *d_name;
entry = readdir(d);
d_name = entry->d_name;
stat(d_name, &statbuf);
if(S_ISDIR(statbuf.st_mode) != 0)
{
if (strcmp (d_name, "..") != 0 && strcmp (d_name, ".") != 0)
{
int path_length;
char path[FILENAME_MAX];
path_length = snprintf (path, FILENAME_MAX, "%s/%s", dir_name, d_name);
if (path_length >= FILENAME_MAX) exit(EXIT_FAILURE);
list_dir (path);
}
}
if (S_ISREG(statbuf.st_mode) != 0)
{
char fullname[FILENAME_MAX] = {0};
sprintf(fullname, "%s/%s", dir_name, d_name);
if (strlen(fullname) >= 2)
{
if (strcmp (".c", & (fullname[strlen(fullname) - 2])) == 0)
{
// it is c file
}
}
}
}
if (closedir(d)) exit(EXIT_FAILURE);
}
Anybody see why and how to fix it?