aboutsummaryrefslogtreecommitdiff
path: root/io/ftw.c
diff options
context:
space:
mode:
Diffstat (limited to 'io/ftw.c')
-rw-r--r--io/ftw.c22
1 files changed, 13 insertions, 9 deletions
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;
}
}