--- modutils-2.4.26/module-init-tools-3.0-pre10/depmod.c~ 2004-01-22 17:28:17.000000000 -0800 +++ modutils-2.4.26/module-init-tools-3.0-pre10/depmod.c 2004-06-14 13:16:12.637390616 -0700 @@ -464,34 +464,35 @@ static struct module *grab_dir(const char *dirname, struct module *next) { - DIR *dir; - struct dirent *dirent; + int n, i; + struct dirent **namelist; - dir = opendir(dirname); - if (!dir) { - warn("Couldn't open directory %s: %s\n", - dirname, strerror(errno)); - return next; + n = scandir(dirname, &namelist, NULL, alphasort); + if (n < 0) { + warn("Couldn't scan directory %s: %s\n", + dirname, strerror(errno)); + return next; } - while ((dirent = readdir(dir)) != NULL) { - if (smells_like_module(dirent->d_name)) - next = grab_module(dirname, dirent->d_name, next); - else if (!streq(dirent->d_name, ".") - && !streq(dirent->d_name, "..")) { + while (n--) { + if (smells_like_module(namelist[n]->d_name)) + next = grab_module(dirname, namelist[n]->d_name, next); + else if (!streq(namelist[n]->d_name, ".") + && !streq(namelist[n]->d_name, "..")) { struct stat st; char subdir[strlen(dirname) + 1 - + strlen(dirent->d_name) + 1]; - sprintf(subdir, "%s/%s", dirname, dirent->d_name); + + strlen(namelist[n]->d_name) + 1]; + sprintf(subdir, "%s/%s", dirname, namelist[n]->d_name); if (lstat(subdir, &st) != 0) warn("Couldn't stat %s: %s\n", subdir, strerror(errno)); else if (S_ISDIR(st.st_mode)) next = grab_dir(subdir, next); } + free(namelist[n]); } - closedir(dir); + free(namelist); return next; }