test for ftello64 and fseeko64

Andreas Jaeger aj@suse.de
Mon Feb 5 12:58:00 GMT 2001


I got a bugreport for glibc 2.1.3 that fseeko/ftello64 are not
working.  I checked that they're working with glibc 2.2 and like to
add the following check to glibc 2.2.  So far there's no test at all
for fseeko64 and ftello64 in glibc.

Ok to commit?

Andreas

2001-02-05  Andreas Jaeger  <aj@suse.de>

	* io/test-lfs.c (do_test): Test lseek64 return value, call
	test_ftello.
	(test_ftello): New function to test ftello64 and fseeko64.

============================================================
Index: io/test-lfs.c
--- io/test-lfs.c	2001/01/08 22:26:19	1.6
+++ io/test-lfs.c	2001/02/05 20:45:49
@@ -88,6 +88,53 @@
     }
 }
 
+static void
+test_ftello (void)
+{
+  FILE *f;
+  int ret;
+  off64_t pos;
+  
+  f = fopen64 (name, "w");
+
+  ret = fseeko64 (f, TWO_GB+100, SEEK_SET);
+  if (ret == -1 && errno == ENOSYS)
+    {
+      error (0, errno, "fseeko is not supported");
+      exit (EXIT_SUCCESS);
+    }
+  if (ret == -1 && errno == EINVAL)
+    {
+      error (0, errno, "LFS seems not to be supported ");
+      exit (EXIT_SUCCESS);
+    }
+  if (ret == -1)
+    {
+      error (0, errno, "fseeko64 failed with error: ");
+      exit (EXIT_FAILURE);
+    }
+
+  ret = fwrite ("Hello", 1, 5, f);
+  if (ret == -1 && errno == EINVAL)
+    {
+      error (0, errno, "LFS seems not to be supported.");
+      exit (EXIT_SUCCESS);
+    }
+
+  if (ret != 5)
+    error (EXIT_FAILURE, errno, "cannot write test string to large file");
+
+  pos = ftello64 (f);
+
+  if (pos != TWO_GB+105)
+    {
+      error (0, 0, "ftello64 gives wrong result.");
+      exit (EXIT_FAILURE);
+    }
+  
+  fclose (f);
+}
+
 int
 do_test (int argc, char *argv[])
 {
@@ -105,6 +152,11 @@
       error (0, errno, "LFS seems not to be supported ");
       exit (EXIT_SUCCESS);
     }
+  if (ret == -1)
+    {
+      error (0, errno, "lseek64 failed with error: ");
+      exit (EXIT_FAILURE);
+    }
 
   ret = write (fd, "Hello", 5);
   if (ret == -1 && errno == EINVAL)
@@ -131,5 +183,7 @@
     error (EXIT_FAILURE, 0, "stat reported size %lld instead of %lld.",
 	   (long long int) statbuf.st_size, (TWO_GB + 100 + 5));
 
+  test_ftello ();
+  
   return 0;
 }

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


More information about the Libc-hacker mailing list