about summary refs log tree commit diff
path: root/dirent/bug-readdir1.c
diff options
context:
space:
mode:
Diffstat (limited to 'dirent/bug-readdir1.c')
-rw-r--r--dirent/bug-readdir1.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/dirent/bug-readdir1.c b/dirent/bug-readdir1.c
new file mode 100644
index 0000000000..f9c609cc98
--- /dev/null
+++ b/dirent/bug-readdir1.c
@@ -0,0 +1,36 @@
+#include <dirent.h>
+#include <errno.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+
+int
+main (void)
+{
+  DIR *dirp;
+  struct dirent* ent;
+
+  /* open a dir stream */
+  dirp = opendir ("/tmp");
+  if (dirp == NULL)
+    {
+      if (errno == ENOENT)
+	exit (0);
+
+      perror ("opendir");
+      exit (1);
+    }
+
+  /* close the dir stream, making it invalid */
+  if (closedir (dirp))
+    {
+      perror ("closedir");
+      exit (1);
+    }
+
+  ent = readdir (dirp);
+
+  return ent != NULL || errno != EBADF;
+}