Back to index

glibc  2.9
tst-ext2.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdio_ext.h>
00003 
00004 
00005 static char *fname;
00006 
00007 #define PREPARE(argc, argv) \
00008   do {                                                         \
00009     int fd = create_temp_file ("tst-ext2", &fname);                   \
00010     if (fd == -1)                                              \
00011       {                                                               \
00012        puts ("cannot create temporary file");                         \
00013        exit (1);                                               \
00014       }                                                               \
00015     close (fd);                                                       \
00016   } while (0)
00017 
00018 
00019 static int
00020 do_test (void)
00021 {
00022   int res = 0;
00023 
00024   FILE *fp;
00025 
00026   fp = fopen (fname, "w");
00027   printf ("Initial state for write-only stream: %d %d\n",
00028           __freading (fp) != 0, __fwriting (fp) != 0);
00029   res |= ((__freading (fp) != 0) != 0
00030          || (__fwriting (fp) != 0) != 1);
00031   fclose (fp);
00032 
00033   fp = fopen (fname, "r");
00034   printf ("Initial state for read-only stream:  %d %d\n",
00035           __freading (fp) != 0, __fwriting (fp) != 0);
00036   res |= ((__freading (fp) != 0) != 1
00037          || (__fwriting (fp) != 0) != 0);
00038   fclose (fp);
00039 
00040   fp = fopen (fname, "r+");
00041   printf ("Initial state for read-write stream: %d %d\n",
00042           __freading (fp) != 0, __fwriting (fp) != 0);
00043   res |= ((__freading (fp) != 0) != 0
00044          || (__fwriting (fp) != 0) != 0);
00045   fclose (fp);
00046 
00047   fp = fopen (fname, "w+");
00048   printf ("Initial state for read-write stream: %d %d\n",
00049           __freading (fp) != 0, __fwriting (fp) != 0);
00050   res |= ((__freading (fp) != 0) != 0
00051          || (__fwriting (fp) != 0) != 0);
00052   fclose (fp);
00053 
00054   return res;
00055 }
00056 
00057 #define TEST_FUNCTION do_test ()
00058 #include "../test-skeleton.c"