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