This source file includes following definitions.
- test_fopen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <errno.h>
22 #include <unistd.h>
23
24 #include "macros.h"
25
26
27
28 static int
29 test_fopen (void)
30 {
31 FILE *f;
32
33 unlink (BASE "file");
34
35
36 errno = 0;
37 ASSERT (fopen (BASE "file", "r") == NULL);
38 ASSERT (errno == ENOENT);
39
40
41 f = fopen (BASE "file", "w");
42 ASSERT (f);
43 ASSERT (fclose (f) == 0);
44
45
46 errno = 0;
47 ASSERT (fopen (BASE "file/", "r") == NULL);
48 ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL);
49
50 errno = 0;
51 ASSERT (fopen (BASE "file/", "r+") == NULL);
52 ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL);
53
54
55 errno = 0;
56 ASSERT (fopen ("nonexist.ent/", "w") == NULL);
57 ASSERT (errno == ENOTDIR || errno == EISDIR || errno == ENOENT
58 || errno == EINVAL);
59
60
61 errno = 0;
62 ASSERT (fopen (".", "w") == NULL);
63 ASSERT (errno == EISDIR || errno == EINVAL || errno == EACCES);
64
65 errno = 0;
66 ASSERT (fopen ("./", "w") == NULL);
67 ASSERT (errno == EISDIR || errno == EINVAL || errno == EACCES);
68
69 errno = 0;
70 ASSERT (fopen (".", "r+") == NULL);
71 ASSERT (errno == EISDIR || errno == EINVAL || errno == EACCES);
72
73 errno = 0;
74 ASSERT (fopen ("./", "r+") == NULL);
75 ASSERT (errno == EISDIR || errno == EINVAL || errno == EACCES);
76
77
78 f = fopen ("/dev/null", "r");
79 ASSERT (f);
80 ASSERT (fclose (f) == 0);
81 f = fopen ("/dev/null", "w");
82 ASSERT (f);
83 ASSERT (fclose (f) == 0);
84
85
86 ASSERT (unlink (BASE "file") == 0);
87
88 return 0;
89 }