From 6313b276cd5032464acbafcb18f1273356a356e4 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 16 Aug 2009 14:46:39 +0200 Subject: [PATCH] Tweak last commit. --- ChangeLog | 7 +++++++ m4/fpurge.m4 | 6 ++---- tests/test-fpurge.c | 20 +++++++++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb286dce9..2233ff170 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-08-16 Bruno Haible + + * m4/fpurge.m4 (gl_FUNC_FPURGE): Don't compile fpurge.c if only the + declaration of fpurge is missing. + * tests/test-fpurge.c (main): Check that the file has not more contents + than expected. Close the file before removing it. + 2009-08-15 Eric Blake fpurge: don't wrap working cygwin implementation diff --git a/m4/fpurge.m4 b/m4/fpurge.m4 index 99b9a6ee1..8c4ddb6c1 100644 --- a/m4/fpurge.m4 +++ b/m4/fpurge.m4 @@ -1,4 +1,4 @@ -# fpurge.m4 serial 4 +# fpurge.m4 serial 5 dnl Copyright (C) 2007, 2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -34,12 +34,10 @@ AC_DEFUN([gl_FUNC_FPURGE], [gl_cv_func_fpurge_works='guessing no'])]) if test "x$gl_cv_func_fpurge_works" != xyes; then REPLACE_FPURGE=1 + AC_LIBOBJ([fpurge]) fi fi if test "x$ac_cv_have_decl_fpurge" = xno; then HAVE_DECL_FPURGE=0 fi - if test "$REPLACE_FPURGE$HAVE_DECL_FPURGE" != 01; then - AC_LIBOBJ([fpurge]) - fi ]) diff --git a/tests/test-fpurge.c b/tests/test-fpurge.c index f63484034..596dd75ae 100644 --- a/tests/test-fpurge.c +++ b/tests/test-fpurge.c @@ -51,6 +51,8 @@ main () if (fclose (fp)) goto skip; + /* The file's contents is now "foobarsh". */ + /* Open it in read-write mode. */ fp = fopen (TESTFILE, "r+"); if (fp == NULL) @@ -82,22 +84,30 @@ main () ASSERT (getc (fp) == EOF); ASSERT (fclose (fp) == 0); + /* The file's contents is now "foogarsh". */ + /* Ensure that purging a read does not corrupt subsequent writes. */ fp = fopen (TESTFILE, "r+"); - ASSERT (fp); - ASSERT (fseek (fp, -1, SEEK_END) == 0); + if (fp == NULL) + goto skip; + if (fseek (fp, -1, SEEK_END)) + goto skip; ASSERT (getc (fp) == 'h'); ASSERT (getc (fp) == EOF); ASSERT (fpurge (fp) == 0); ASSERT (putc ('!', fp) == '!'); ASSERT (fclose (fp) == 0); fp = fopen (TESTFILE, "r"); - ASSERT (fp); + if (fp == NULL) + goto skip; { - char buf[9]; - ASSERT (fread (buf, 1, 9, fp) == 9); + char buf[10]; + ASSERT (fread (buf, 1, 10, fp) == 9); ASSERT (memcmp (buf, "foogarsh!", 9) == 0); } + ASSERT (fclose (fp) == 0); + + /* The file's contents is now "foogarsh!". */ remove (TESTFILE); return 0; -- 2.11.0