1 | #include <stdio.h> |
2 | #include <stdio_ext.h> |
3 | |
4 | |
5 | static char *fname; |
6 | |
7 | #define PREPARE(argc, argv) \ |
8 | do { \ |
9 | int fd = create_temp_file ("tst-ext2", &fname); \ |
10 | if (fd == -1) \ |
11 | { \ |
12 | puts ("cannot create temporary file"); \ |
13 | exit (1); \ |
14 | } \ |
15 | close (fd); \ |
16 | } while (0) |
17 | |
18 | |
19 | static int |
20 | do_test (void) |
21 | { |
22 | int res = 0; |
23 | |
24 | FILE *fp; |
25 | |
26 | fp = fopen (fname, "w" ); |
27 | printf (format: "Initial state for write-only stream: %d %d\n" , |
28 | __freading (fp: fp) != 0, __fwriting (fp: fp) != 0); |
29 | res |= ((__freading (fp: fp) != 0) != 0 |
30 | || (__fwriting (fp: fp) != 0) != 1); |
31 | fclose (fp); |
32 | |
33 | fp = fopen (fname, "r" ); |
34 | printf (format: "Initial state for read-only stream: %d %d\n" , |
35 | __freading (fp: fp) != 0, __fwriting (fp: fp) != 0); |
36 | res |= ((__freading (fp: fp) != 0) != 1 |
37 | || (__fwriting (fp: fp) != 0) != 0); |
38 | fclose (fp); |
39 | |
40 | fp = fopen (fname, "r+" ); |
41 | printf (format: "Initial state for read-write stream: %d %d\n" , |
42 | __freading (fp: fp) != 0, __fwriting (fp: fp) != 0); |
43 | res |= ((__freading (fp: fp) != 0) != 0 |
44 | || (__fwriting (fp: fp) != 0) != 0); |
45 | fclose (fp); |
46 | |
47 | fp = fopen (fname, "w+" ); |
48 | printf (format: "Initial state for read-write stream: %d %d\n" , |
49 | __freading (fp: fp) != 0, __fwriting (fp: fp) != 0); |
50 | res |= ((__freading (fp: fp) != 0) != 0 |
51 | || (__fwriting (fp: fp) != 0) != 0); |
52 | fclose (fp); |
53 | |
54 | return res; |
55 | } |
56 | |
57 | #define TEST_FUNCTION do_test () |
58 | #include "../test-skeleton.c" |
59 | |