2.9
[glibc/nacl-glibc.git] / dirent / bug-readdir1.c
blob4c3521dbb54b9e01f4231ce0eb0a5d32aa3f8be0
1 #include <dirent.h>
2 #include <errno.h>
3 #include <errno.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <sys/types.h>
10 int
11 main (void)
13 DIR *dirp;
14 struct dirent* ent;
16 /* open a dir stream */
17 dirp = opendir ("/tmp");
18 if (dirp == NULL)
20 if (errno == ENOENT)
21 exit (0);
23 perror ("opendir");
24 exit (1);
27 /* close the directory file descriptor, making it invalid */
28 if (close (dirfd (dirp)) != 0)
30 puts ("could not close directory file descriptor");
31 /* This is not an error. It is not guaranteed this is possible. */
32 return 0;
35 ent = readdir (dirp);
37 return ent != NULL || errno != EBADF;