Home | History | Annotate | Line # | Download | only in c
      1 /* Check that basic (ll|f)seek sim functionality works.  Also uses basic
      2    file open/write functionality.  */
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <string.h>
      6 
      7 int
      8 main (void)
      9 {
     10   FILE *f;
     11   const char fname[] = "sk1test.dat";
     12   const char tsttxt[]
     13     = "A random line of text, used to test correct read, write and seek.\n";
     14   char buf[sizeof tsttxt] = "";
     15 
     16   f = fopen (fname, "w");
     17   if (f == NULL
     18       || fwrite (tsttxt, 1, strlen (tsttxt), f) != strlen (tsttxt)
     19       || fclose (f) != 0)
     20     {
     21       printf ("fail\n");
     22       exit (1);
     23     }
     24 
     25   /* Using "rb" to make this test similar to the use in genconf.c in
     26      GhostScript.  */
     27   f = fopen (fname, "rb");
     28   if (f == NULL
     29       || fseek (f, 0L, SEEK_END) != 0
     30       || ftell (f) != strlen (tsttxt))
     31     {
     32       printf ("fail\n");
     33       exit (1);
     34     }
     35 
     36   rewind (f);
     37   if (fread (buf, 1, strlen (tsttxt), f) != strlen (tsttxt)
     38       || strcmp (buf, tsttxt) != 0
     39       || fclose (f) != 0)
     40     {
     41       printf ("fail\n");
     42       exit (1);
     43     }
     44 
     45   printf ("pass\n");
     46   exit (0);
     47 }
     48