Mercurial > hg > octave-lyh > gnulib-hg
changeset 11924:10d064d93551
fts: fts_close now fails also when closing a dir file descriptor fails
* lib/fts.c (fts_close): Detect close failure, not just fchdir failure,
and propagate to caller, along with errno.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Tue, 01 Sep 2009 11:18:07 +0200 |
parents | 61821cbbceb2 |
children | 4934b28baa2b |
files | ChangeLog lib/fts.c |
diffstat | 2 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-09-01 Jim Meyering <meyering@redhat.com> + fts: fts_close now fails also when closing a dir file descriptor fails + * lib/fts.c (fts_close): Detect close failure, not just fchdir failure, + and propagate to caller, along with errno. + announce-gen: correct formatting in --help output * build-aux/announce-gen (usage): Move the one-line description in --help output "up", to where it belongs, just after Usage:.
--- a/lib/fts.c +++ b/lib/fts.c @@ -606,14 +606,20 @@ if (ISSET(FTS_CWDFD)) { if (0 <= sp->fts_cwd_fd) - close (sp->fts_cwd_fd); + if (close (sp->fts_cwd_fd)) + saved_errno = errno; } else if (!ISSET(FTS_NOCHDIR)) { /* Return to original directory, save errno if necessary. */ if (fchdir(sp->fts_rfd)) saved_errno = errno; - close(sp->fts_rfd); + + /* If close fails, record errno only if saved_errno is zero, + so that we report the probably-more-meaningful fchdir errno. */ + if (close (sp->fts_rfd)) + if (saved_errno == 0) + saved_errno = errno; } fd_ring_clear (&sp->fts_fd_ring);