Another fseek test.
authorEric Blake <ebb9@byu.net>
Thu, 13 Dec 2007 21:58:44 +0000 (14:58 -0700)
committerEric Blake <ebb9@byu.net>
Thu, 13 Dec 2007 22:01:58 +0000 (15:01 -0700)
* tests/test-fseek.c (main): Also test ungetc handling.
* tests/test-fseeko.c (main): Likewise.
* modules/fseeko (Depends-on): Add verify.
* lib/fseeko.c [!HAVE_FSEEKO]: Verify that off_t is not too
large.
Reported by Larry Jones.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/fseeko.c
modules/fseeko
tests/test-fseek.c
tests/test-fseeko.c

index dd3d5f2c1e7af66d835a25c66ec9ec2f1d4f5ec7..a7828da310c21a6fbe3faeefaf4eba8c20bc2e27 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2007-12-13  Eric Blake  <ebb9@byu.net>
 
+       Another fseek test.
+       * tests/test-fseek.c (main): Also test ungetc handling.
+       * tests/test-fseeko.c (main): Likewise.
+       * modules/fseeko (Depends-on): Add verify.
+       * lib/fseeko.c [!HAVE_FSEEKO]: Verify that off_t is not too
+       large.
+       Reported by Larry Jones.
+
        Fix fseeko on mingw.
        * lib/fseeko.c (rpl_fseeko) [_IOERR]: Reset EOF flag on successful
        seek.
index 97dcf6da05c9ebfea0d02d97ea22f95f0dca59e1..6d55ec8b12d6194efa4b92969f8e3d5e1d8cf6b8 100644 (file)
@@ -27,6 +27,9 @@
 #if !HAVE_FSEEKO
 # undef fseek
 # define fseeko fseek
+
+# include <verify.h>
+verify (sizeof (off_t) == sizeof (long));
 #endif
 
 int
index eb109011edc1a45dbe8ba9b7cb36d5b90e685c86..cb26003de819ae24b021fa7ec66e61e33f0604dd 100644 (file)
@@ -8,6 +8,7 @@ m4/fseeko.m4
 Depends-on:
 lseek
 stdio
+verify
 
 configure.ac-early:
 AC_REQUIRE([AC_FUNC_FSEEKO])
index dde7ea0de4b413b983082346d0c1a5464c29b150..0c7db958dd32b45750cc994e5a4ddfc156f6e9bd 100644 (file)
 int
 main (int argc, char **argv)
 {
-  /* Assume stdin is seekable iff argc > 1.  */
+  /* Assume stdin is non-empty and seekable iff argc > 1.  */
   int expected = argc > 1 ? 0 : -1;
   if (fseek (stdin, 0, SEEK_CUR) != expected)
     return 1;
   if (argc > 1)
     {
-      /* Test that fseek resets end-of-file marker.  */
+      /* Test that fseek discards ungetc data.  */
+      int ch = fgetc (stdin);
+      if (ch == EOF)
+        return 1;
+      if (ungetc (ch ^ 0xff, stdin) != (ch ^ 0xff))
+        return 1;
       if (fseek (stdin, 0, SEEK_END))
         return 1;
       if (fgetc (stdin) != EOF)
         return 1;
+      /* Test that fseek resets end-of-file marker.  */
       if (!feof (stdin))
         return 1;
       if (fseek (stdin, 0, SEEK_END))
index 3be4f6e5025f53f471e78080ee967344c71ec265..25289cef06c9d5d94b7c2261330d5631be1ebfaa 100644 (file)
@@ -26,7 +26,7 @@
 int
 main (int argc, char **argv)
 {
-  /* Assume stdin is seekable iff argc > 1.  */
+  /* Assume stdin is non-empty and seekable iff argc > 1.  */
   int expected = argc > 1 ? 0 : -1;
   /* Exit with success only if fseek/fseeko agree.  */
   int r1 = fseeko (stdin, (off_t)0, SEEK_CUR);
@@ -35,11 +35,17 @@ main (int argc, char **argv)
     return 1;
   if (argc > 1)
     {
-      /* Test that fseek resets end-of-file marker.  */
+      /* Test that fseek discards ungetc data.  */
+      int ch = fgetc (stdin);
+      if (ch == EOF)
+        return 1;
+      if (ungetc (ch ^ 0xff, stdin) != (ch ^ 0xff))
+        return 1;
       if (fseeko (stdin, (off_t) 0, SEEK_END))
         return 1;
       if (fgetc (stdin) != EOF)
         return 1;
+      /* Test that fseek resets end-of-file marker.  */
       if (!feof (stdin))
         return 1;
       if (fseeko (stdin, (off_t) 0, SEEK_END))