diff options
author | rofl0r <rofl0r@users.noreply.github.com> | 2021-10-27 13:40:41 +0000 |
---|---|---|
committer | rofl0r <rofl0r@users.noreply.github.com> | 2021-10-27 13:40:41 +0000 |
commit | abab9d360de19723cdf15346a2fe94e7e75a5304 (patch) | |
tree | 7aa837e93e2456346fc56272b2577eb4323782ad | |
parent | 96a923192726f4ce77b5168a17f7a8355e6f2238 (diff) |
dir_scan: fix wrong assumption that errno can only be changed by readdir()
this breaks ncdu with musl 1.2.2, if the madvise syscall isn't implemented,
in which case realloc sets errno.
if errno is to be used, it needs to be set to 0 and checked after every
single libc call that could modify it.
interestingly, in the condition that the error is set here, ncdu just
prints nothing and silently quits with exit status 0 (success).
(maybe an error is being printed, but before the terminal is put back into
a normal state.)
-rw-r--r-- | src/dir_scan.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/dir_scan.c b/src/dir_scan.c index 87b416b..b53e4b9 100644 --- a/src/dir_scan.c +++ b/src/dir_scan.c @@ -162,9 +162,14 @@ static char *dir_read(int *err) { } buf = xmalloc(buflen); - errno = 0; - while((item = readdir(dir)) != NULL) { + while(1) { + errno = 0; + if ((item = readdir(dir)) == NULL) { + if(errno) + *err = 1; + break; + } if(item->d_name[0] == '.' && (item->d_name[1] == 0 || (item->d_name[1] == '.' && item->d_name[2] == 0))) continue; size_t req = off+3+strlen(item->d_name); @@ -175,8 +180,6 @@ static char *dir_read(int *err) { strcpy(buf+off, item->d_name); off += strlen(item->d_name)+1; } - if(errno) - *err = 1; if(closedir(dir) < 0) *err = 1; |