From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 1999 invoked from network); 7 Mar 2023 13:19:00 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 7 Mar 2023 13:19:00 -0000 Received: (qmail 13727 invoked by uid 550); 7 Mar 2023 13:18:57 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 13671 invoked from network); 7 Mar 2023 13:18:56 -0000 Date: Tue, 7 Mar 2023 08:18:44 -0500 From: Rich Felker To: somethingfnothing Cc: "musl@lists.openwall.com " Message-ID: <20230307131844.GN4163@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] 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?