summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/fts.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index 1ca8334..8083a88 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -515,7 +515,7 @@ FTSENT *
fts_children(FTS *sp, int instr)
{
FTSENT *p;
- int fd;
+ int fd, rc, serrno;
if (instr != 0 && instr != FTS_NAMEONLY) {
errno = EINVAL;
@@ -571,11 +571,14 @@ fts_children(FTS *sp, int instr)
if ((fd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
return (NULL);
sp->fts_child = fts_build(sp, instr);
- if (fchdir(fd)) {
- (void)_close(fd);
- return (NULL);
- }
+ serrno = (sp->fts_child == NULL) ? errno : 0;
+ rc = fchdir(fd);
+ if (rc < 0 && serrno == 0)
+ serrno = errno;
(void)_close(fd);
+ errno = serrno;
+ if (rc < 0)
+ return (NULL);
return (sp->fts_child);
}
OpenPOWER on IntegriCloud