Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230307131844.GN4163@brightrain.aerifal.cx>
Date: Tue, 7 Mar 2023 08:18:44 -0500
From: Rich Felker <dalias@...c.org>
To: somethingfnothing <somethingfnothing@....com>
Cc: "musl@...ts.openwall.com " <musl@...ts.openwall.com>
Subject: Re: fputs stdout lost characters on nonblock tty

On Tue, Mar 07, 2023 at 08:42:37PM +0800, somethingfnothing wrote:
> hi
> 
> 
> I use fputs to write string to stdout, sometimes it will lost some
> characters, the error is EAGAIN, my tty is nonblock.
> 
> 
> fputs did not handle this error, it reset the "wpos" "wbase" "wend"
> and return -1 when recive error, thus the last characters was lost,
> and I cannot know how much characters was lost

This is the expected behavior. fputs is expected to behave "as if" by
repeated fputc, and return an error if any of those fputc operations
would have returned an error. fputc in turn is specified to fail with
EAGAIN in this case:

    [EAGAIN]     [CX] [Option Start] The O_NONBLOCK flag is set for
    the file descriptor underlying stream and the thread would be
    delayed in the write operation. [Option End]

https://pubs.opengroup.org/onlinepubs/9699919799/functions/fputc.html

Nonblocking file descriptors are generally not useful with stdio. Is
there a reason you're setting it to nonblocking mode?

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.