about summary refs log tree commit diff
path: root/io/ftw.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-11-04 21:11:41 +0000
committerUlrich Drepper <drepper@redhat.com>2003-11-04 21:11:41 +0000
commit9378784537d0a4cd4e630aa360d0ae838dfcf500 (patch)
treee1607d2c9565d13cc916214f1c4c9a603a0202d3 /io/ftw.c
parent1c15327821aee947476284374a96c7ebb64dc0d6 (diff)
downloadglibc-9378784537d0a4cd4e630aa360d0ae838dfcf500.tar.gz
glibc-9378784537d0a4cd4e630aa360d0ae838dfcf500.tar.xz
glibc-9378784537d0a4cd4e630aa360d0ae838dfcf500.zip
Update.
2003-11-04  Jakub Jelinek  <jakub@redhat.com>

	* 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.
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;
 	}
     }