mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
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.)
This commit is contained in:
parent
96a9231927
commit
abab9d360d
1 changed files with 7 additions and 4 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue