]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
2007-02-21 Ulrich Drepper <drepper@redhat.com>
authorJakub Jelinek <jakub@redhat.com>
Thu, 12 Jul 2007 14:57:39 +0000 (14:57 +0000)
committerJakub Jelinek <jakub@redhat.com>
Thu, 12 Jul 2007 14:57:39 +0000 (14:57 +0000)
[BZ #4076]
* io/ftw.c (ftw_startup): Handle special case of FTW_CHDIR in /.
(open_dir_stream): Likewise.
* io/Makefile (tests): Add bug-ftw5.
* io/bug-ftw5.c: New file.

ChangeLog
io/Makefile
io/bug-ftw5.c [new file with mode: 0644]
io/ftw.c

index 5e01cc1647e3f9b4b56cbf2311509937753dcf50..431be14395bb43d0f6b27a4cc86602554f9343d1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-02-21  Ulrich Drepper  <drepper@redhat.com>
+
+       [BZ #4076]
+       * io/ftw.c (ftw_startup): Handle special case of FTW_CHDIR in /.
+       (open_dir_stream): Likewise.
+       * io/Makefile (tests): Add bug-ftw5.
+       * io/bug-ftw5.c: New file.
+
 2007-02-21  Ulrich Drepper  <drepper@redhat.com>
 
        * nscd/grpcache.c (cache_addgr): In case a record changed on
index d4e04d260ab58b96e2014ea0088086f371361237..7444ef57ebb3c5e81477f86f0b8e36e2a70f486c 100644 (file)
@@ -66,7 +66,7 @@ tests         := test-utime test-stat test-stat2 test-lfs tst-getcwd \
                   tst-openat tst-unlinkat tst-fstatat tst-futimesat \
                   tst-renameat tst-fchownat tst-fchmodat tst-faccessat \
                   tst-symlinkat tst-linkat tst-readlinkat tst-mkdirat \
-                  tst-mknodat tst-mkfifoat tst-ttyname_r
+                  tst-mknodat tst-mkfifoat tst-ttyname_r bug-ftw5
 
 distribute     := ftwtest-sh
 
diff --git a/io/bug-ftw5.c b/io/bug-ftw5.c
new file mode 100644 (file)
index 0000000..c1cd81d
--- /dev/null
@@ -0,0 +1,25 @@
+#include <errno.h>
+#include <ftw.h>
+#include <stdio.h>
+
+static int
+fn (const char *file, const struct stat *sb, int flag, struct FTW *s)
+{
+  puts (file);
+  return FTW_STOP;
+}
+
+static int
+do_test (void)
+{
+  if (nftw ("/", fn, 0, FTW_CHDIR | FTW_ACTIONRETVAL) < 0)
+    {
+      printf ("nftw / FTW_CHDIR: %m\n");
+      return 1;
+    }
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
index 413871744eac8667ab1fe5bcb3a3c6bac3c98434..5e35cb21c13133c8a9dadcd6875bbe1e98dfedba 100644 (file)
--- a/io/ftw.c
+++ b/io/ftw.c
@@ -348,8 +348,17 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
        }
       else
        {
-         const char *name = ((data->flags & FTW_CHDIR)
-                             ? data->dirbuf + data->ftw.base: data->dirbuf);
+         const char *name;
+
+         if (data->flags & FTW_CHDIR)
+           {
+             name = data->dirbuf + data->ftw.base;
+             if (name[0] == '\0')
+               name = ".";
+           }
+         else
+           name = data->dirbuf;
+
          dirp->stream = __opendir (name);
        }
 
@@ -721,9 +730,16 @@ ftw_startup (const char *dir, int is_nftw, void *func, int descriptors,
   /* Get stat info for start directory.  */
   if (result == 0)
     {
-      const char *name = ((data.flags & FTW_CHDIR)
-                         ? data.dirbuf + data.ftw.base
-                         : data.dirbuf);
+      const char *name;
+
+      if (data.flags & FTW_CHDIR)
+       {
+         name = data.dirbuf + data.ftw.base;
+         if (name[0] == '\0')
+           name = ".";
+       }
+      else
+       name = data.dirbuf;
 
       if (((flags & FTW_PHYS)
           ? LXSTAT (_STAT_VER, name, &st)