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
22
23 #define _GL_NO_LARGE_FILES
24 #include "freadable.h"
25
26 #include <stdio.h>
27
28 #include "macros.h"
29
30 #define TESTFILE "t-freadable.tmp"
31
32 int
33 main ()
34 {
35 FILE *fp;
36
37
38 fp = fopen (TESTFILE, "w");
39 if (fp == NULL)
40 goto skip;
41 ASSERT (!freadable (fp));
42 if (fwrite ("foobarsh", 1, 8, fp) < 8)
43 goto skip;
44 ASSERT (!freadable (fp));
45 if (fclose (fp))
46 goto skip;
47
48
49 fp = fopen (TESTFILE, "r");
50 if (fp == NULL)
51 goto skip;
52 ASSERT (freadable (fp));
53 if (fgetc (fp) != 'f')
54 goto skip;
55 ASSERT (freadable (fp));
56 if (fseek (fp, 2, SEEK_CUR))
57 goto skip;
58 ASSERT (freadable (fp));
59 if (fgetc (fp) != 'b')
60 goto skip;
61 ASSERT (freadable (fp));
62 fflush (fp);
63 ASSERT (freadable (fp));
64 if (fgetc (fp) != 'a')
65 goto skip;
66 ASSERT (freadable (fp));
67 if (fseek (fp, 0, SEEK_END))
68 goto skip;
69 ASSERT (freadable (fp));
70 if (fclose (fp))
71 goto skip;
72
73
74 fp = fopen (TESTFILE, "r+");
75 if (fp == NULL)
76 goto skip;
77 ASSERT (freadable (fp));
78 if (fgetc (fp) != 'f')
79 goto skip;
80 ASSERT (freadable (fp));
81 if (fseek (fp, 2, SEEK_CUR))
82 goto skip;
83 ASSERT (freadable (fp));
84 if (fgetc (fp) != 'b')
85 goto skip;
86 ASSERT (freadable (fp));
87 fflush (fp);
88 ASSERT (freadable (fp));
89 if (fgetc (fp) != 'a')
90 goto skip;
91 ASSERT (freadable (fp));
92 if (fputc ('z', fp) != 'z')
93 goto skip;
94 ASSERT (freadable (fp));
95 if (fseek (fp, 0, SEEK_END))
96 goto skip;
97 ASSERT (freadable (fp));
98 if (fclose (fp))
99 goto skip;
100
101
102 fp = fopen (TESTFILE, "a");
103 if (fp == NULL)
104 goto skip;
105 ASSERT (!freadable (fp));
106 if (fwrite ("bla", 1, 3, fp) < 3)
107 goto skip;
108 ASSERT (!freadable (fp));
109 if (fclose (fp))
110 goto skip;
111
112 return 0;
113
114 skip:
115 fprintf (stderr, "Skipping test: file operations failed.\n");
116 return 77;
117 }