Skip to content

Commit

Permalink
move test to stat; only loop on ENOENT
Browse files Browse the repository at this point in the history
  • Loading branch information
zedlopez committed Jun 7, 2023
1 parent b52e218 commit 8bf0ab3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions foundation-module/Chapter 1/POSIX Platforms.w
Expand Up @@ -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);
Expand Down

0 comments on commit 8bf0ab3

Please sign in to comment.