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