changeset 29219:bbaa39c67da5

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. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Thu, 13 Dec 2007 14:58:44 -0700
parents 55855e34d9d9
children a67344c101f8 0066c610cdb6
files ChangeLog lib/fseeko.c modules/fseeko tests/test-fseek.c tests/test-fseeko.c
diffstat 5 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Dec 13 12:09:31 2007 -0700
+++ b/ChangeLog	Thu Dec 13 14:58:44 2007 -0700
@@ -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.
--- a/lib/fseeko.c	Thu Dec 13 12:09:31 2007 -0700
+++ b/lib/fseeko.c	Thu Dec 13 14:58:44 2007 -0700
@@ -27,6 +27,9 @@
 #if !HAVE_FSEEKO
 # undef fseek
 # define fseeko fseek
+
+# include <verify.h>
+verify (sizeof (off_t) == sizeof (long));
 #endif
 
 int
--- a/modules/fseeko	Thu Dec 13 12:09:31 2007 -0700
+++ b/modules/fseeko	Thu Dec 13 14:58:44 2007 -0700
@@ -8,6 +8,7 @@
 Depends-on:
 lseek
 stdio
+verify
 
 configure.ac-early:
 AC_REQUIRE([AC_FUNC_FSEEKO])
--- a/tests/test-fseek.c	Thu Dec 13 12:09:31 2007 -0700
+++ b/tests/test-fseek.c	Thu Dec 13 14:58:44 2007 -0700
@@ -23,17 +23,23 @@
 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))
--- a/tests/test-fseeko.c	Thu Dec 13 12:09:31 2007 -0700
+++ b/tests/test-fseeko.c	Thu Dec 13 14:58:44 2007 -0700
@@ -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 @@
     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))