From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13785 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 00:39:07 +0300 Message-ID: <419e95bb3a69fa0990e56996e198355f@ispras.ru> References: <20190212034838.GH23599@brightrain.aerifal.cx> <20190212035106.GI23599@brightrain.aerifal.cx> <20190212163027.GK23599@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="74101"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Roundcube Webmail/1.1.2 Cc: Rich Felker , Rich Felker To: musl@lists.openwall.com Original-X-From: musl-return-13801-gllmg-musl=m.gmane.org@lists.openwall.com Wed Feb 13 22:39:21 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 1gu2FV-000J8V-2q for gllmg-musl@m.gmane.org; Wed, 13 Feb 2019 22:39:21 +0100 Original-Received: (qmail 16153 invoked by uid 550); 13 Feb 2019 21:39:18 -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 16135 invoked from network); 13 Feb 2019 21:39:18 -0000 In-Reply-To: <20190212163027.GK23599@brightrain.aerifal.cx> X-Sender: izbyshev@ispras.ru Xref: news.gmane.org gmane.linux.lib.musl.general:13785 Archived-At: 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. Alexey