[Top][All Lists]

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

Re: fpurge now available in cygwin

From: Eric Blake
Subject: Re: fpurge now available in cygwin
Date: Sat, 15 Aug 2009 13:03:34 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20090605 Thunderbird/ Mnenhy/

Hash: SHA1

According to Eric Blake on 7/14/2009 7:18 AM:
> Cygwin 1.7 now provides fpurge, and it passes test-fpurge.c without the
> use of a wrapper function.  Therefore, I think that it avoids the BSD bug
> reported here:
> http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00277.html
> That means that blindly compiling the replacement fpurge.o is now a waste
> on Cygwin (it is still necessary for BSD, where fpurge is broken; for
> glibc, where it is spelled __fpurge and lacks a return value; and for
> systems that lack a native fpurge).  But I'm struggling to come up with a
> minimal test that can be used in fpurge.m4 to detect the difference
> between the working Cygwin and the broken BSD fpurge implementations; the
> referenced email doesn't show how to expose the BSD failure, just how to
> work around it.  And it also seems that the comment is wrong:
>          "The following always hold: if _flags & __SRD, _w is 0."
>        If this invariant is not fulfilled and the stream is read-write but
>        currently writing, subsequent putc or fputc calls will write directly
>        into the buffer, although they shouldn't be allowed to.  */

The comment is indeed wrong.  And after several hours of staring at BSD
source code, I now finally have a minimal test:

$ cat foo.c
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
  FILE *f = fopen("bar", "w+");
  fputs ("abc", f);
  rewind (f);
  while (EOF != fgetc (f));
  fpurge (f); /* BSD fpurge leaves f in read state, with write buffer */
  argc > 1 ? putc ('d', f) : fputc ('d', f);
  return 0;
$ ./foo # BSD fputc always changes stream state to writing
$ cat foo && echo
$ ./foo 1 # oops - putc is a macro, and does not adjust stream state
$ # so fflush/fclose assume nothing needs flushing
$ cat foo && echo

On cygwin, both variants properly print 'abcd' - that is, the fpurge does
not leave the stream in an inconsistent read state, such that the putc
operates correctly.

I'm now working on updating the fpurge module to avoid compiling the
rpl_fpurge wrapper on cygwin 1.7.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/


reply via email to

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