diff --git a/foundation-module/Chapter 1/POSIX Platforms.w b/foundation-module/Chapter 1/POSIX Platforms.w index c2dcc7f6..db94118b 100644 --- a/foundation-module/Chapter 1/POSIX Platforms.w +++ b/foundation-module/Chapter 1/POSIX Platforms.w @@ -250,12 +250,12 @@ int Platform::readdir(void *D, char *dir_name, char *leafname) { DIR *dirp = (DIR *) D; struct dirent *dp; do { - errno = 0; dp = readdir(dirp); - } while (errno); - if (dp == NULL) return FALSE; - sprintf(path_to, "%s%c%s", dir_name, FOLDER_SEPARATOR, dp->d_name); - rv = stat(path_to, &file_status); + if (dp == NULL) return FALSE; + sprintf(path_to, "%s%c%s", dir_name, FOLDER_SEPARATOR, dp->d_name); + errno = 0; + rv = stat(path_to, &file_status); + } while (dp && (errno == ENOENT)); if (rv != 0) return FALSE; if (S_ISDIR(file_status.st_mode)) sprintf(leafname, "%s/", dp->d_name); else strcpy(leafname, dp->d_name);