From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13787 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alexey Izbyshev Newsgroups: gmane.linux.lib.musl.general Subject: Re: Bug in gets function? Date: Thu, 14 Feb 2019 02:19:09 +0300 Message-ID: <216fbc9c9c54d99f043cda3ef11cf145@ispras.ru> References: <20190212034838.GH23599@brightrain.aerifal.cx> <20190212035106.GI23599@brightrain.aerifal.cx> <20190212163027.GK23599@brightrain.aerifal.cx> <419e95bb3a69fa0990e56996e198355f@ispras.ru> <20190213221330.GR23599@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="970"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Roundcube Webmail/1.1.2 Cc: Rich Felker To: musl@lists.openwall.com Original-X-From: musl-return-13803-gllmg-musl=m.gmane.org@lists.openwall.com Thu Feb 14 00:19:24 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1gu3oJ-0000AC-Nl for gllmg-musl@m.gmane.org; Thu, 14 Feb 2019 00:19:23 +0100 Original-Received: (qmail 11882 invoked by uid 550); 13 Feb 2019 23:19:21 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 11860 invoked from network); 13 Feb 2019 23:19:21 -0000 In-Reply-To: <20190213221330.GR23599@brightrain.aerifal.cx> X-Sender: izbyshev@ispras.ru Xref: news.gmane.org gmane.linux.lib.musl.general:13787 Archived-At: On 2019-02-14 01:13, Rich Felker wrote: > On Thu, Feb 14, 2019 at 12:39:07AM +0300, Alexey Izbyshev wrote: >> On 2019-02-12 19:30, Rich Felker wrote: >> >Here's an alternate proposal via direct implementation: >> > >> >char *gets(char *s) >> >{ >> > size_t i=0; >> > int c; >> > FLOCK(stdin); >> > while ((c=getc_unlocked(stdin)) != EOF && c != '\n') s[i++] = c; >> > s[i] = 0; >> > if (c != '\n' && !feof(stdin)) s = 0; >> > FUNLOCK(stdin); >> > return s; >> >} >> > >> >Does this look ok? Of course it's slow compared to a fgets-like >> >operation on the buffer, but gets is not a usable interface and I >> >don't see any reason to care whether it's fast. >> > >> gets() must also return NULL if EOF is reached and no bytes were read. > > So if (c != '\n' && (!feof(stdin) || !i)) ? > Yes, looks good. Alexey