This source file includes following definitions.
- test_open
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #if __GLIBC__ && defined __always_inline
25 # define ALWAYS_INLINE __always_inline
26 #else
27 # define ALWAYS_INLINE
28 #endif
29
30
31
32
33
34
35
36 static ALWAYS_INLINE int
37 test_open (int (*func) (char const *, int, ...), bool print)
38 {
39 int fd;
40
41
42 unlink (BASE "file");
43 unlink (BASE "e.exe");
44 unlink (BASE "link");
45
46
47 errno = 0;
48 ASSERT (func ("nonexist.ent/", O_CREAT | O_RDONLY, 0600) == -1);
49 ASSERT (errno == ENOTDIR || errno == EISDIR || errno == ENOENT
50 || errno == EINVAL);
51
52
53 fd = func (BASE "file", O_CREAT | O_RDONLY, 0600);
54 ASSERT (0 <= fd);
55 ASSERT (close (fd) == 0);
56
57
58 fd = func (BASE "e.exe", O_CREAT | O_RDONLY, 0700);
59 ASSERT (0 <= fd);
60 ASSERT (close (fd) == 0);
61
62
63 errno = 0;
64 ASSERT (func (BASE "file/", O_RDONLY) == -1);
65 ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL);
66
67
68 errno = 0;
69 ASSERT (func (".", O_WRONLY) == -1);
70 ASSERT (errno == EISDIR || errno == EACCES);
71
72
73 fd = func ("/dev/null", O_RDONLY);
74 ASSERT (0 <= fd);
75 {
76 char c;
77 ASSERT (read (fd, &c, 1) == 0);
78 }
79 ASSERT (close (fd) == 0);
80 fd = func ("/dev/null", O_WRONLY);
81 ASSERT (0 <= fd);
82 ASSERT (write (fd, "c", 1) == 1);
83 ASSERT (close (fd) == 0);
84
85
86
87 fd = func (BASE "file", O_NONBLOCK | O_RDONLY);
88 ASSERT (0 <= fd);
89 ASSERT (close (fd) == 0);
90
91
92 if (O_CLOEXEC)
93 {
94
95
96 int i;
97
98 for (i = 0; i < 2; i++)
99 {
100 int flags;
101
102 fd = func (BASE "file", O_CLOEXEC | O_RDONLY);
103 ASSERT (0 <= fd);
104 flags = fcntl (fd, F_GETFD);
105 ASSERT (flags >= 0);
106 ASSERT ((flags & FD_CLOEXEC) != 0);
107 ASSERT (close (fd) == 0);
108 }
109 }
110
111
112 if (symlink (BASE "file", BASE "link") != 0)
113 {
114 ASSERT (unlink (BASE "file") == 0);
115 if (print)
116 fputs ("skipping test: symlinks not supported on this file system\n",
117 stderr);
118 return 77;
119 }
120 errno = 0;
121 ASSERT (func (BASE "link/", O_RDONLY) == -1);
122 ASSERT (errno == ENOTDIR);
123 fd = func (BASE "link", O_RDONLY);
124 ASSERT (0 <= fd);
125 ASSERT (close (fd) == 0);
126
127
128 ASSERT (unlink (BASE "file") == 0);
129 ASSERT (unlink (BASE "e.exe") == 0);
130 ASSERT (unlink (BASE "link") == 0);
131
132 return 0;
133 }