From: Eric Blake Date: Wed, 25 Apr 2007 13:22:15 +0000 (+0000) Subject: * lib/fpurge.c (includes): Use stdlib.h for free. X-Git-Tag: cvs-readonly~504 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=a507c022cea66634ee5ebf20ece1cdba6590aa3d;p=gnulib.git * lib/fpurge.c (includes): Use stdlib.h for free. * tests/test-fflush.c (main): Also test fflush-fseeko. --- diff --git a/ChangeLog b/ChangeLog index 6218a8e72..b5615eec4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-04-25 Eric Blake + + * lib/fpurge.c (includes): Use stdlib.h for free. + * tests/test-fflush.c (main): Also test fflush-fseeko. + 2007-04-25 Bruno Haible Make fflush+fseek POSIX-compliant on FreeBSD and MacOS X. diff --git a/lib/fpurge.c b/lib/fpurge.c index 0e8c164e2..863f8536b 100644 --- a/lib/fpurge.c +++ b/lib/fpurge.c @@ -20,6 +20,8 @@ /* Specification. */ #include "fpurge.h" +#include + int fpurge (FILE *fp) { diff --git a/tests/test-fflush.c b/tests/test-fflush.c index 276d8bfba..79fa05126 100755 --- a/tests/test-fflush.c +++ b/tests/test-fflush.c @@ -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;