bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fpurge now available in cygwin


From: Bruno Haible
Subject: Re: fpurge now available in cygwin
Date: Sun, 16 Aug 2009 14:58:40 +0200
User-agent: KMail/1.9.9

Hi Eric,

Great work, this testcase!

>         If this invariant is not fulfilled and the stream is read-write but
> -       currently writing, subsequent putc or fputc calls will write directly
> +       currently reading, subsequent putc or fputc calls will write directly
>         into the buffer, although they shouldn't be allowed to.  */

Yes, the comment was wrong. Sorry if it led you the wrong way.

> +  if test "$REPLACE_FPURGE$HAVE_DECL_FPURGE" != 01; then
> +    AC_LIBOBJ([fpurge])
> +  fi

This is not right: When REPLACE_FPURGE = 0 and HAVE_DECL_FPURGE = 0, it is not
needed to compile fpurge.c just because the declaration is missing. It would
also lead to a symbol clash, because in this case lib/stdio.in.h does not do
"#define fpurge rpl_fpurge", thus fpurge.o would and libc.so would both define
the symbol 'fpurge'. Which may lead to the expected effect of fpurge.o ends
up in a shared library that is dynamically loaded.

> +  remove (TESTFILE);

Without a preceding fclose (fp), this call may not work on Windows platforms.

I'm applying this fix:


2009-08-16  Bruno Haible  <address@hidden>

        * 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.

--- m4/fpurge.m4.orig   2009-08-16 14:43:16.000000000 +0200
+++ m4/fpurge.m4        2009-08-16 14:24:10.000000000 +0200
@@ -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 @@
       [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
 ])
--- tests/test-fpurge.c.orig    2009-08-16 14:43:16.000000000 +0200
+++ tests/test-fpurge.c 2009-08-16 14:42:28.000000000 +0200
@@ -51,6 +51,8 @@
   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 @@
   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;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]