+2009-08-16 Bruno Haible <bruno@clisp.org>
+
+ * 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 <ebb9@byu.net>
fpurge: don't wrap working cygwin implementation
-# 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,
[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
])
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)
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;