This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "dirent--.h"
22
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <stdio.h>
26 #include <unistd.h>
27
28
29
30
31
32 #define BACKUP_STDERR_FILENO 10
33 #define ASSERT_STREAM myerr
34 #include "macros.h"
35
36 static FILE *myerr;
37
38 int
39 main (void)
40 {
41 int i;
42 DIR *dp;
43
44
45
46
47
48
49 #if HAVE_FDOPENDIR || GNULIB_TEST_FDOPENDIR
50 int dfd;
51 #endif
52
53
54 if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
55 || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
56 return 2;
57
58 #if HAVE_FDOPENDIR || GNULIB_TEST_FDOPENDIR
59 dfd = open (".", O_RDONLY);
60 ASSERT (STDERR_FILENO < dfd);
61 #endif
62
63
64
65 for (i = -1; i <= STDERR_FILENO; i++)
66 {
67 if (0 <= i)
68 ASSERT (close (i) == 0);
69 dp = opendir (".");
70 ASSERT (dp);
71 ASSERT (dirfd (dp) == -1 || STDERR_FILENO < dirfd (dp));
72 ASSERT (closedir (dp) == 0);
73
74 #if HAVE_FDOPENDIR || GNULIB_TEST_FDOPENDIR
75 {
76 int fd = fcntl (dfd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
77 ASSERT (STDERR_FILENO < fd);
78 dp = fdopendir (fd);
79 ASSERT (dp);
80 ASSERT (dirfd (dp) == -1 || STDERR_FILENO < dirfd (dp));
81 ASSERT (closedir (dp) == 0);
82 errno = 0;
83 ASSERT (close (fd) == -1);
84 ASSERT (errno == EBADF);
85 }
86 #endif
87 }
88
89 #if HAVE_FDOPENDIR || GNULIB_TEST_FDOPENDIR
90 ASSERT (close (dfd) == 0);
91 #endif
92
93 return 0;
94 }