]> git.ipfire.org Git - thirdparty/glibc.git/blame - dirent/bug-readdir1.c
Fix __getcwd rewinddir namespace (bug 17584).
[thirdparty/glibc.git] / dirent / bug-readdir1.c
CommitLineData
05ae4d6a
UD
1#include <dirent.h>
2#include <errno.h>
3#include <errno.h>
4#include <stdio.h>
5#include <stdlib.h>
9d263d72 6#include <unistd.h>
05ae4d6a
UD
7#include <sys/types.h>
8
9
10int
11main (void)
12{
13 DIR *dirp;
14 struct dirent* ent;
15
16 /* open a dir stream */
17 dirp = opendir ("/tmp");
18 if (dirp == NULL)
19 {
20 if (errno == ENOENT)
21 exit (0);
22
23 perror ("opendir");
24 exit (1);
25 }
26
bf6fc6c1
UD
27 /* close the directory file descriptor, making it invalid */
28 if (close (dirfd (dirp)) != 0)
05ae4d6a 29 {
bf6fc6c1
UD
30 puts ("could not close directory file descriptor");
31 /* This is not an error. It is not guaranteed this is possible. */
32 return 0;
05ae4d6a
UD
33 }
34
35 ent = readdir (dirp);
36
37 return ent != NULL || errno != EBADF;
38}