Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 21 Nov 2019 14:04:44 -0500
From: Rich Felker <>
Cc: "" <>
Subject: Re: non-standard implementation of fflush()

On Thu, Nov 21, 2019 at 06:31:02PM +0000, wrote:
> Hello everyone,
> the implementation of fflush() in musl doesn't seem to conform to
> the opengroup standard:
> In addition to flushing unwritten data, which is expected, musl
> flushes the read buffer when calling fflush(). This leads to data
> loss in bidirectional communication uses. Other standard libraries
> don't do this.
> As a reference compare musl to openbsd's libc:
> I think this is unexpected behavior and should be changed.

ISO C leaves the behavior of fflush undefined unless "stream points to
an output stream or an update stream in which the most recent
operation was not input". POSIX further defines it for read, but only
if the underlying fd is seekable:

    "For a stream open for reading with an underlying file
    description, if the file is not already at EOF, and the file is
    one capable of seeking, the file offset of the underlying open
    file description shall be set to the file position of the stream,
    and any characters pushed back onto the stream by ungetc() or
    ungetwc() that have not subsequently been read from the stream
    shall be discarded (without further changing the file offset).

The case of reading from an unseekable stream is left undefined.
Correct programs should not be doing this at all. The current behavior
in musl is simply the default effect from not making any special
provisions to treat unseekable streams differently, since there is not
any particular behavior we're trying to achieve.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.