From 9378784537d0a4cd4e630aa360d0ae838dfcf500 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 4 Nov 2003 21:11:41 +0000 Subject: Update. 2003-11-04 Jakub Jelinek * io/ftw.c (ftw_dir): Close dir if callback with FTW_D type returns non-zero. * io/Makefile (tests): Add bug-ftw4. * io/bug-ftw4.c: New test. --- io/ftw.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'io/ftw.c') diff --git a/io/ftw.c b/io/ftw.c index c7c2038c06..6d5cedf63e 100644 --- a/io/ftw.c +++ b/io/ftw.c @@ -476,23 +476,27 @@ ftw_dir (struct ftw_data *data, struct STAT *st) { result = (*data->func) (data->dirbuf, st, FTW_D, &data->ftw); if (result != 0) - return result; - } - - /* If necessary, change to this directory. */ - if (data->flags & FTW_CHDIR) - { - if (__fchdir (dirfd (dir.stream)) < 0) { - int save_err = errno; + int save_err; +fail: + save_err = errno; __closedir (dir.stream); __set_errno (save_err); if (data->actdir-- == 0) data->actdir = data->maxdir - 1; data->dirstreams[data->actdir] = NULL; + return result; + } + } - return -1; + /* If necessary, change to this directory. */ + if (data->flags & FTW_CHDIR) + { + if (__fchdir (dirfd (dir.stream)) < 0) + { + result = -1; + goto fail; } } -- cgit v1.2.3