* lib/fpurge.c (includes): Use stdlib.h for free.
authorEric Blake <ebb9@byu.net>
Wed, 25 Apr 2007 13:22:15 +0000 (13:22 +0000)
committerEric Blake <ebb9@byu.net>
Wed, 25 Apr 2007 13:22:15 +0000 (13:22 +0000)
* tests/test-fflush.c (main): Also test fflush-fseeko.

ChangeLog
lib/fpurge.c
tests/test-fflush.c

index 6218a8e72f07b1a42ab1b0fe751b83b02e9d7cf8..b5615eec4a3439e7085409e21d523a11f179c7a7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-04-25  Eric Blake  <ebb9@byu.net>
+
+       * lib/fpurge.c (includes): Use stdlib.h for free.
+       * tests/test-fflush.c (main): Also test fflush-fseeko.
+
 2007-04-25  Bruno Haible  <bruno@clisp.org>
 
        Make fflush+fseek POSIX-compliant on FreeBSD and MacOS X.
index 0e8c164e29d2c842cda4ab3458eb31c67f685e00..863f8536ba985619df31430083a929b9c0e43d75 100644 (file)
@@ -20,6 +20,8 @@
 /* Specification.  */
 #include "fpurge.h"
 
+#include <stdlib.h>
+
 int
 fpurge (FILE *fp)
 {
index 276d8bfba1f503b6ea58f20f8ff649c9d65b071c..79fa051263d7d8853451a26afd4268b4925b3309 100755 (executable)
@@ -53,7 +53,7 @@ main (int argc, char *argv[])
   /* For deterministic results, ensure f read a bigger buffer.  */
   if (lseek (fd, 0, SEEK_CUR) == 5)
     {
-      fputs ("Sample file was not buffered.\n", stderr);
+      fputs ("Sample file was not buffered after fread.\n", stderr);
       fclose (f);
       unlink ("test-fflush.txt");
       return 1;
@@ -61,7 +61,7 @@ main (int argc, char *argv[])
   /* POSIX requires fflush-fseek to set file offset of fd.  */
   if (fflush (f) != 0 || fseek (f, 0, SEEK_CUR) != 0)
     {
-      fputs ("Failed to flush sample file.\n", stderr);
+      fputs ("Failed to flush-fseek sample file.\n", stderr);
       fclose (f);
       unlink ("test-fflush.txt");
       return 1;
@@ -69,7 +69,7 @@ main (int argc, char *argv[])
   /* Check that offset is correct.  */
   if (lseek (fd, 0, SEEK_CUR) != 5)
     {
-      fputs ("File offset is wrong.\n", stderr);
+      fputs ("File offset is wrong after fseek.\n", stderr);
       fclose (f);
       unlink ("test-fflush.txt");
       return 1;
@@ -77,7 +77,39 @@ main (int argc, char *argv[])
   /* Check that file reading resumes at correct location.  */
   if (fgetc (f) != '6')
     {
-      fputs ("Failed to read next byte of file.\n", stderr);
+      fputs ("Failed to read next byte after fseek.\n", stderr);
+      fclose (f);
+      unlink ("test-fflush.txt");
+      return 1;
+    }
+  /* For deterministic results, ensure f read a bigger buffer.  */
+  if (lseek (fd, 0, SEEK_CUR) == 6)
+    {
+      fputs ("Sample file was not buffered after fgetc.\n", stderr);
+      fclose (f);
+      unlink ("test-fflush.txt");
+      return 1;
+    }
+  /* POSIX requires fflush-fseeko to set file offset of fd.  */
+  if (fflush (f) != 0 || fseeko (f, 0, SEEK_CUR) != 0)
+    {
+      fputs ("Failed to flush-fseeko sample file.\n", stderr);
+      fclose (f);
+      unlink ("test-fflush.txt");
+      return 1;
+    }
+  /* Check that offset is correct.  */
+  if (lseek (fd, 0, SEEK_CUR) != 6)
+    {
+      fputs ("File offset is wrong after fseeko.\n", stderr);
+      fclose (f);
+      unlink ("test-fflush.txt");
+      return 1;
+    }
+  /* Check that file reading resumes at correct location.  */
+  if (fgetc (f) != '7')
+    {
+      fputs ("Failed to read next byte after fseeko.\n", stderr);
       fclose (f);
       unlink ("test-fflush.txt");
       return 1;