4 #define TESTFILE "/tmp/test.dat"
12 puts ("\nFile seek test");
13 fp
= fopen (TESTFILE
, "w");
20 for (i
= 0; i
< 256; i
++)
22 if (freopen (TESTFILE
, "r", fp
) != fp
)
24 perror ("Cannot open file for reading");
28 for (i
= 1; i
<= 255; i
++)
31 fseek (fp
, (long) -i
, SEEK_END
);
32 if ((j
= getc (fp
)) != 256 - i
)
34 printf ("SEEK_END failed %d\n", j
);
37 if (fseek (fp
, (long) i
, SEEK_SET
))
39 puts ("Cannot SEEK_SET");
42 if ((j
= getc (fp
)) != i
)
44 printf ("SEEK_SET failed %d\n", j
);
47 if (fseek (fp
, (long) i
, SEEK_SET
))
49 puts ("Cannot SEEK_SET");
52 if (fseek (fp
, (long) (i
>= 128 ? -128 : 128), SEEK_CUR
))
54 puts ("Cannot SEEK_CUR");
57 if ((j
= getc (fp
)) != (i
>= 128 ? i
- 128 : i
+ 128))
59 printf ("SEEK_CUR failed %d\n", j
);
65 puts ((i
> 255) ? "Test succeeded." : "Test FAILED!");
66 return (i
> 255) ? 0 : 1;