From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from conssluserg-02.nifty.com (conssluserg-02.nifty.com [210.131.2.81]) by sourceware.org (Postfix) with ESMTPS id CDC2F3858C51 for ; Mon, 20 Jun 2022 09:00:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CDC2F3858C51 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=nifty.ne.jp Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nifty.ne.jp Received: from HP-Z230 (ak044095.dynamic.ppp.asahi-net.or.jp [119.150.44.95]) (authenticated) by conssluserg-02.nifty.com with ESMTP id 25K8xY8v013110 for ; Mon, 20 Jun 2022 17:59:34 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com 25K8xY8v013110 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.ne.jp; s=dec2015msa; t=1655715574; bh=KUoexj2YOmGtcPTTPxIWYQZhrYB6/GBee3VdwreJ4gY=; h=Date:From:To:Subject:In-Reply-To:References:From; b=fTMApXcjMKJBoqiISLWcxwVtXvpAGJ/THvZ/AjoSsvXcVZMbQZcnsViLL9vlX1d9z Rq9AWuvCpMauGOG/VVe6g5t6H6+H7ggKpid2gIh27bhUfpHFtrCA74r/0pVy9W8qe0 vXdKjCKPg7/41OZa9h8mYEnOjN64gIcGypLdmPwAEx3tVqmKyJdNld2ZYP8fij7CjV eNDfbiqYbUqTFRLUhoSnJvfmZWDtvcwAtW6+UHuayeB+FxBePmObVM6tL7nxOI7KCy mac5VE6c0Im2r/sCQLagdSrW/gudqEn86hk16mW3RUG9SWA2npGlks1xPHD/Ei2p9i OEzHRzfGP9GEw== X-Nifty-SrcIP: [119.150.44.95] Date: Mon, 20 Jun 2022 17:59:35 +0900 From: Takashi Yano To: cygwin@cygwin.com Subject: Re: Bug in Control-d handling? Message-Id: <20220620175935.924a49feb13156f1a3cf3da4@nifty.ne.jp> In-Reply-To: <827e2006-2aae-9f7f-9c3f-eef3a7c6e793@cornell.edu> References: <827e2006-2aae-9f7f-9c3f-eef3a7c6e793@cornell.edu> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: cygwin@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jun 2022 09:00:07 -0000 On Sun, 19 Jun 2022 15:08:19 -0400 Ken Brown wrote: > Consider the following program, which reads from standard input a line at a time > and then echoes the input back to the terminal: > > $ cat cat_line.c > #include > > int main () > { > char buf[BUFSIZ]; > > while (fgets (buf, BUFSIZ, stdin)) > fputs (buf, stdout); > } > > Run the program, type one or more characters (without hitting Enter), and type > Ctrl-d until the program exits. What I expect is that nothing visible happens > on the first Ctrl-d [but the input is sent to the internal stdin buffer], and > that the input is echoed and the program exits after the second Ctrl-d [the > program sees EOF]. This is what happens on Linux. On Cygwin, however, the > program keeps running after the second Ctrl-d and doesn't exit until Ctrl-d is > pressed a third time. > > I observed this problem because of a failing Emacs test, in which the program > "rev" was not seeing EOF after being sent Ctrl-d; "rev" does something like the > test case above, but using fgetws instead of fgets. Isn't this a bug of newlib? Try following code. #include int main() { printf("%d\n", getchar()); printf("%d\n", feof(stdin)); printf("%d\n", getchar()); return 0; } If you press Ctrl-D at the first getchar(), the second getchar() does not return EOF while it does in linux. The following patch seems to resolve the issue. diff --git a/newlib/libc/stdio/refill.c b/newlib/libc/stdio/refill.c index ccedc7af7..843163b7e 100644 --- a/newlib/libc/stdio/refill.c +++ b/newlib/libc/stdio/refill.c @@ -47,11 +47,9 @@ __srefill_r (struct _reent * ptr, fp->_r = 0; /* largely a convenience for callers */ -#ifndef __CYGWIN__ /* SysV does not make this test; take it out for compatibility */ if (fp->_flags & __SEOF) return EOF; -#endif /* if not already reading, have to be reading and writing */ if ((fp->_flags & __SRD) == 0) However, I am not sure what this #ifndef __CYGWIN__ is for. -- Takashi Yano