aboutsummaryrefslogtreecommitdiff
path: root/dirent
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-09-28 21:19:53 +0000
committerUlrich Drepper <drepper@redhat.com>2005-09-28 21:19:53 +0000
commit1812d50bc9ad034c8406f5e3de83b5a6c668f3a9 (patch)
tree54c88f0ffa5e7ccdece3941a630f5c19f59d3f70 /dirent
parenta898514259e9fef06feddbe74df4d11fb94baf66 (diff)
downloadglibc-1812d50bc9ad034c8406f5e3de83b5a6c668f3a9.tar
glibc-1812d50bc9ad034c8406f5e3de83b5a6c668f3a9.tar.gz
glibc-1812d50bc9ad034c8406f5e3de83b5a6c668f3a9.tar.bz2
glibc-1812d50bc9ad034c8406f5e3de83b5a6c668f3a9.zip
* dirent/dirent.h: Declare fdopendir.
* dirent/Versions: Export fdopendir for GLIBC_2.4. * dirent/Makefile (routines): Add fdopendir. (tests): Add tst-fdopendir. * dirent/tst-fdopendir.c: New file. * include/dirent.h: Declare __alloc_dir. * sysdeps/generic/fdopendir.c: New file. * sysdeps/unix/fdopendir.c: New file. * sysdeps/unix/opendir.c: Split off back part of opendir into new function __alloc_dir.
Diffstat (limited to 'dirent')
-rw-r--r--dirent/Versions3
-rw-r--r--dirent/dirent.h10
-rw-r--r--dirent/tst-fdopendir.c124
3 files changed, 136 insertions, 1 deletions
diff --git a/dirent/Versions b/dirent/Versions
index 9d96caeb36..41c1584426 100644
--- a/dirent/Versions
+++ b/dirent/Versions
@@ -41,4 +41,7 @@ libc {
# g*
getdirentries64;
}
+ GLIBC_2.4 {
+ fdopendir;
+ }
}
diff --git a/dirent/dirent.h b/dirent/dirent.h
index a5e8a004e2..ed4147dbca 100644
--- a/dirent/dirent.h
+++ b/dirent/dirent.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2000, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2000, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -134,6 +134,14 @@ typedef struct __dirstream DIR;
marked with __THROW. */
extern DIR *opendir (__const char *__name) __nonnull ((1));
+#ifdef __USE_GNU
+/* Same as opendir, but open the stream on the file descriptor FD.
+
+ This function is a possible cancellation point and therefore not
+ marked with __THROW. */
+extern DIR *fdopendir (int __fd);
+#endif
+
/* Close the directory stream DIRP.
Return 0 if successful, -1 if not.
diff --git a/dirent/tst-fdopendir.c b/dirent/tst-fdopendir.c
new file mode 100644
index 0000000000..3cf315d85c
--- /dev/null
+++ b/dirent/tst-fdopendir.c
@@ -0,0 +1,124 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <stdbool.h>
+#include <string.h>
+
+
+static int
+do_test (void)
+{
+ char fname[] = "/tmp/jXXXXXX";
+ int fd = mkstemp (fname);
+ if (fd == -1)
+ {
+ puts ("mkstemp failed");
+ return 1;
+ }
+
+ write (fd, "hello", 5);
+ close (fd);
+
+ struct stat64 st;
+ if (stat64 (fname, &st) == -1)
+ {
+ puts ("first stat failed");
+ return 0;
+ }
+
+ /* Make sure there is enough time between the creation and the access. */
+ sleep (2);
+
+ fd = open (fname, O_RDONLY | O_NOATIME);
+ if (fd == -1)
+ {
+ puts ("first open failed");
+ return 1;
+ }
+
+ char buf[5];
+ read(fd, buf, sizeof (buf));
+ close(fd);
+
+ struct stat64 st2;
+ if (stat64 (fname, &st2) == -1)
+ {
+ puts ("second stat failed");
+ return 0;
+ }
+
+ bool no_noatime = false;
+#ifdef _STATBUF_ST_NSEC
+ if (st.st_atim.tv_sec != st2.st_atim.tv_sec
+ || st.st_atim.tv_nsec != st2.st_atim.tv_nsec)
+#else
+ if (st.st_atime != st2.st_atime)
+#endif
+ {
+ puts ("file atime changed");
+ no_noatime = true;
+ }
+
+ unlink(fname);
+
+ strcpy(fname, "/tmp/dXXXXXX");
+ char *d = mkdtemp (fname);
+ if (d == NULL)
+ {
+ puts ("mkdtemp failed");
+ return 1;
+ }
+
+ if (stat64 (d, &st) == -1)
+ {
+ puts ("third stat failed");
+ return 0;
+ }
+ sleep (2);
+
+ fd = open64 (d, O_RDONLY|O_NDELAY|O_DIRECTORY|O_NOATIME);
+ if (fd == -1)
+ {
+ puts ("second open failed");
+ return 1;
+ }
+ DIR *dir = fdopendir (fd);
+ if (dir == NULL)
+ {
+ puts ("fdopendir failed");
+ return 1;
+ }
+
+ struct dirent *de;
+ while ((de = readdir (dir)) != NULL)
+ ;
+
+ closedir (dir);
+
+ if (stat64 (d, &st2) == -1)
+ {
+ puts ("fourth stat failed");
+ return 0;
+ }
+#ifdef _STATBUF_ST_NSEC
+ if (!no_noatime
+ && (st.st_atim.tv_sec != st2.st_atim.tv_sec
+ || st.st_atim.tv_nsec != st2.st_atim.tv_nsec))
+#else
+ if (!no_noatime && st.st_atime != st2.st_atime)
+#endif
+ {
+ puts ("directory atime changed");
+ return 1;
+ }
+
+ rmdir(fname);
+
+ return 0;
+}
+
+#define TIMEOUT 6
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"