From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.13]) by sourceware.org (Postfix) with ESMTPS id 6A5FF3858288 for ; Mon, 4 Jul 2022 08:10:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6A5FF3858288 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=cygwin.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=cygwin.com Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MuUrM-1nGrYj45S6-00ra8m for ; Mon, 04 Jul 2022 10:10:24 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id E0433A80B74; Mon, 4 Jul 2022 10:10:22 +0200 (CEST) Date: Mon, 4 Jul 2022 10:10:22 +0200 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Bug in Control-d handling? Message-ID: Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <827e2006-2aae-9f7f-9c3f-eef3a7c6e793@cornell.edu> <20220620175935.924a49feb13156f1a3cf3da4@nifty.ne.jp> <20220620192223.2e0a084a7c093939b1c7c8d6@nifty.ne.jp> <5c548a4c-b7ea-b7e0-6ab6-ea0e94ce66a1@cornell.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5c548a4c-b7ea-b7e0-6ab6-ea0e94ce66a1@cornell.edu> X-Provags-ID: V03:K1:jLBTJKNahDmKMQxCfof2JYHiznBf3F21rbTUbG5IkjRqdZsUBex r13oHkweIx6BrO+0I78HaPN4F4kU0KnSGVTedAkR6HaRS1eoeBEQeShLMr5YGmF7xxy6w7K EMKl9jmDXWRXukT0Fs5Ispp/5tDnEoh04wVa+oEVyQxK4J4I3yarzP3DR3q0ge3oA3QIiAL XlEekX3bFHGnpYmiPHAzQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:ck9Ab55izlo=:qAAacBw3Niif/Zc6llDvLy Q/YOSYakHeYNzVG49/HICBKZ5HABHFttWOjezijtvdr41Qfc85BmO5L0c+zcYzlJjE3zo5Can zJssZ/nTSWQY4Ba6w6mIaFp2e5T8lJh7fubO5CojKliJgHKUaOWppWHGQ8I5T9C8IZjRfcI1g LilGnkEUfA8SgFmg+HXDMZn1Pv0b2Q11xNbflLdvRhVZayzeUICtYyjezhEDKTL5BmXjPe/zi FpVMLwbwXmWRfTlC3vAPY7B21dCok6oURYco6RUFfocKGiazxOFa70u5nV6EwC+qLFRv+SbFT gCyVMsed1TTtq77VqcGba7C2h4hvXiUjll7T5gwuj8lGydrCVCtlDT+iEJvDHc4K0498aZ+FR jkMPn4YH8bEGcQjIjmLeNwkBLqKWYr+bhC5FqxIVReLDzmJ15CO5YzyuK6tj7WOb2zNbHrXE4 i7buH/9RfNKGu7Noef4dDFhIz0Rk+KqoD4AWz0eCyS0iY9A7kqqPbZeKY0H2/IFTA0wr2ZyuP sjLSwco7uwXN0ZIovi3dZjgUJhw+adQyGvckMRsVziaEYySaSgIOvlhMM5Vzfrf1ijY6kHPvp SmuSs3r9c+1ELi+gSjaSECjm1AX6jxMgXbmqr4A+KVqR6faHolaIMTeWTnX5+c963dTB64mUH NAx0EZ0t6I4h5RLw40E1BsUAVusb99DGghMTq6EkSAs+DqawunEU8PmwGYuHKYJoZIWAG7bpr e1DMzozUSxvRfPpeNJsxmu2WWh4M/1+RSkQaYYAPyPdQK1lw/Vm3oZghnGM= X-Spam-Status: No, score=-100.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, GOOD_FROM_CORINNA_CYGWIN, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_FAIL, SPF_HELO_NONE, 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, 04 Jul 2022 08:10:32 -0000 On Jun 20 09:24, Ken Brown wrote: > On 6/20/2022 6:22 AM, Takashi Yano wrote: > > On Mon, 20 Jun 2022 17:59:35 +0900 > > Takashi Yano wrote: > > > 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. > > > > Ah, I confirmed that System V (Solaris 11.4) behaves like that. > > Does cygwin aim for System V compatibility??? > > Thanks for tracking this down! > > I don't recall any situation in which Cygwin preferred System V > compatibility over Linux compatibility. I'm attaching the commit (from > November 2004) in which the #ifndef __CYGWIN__ was introduced. There's no > indication in the commit message as to the reason for the change. I also > didn't see anything relevant in the cygwin or cygwin-developers mailing > lists from November 2004, but I might have missed it. > > I think that commit should probably be reverted, but we should wait until > Corinna is available. Even though the issue is in newlib code, the code > only affects Cygwin, so there's probably no need to involve the newlib list. > But again, that's Corinna's call. I think reverting this patch makes sense these days. Thanks for tracking this down, please push this on the master branch. Thanks, Corinna > > Ken > From 1f8f7e2d54364bd2993892adffb5c6435f53167d Mon Sep 17 00:00:00 2001 > From: Christopher Faylor > Date: Wed, 17 Nov 2004 17:02:10 +0000 > Subject: [PATCH] * libc/stdio/refill.c (__srefill): Try again after EOF on > Cygwin. Clear EOF flag if successful. > > --- > newlib/ChangeLog | 5 +++++ > newlib/libc/stdio/refill.c | 8 ++++++++ > 2 files changed, 13 insertions(+) > > diff --git a/newlib/ChangeLog b/newlib/ChangeLog > index 9983e6ba6..8b8cf4d4c 100644 > --- a/newlib/ChangeLog > +++ b/newlib/ChangeLog > @@ -1,3 +1,8 @@ > +2004-11-17 Christopher Faylor > + > + * libc/stdio/refill.c (__srefill): Try again after EOF on Cygwin. Clear > + EOF flag if successful. > + > 2004-10-28 Christopher Faylor > > * libc/include/sys/signal.h: Move include to bottom of file > diff --git a/newlib/libc/stdio/refill.c b/newlib/libc/stdio/refill.c > index 74573e8fd..3f0b1a566 100644 > --- a/newlib/libc/stdio/refill.c > +++ b/newlib/libc/stdio/refill.c > @@ -45,9 +45,11 @@ _DEFUN(__srefill, (fp), > > 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) > @@ -98,7 +100,13 @@ _DEFUN(__srefill, (fp), > fp->_p = fp->_bf._base; > fp->_r = (*fp->_read) (fp->_cookie, (char *) fp->_p, fp->_bf._size); > fp->_flags &= ~__SMOD; /* buffer contents are again pristine */ > +#ifndef __CYGWIN__ > if (fp->_r <= 0) > +#else > + if (fp->_r > 0) > + fp->_flags &= ~__SEOF; > + else > +#endif > { > if (fp->_r == 0) > fp->_flags |= __SEOF; > -- > 2.36.1 > > > -- > Problem reports: https://cygwin.com/problems.html > FAQ: https://cygwin.com/faq/ > Documentation: https://cygwin.com/docs.html > Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple