|
Message-ID: <419e95bb3a69fa0990e56996e198355f@ispras.ru> Date: Thu, 14 Feb 2019 00:39:07 +0300 From: Alexey Izbyshev <izbyshev@...ras.ru> To: musl@...ts.openwall.com Cc: Rich Felker <dalias@...ifal.cx>, Rich Felker <dalias@...c.org> Subject: Re: Bug in gets function? 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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.