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