diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2015-06-20 20:54:05 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2015-06-20 20:54:05 +0000 |
commit | 764a9bbee12bbdaefaf9739ed37555fef477eab4 (patch) | |
tree | 4cfe8297f1e4351ab31e41b8fc7194369f14b192 | |
parent | 7705435606cd6e314397a6573a02c5e9bd483f02 (diff) |
Notes
-rw-r--r-- | lib/libc/gen/fts.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 1ca8334acc68..8083a88b86e6 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); } |