about summary refs log tree commit diff
path: root/stdio/test-fseek.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-02-18 01:27:10 +0000
committerRoland McGrath <roland@gnu.org>1995-02-18 01:27:10 +0000
commit28f540f45bbacd939bfd07f213bcad2bf730b1bf (patch)
tree15f07c4c43d635959c6afee96bde71fb1b3614ee /stdio/test-fseek.c
downloadglibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.tar.gz
glibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.tar.xz
glibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.zip
initial import
Diffstat (limited to 'stdio/test-fseek.c')
-rw-r--r--stdio/test-fseek.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/stdio/test-fseek.c b/stdio/test-fseek.c
new file mode 100644
index 0000000000..398cac796f
--- /dev/null
+++ b/stdio/test-fseek.c
@@ -0,0 +1,67 @@
+#include <ansidecl.h>
+#include <stdio.h>
+
+#define TESTFILE "test.dat"
+
+int
+main __P((void))
+{
+  FILE *fp;
+  int i, j;
+
+  puts ("\nFile seek test");
+  fp = fopen (TESTFILE, "w");
+  if (fp == NULL)
+    {
+      perror (TESTFILE);
+      return 1;
+    }
+
+  for (i = 0; i < 256; i++)
+    putc (i, fp);
+  if (freopen (TESTFILE, "r", fp) != fp)
+    {
+      perror ("Cannot open file for reading");
+      return 1;
+    }
+
+  for (i = 1; i <= 255; i++)
+    {
+      printf ("%3d\n", i);
+      fseek (fp, (long) -i, SEEK_END);
+      if ((j = getc (fp)) != 256 - i)
+	{
+	  printf ("SEEK_END failed %d\n", j);
+	  break;
+	}
+      if (fseek (fp, (long) i, SEEK_SET))
+	{
+	  puts ("Cannot SEEK_SET");
+	  break;
+	}
+      if ((j = getc (fp)) != i)
+	{
+	  printf ("SEEK_SET failed %d\n", j);
+	  break;
+	}
+      if (fseek (fp, (long) i, SEEK_SET))
+	{
+	  puts ("Cannot SEEK_SET");
+	  break;
+	}
+      if (fseek (fp, (long) (i >= 128 ? -128 : 128), SEEK_CUR))
+	{
+	  puts ("Cannot SEEK_CUR");
+	  break;
+	}
+      if ((j = getc (fp)) != (i >= 128 ? i - 128 : i + 128))
+	{
+	  printf ("SEEK_CUR failed %d\n", j);
+	  break;
+	}
+    }
+  fclose (fp);
+
+  puts ((i > 255) ? "Test succeeded." : "Test FAILED!");
+  return (i > 255) ? 0 : 1;
+}