bug-gnulib
[Top][All Lists]
Advanced

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

Re: no new modules 'freading', 'fwriting'


From: Bruno Haible
Subject: Re: no new modules 'freading', 'fwriting'
Date: Fri, 27 Apr 2007 12:56:48 +0200
User-agent: KMail/1.5.4

Eric Blake wrote:
> I'm checking this in now, since I needed it to fix fflush on mingw (see
> next email).

Thanks. This was hard to understand, so I'm adding some comments.

2007-04-27  Bruno Haible  <address@hidden>

        * lib/fflush.c: Add comments.
        * modules/fpurge-tests (Depends-on): Add fflush.
        * modules/freadable-tests (Depends-on): Likewise.
        * modules/fwritable-tests (Depends-on): Likewise.

*** lib/fflush.c        26 Apr 2007 13:20:51 -0000      1.6
--- lib/fflush.c        27 Apr 2007 10:28:32 -0000
***************
*** 38,48 ****
    int result;
    off_t pos;
  
!   /* When stream is NULL, POSIX only requires flushing of output
!      streams.  C89 guarantees behavior of output streams, and fflush
!      should be safe on read-write streams that are not currently
!      reading.  */
!   if (! stream || ! freading (stream))
      return fflush (stream);
  
    /* POSIX does not specify fflush behavior for non-seekable input
--- 38,61 ----
    int result;
    off_t pos;
  
!   /* When stream is NULL, POSIX and C99 only require flushing of "output
!      streams and update streams in which the most recent operation was not
!      input", and all implementations do this.
! 
!      When stream is "an output stream or an update stream in which the most
!      recent operation was not input", POSIX and C99 requires that fflush
!      writes out any buffered data, and all implementations do this.
! 
!      When stream is, however, an input stream or an update stream in which
!      the most recent operation was input, POSIX and C99 specify nothing.
!      mingw, in particular, drops the input buffer, leaving the file descriptor
!      positioned at the end of the input buffer. I.e. ftell (stream) is lost.
!      We don't want to call the implementation's fflush in this case.
! 
!      We test ! freading (stream) here, rather than fwriting (stream), because
!      what we need to know is whether the stream holds a "read buffer", and on
!      mingw this is indicated by _IOREAD, regardless of _IOWRT.  */
!   if (stream == NULL || ! freading (stream))
      return fflush (stream);
  
    /* POSIX does not specify fflush behavior for non-seekable input
***************
*** 60,71 ****
--- 73,88 ----
    result = fpurge (stream);
    if (result != 0)
      return result;
+ 
    pos = lseek (fileno (stream), pos, SEEK_SET);
    if (pos == -1)
      return EOF;
+   /* After a successful lseek, update the file descriptor's position cache
+      in the stream.  */
  #if defined __sferror               /* FreeBSD, NetBSD, OpenBSD, MacOS X, 
Cygwin */
    stream->_offset = pos;
    stream->_flags |= __SOFF;
  #endif
+ 
    return 0;
  }
*** modules/fpurge-tests        16 Apr 2007 15:02:36 -0000      1.2
--- modules/fpurge-tests        27 Apr 2007 10:28:33 -0000
***************
*** 2,7 ****
--- 2,8 ----
  tests/test-fpurge.c
  
  Depends-on:
+ fflush
  
  configure.ac:
  
*** modules/freadable-tests     14 Apr 2007 00:11:41 -0000      1.1
--- modules/freadable-tests     27 Apr 2007 10:28:33 -0000
***************
*** 2,7 ****
--- 2,8 ----
  tests/test-freadable.c
  
  Depends-on:
+ fflush
  
  configure.ac:
  
*** modules/fwritable-tests     14 Apr 2007 00:15:48 -0000      1.1
--- modules/fwritable-tests     27 Apr 2007 10:28:33 -0000
***************
*** 2,7 ****
--- 2,8 ----
  tests/test-fwritable.c
  
  Depends-on:
+ fflush
  
  configure.ac:
  





reply via email to

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