changeset 8714:50acfe842621

* lib/fpurge.c (includes): Use stdlib.h for free. * tests/test-fflush.c (main): Also test fflush-fseeko.
author Eric Blake <ebb9@byu.net>
date Wed, 25 Apr 2007 13:22:15 +0000
parents aad7ea346fbf
children bce2b6584930
files ChangeLog lib/fpurge.c tests/test-fflush.c
diffstat 3 files changed, 43 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- a/lib/fpurge.c
+++ b/lib/fpurge.c
@@ -20,6 +20,8 @@
 /* Specification.  */
 #include "fpurge.h"
 
+#include <stdlib.h>
+
 int
 fpurge (FILE *fp)
 {
--- a/tests/test-fflush.c
+++ b/tests/test-fflush.c
@@ -53,7 +53,7 @@
   /* 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 @@
   /* 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 @@
   /* 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 @@
   /* 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;