mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: y38h5z@protonmail.com
Cc: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: Re: non-standard implementation of fflush()
Date: Thu, 21 Nov 2019 14:04:44 -0500	[thread overview]
Message-ID: <20191121190444.GE16318@brightrain.aerifal.cx> (raw)
In-Reply-To: <hWubjKhHb4ZfOGaZv79qXIyVWlWXwlqxkFR4yrVHEB9X2W2VPxj2Cv5RicGK3Ep8M3rd-CPtQJXyH4-dGSGeMnzbKmEwyS6hBSJghPJx__k=@protonmail.com>

On Thu, Nov 21, 2019 at 06:31:02PM +0000, y38h5z@protonmail.com wrote:
> Hello everyone,
> 
> the implementation of fflush() in musl doesn't seem to conform to
> the opengroup standard:
> 
> https://pubs.opengroup.org/onlinepubs/009695399/functions/fflush.html
> 
> 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:
> 
> https://git.musl-libc.org/cgit/musl/tree/src/stdio/fflush.c
> https://github.com/openbsd/src/blob/master/lib/libc/stdio/fflush.c
> 
> 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.

Rich


  reply	other threads:[~2019-11-21 19:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-21 18:31 y38h5z
2019-11-21 19:04 ` Rich Felker [this message]
     [not found]   ` <I6lA7ERFkqk6k724VlnK6OZT6Uy2zzixDgjODO9RLz0K0BW86wWppsTn8ockD67PPoO09kzCdwyXs6NZzTVf6kWj9VWtotdFS8doVeYzJck=@protonmail.com>
2019-11-21 22:58     ` Rich Felker
2019-11-23 21:35       ` y38h5z

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191121190444.GE16318@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=y38h5z@protonmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).