Re: [hackers] [sbase] [PATCH 2/3] find: Fix flushing input buffer with -ok

From: Evan Gates <evan.gates_AT_gmail.com>
Date: Tue, 16 Jun 2015 07:42:54 -0700

On Mon, Jun 15, 2015 at 11:59 PM, Roberto E. Vargas Caballero
<k0ga_AT_shike2.com> wrote:
> On Mon, Jun 15, 2015 at 03:27:37PM -0400, Wolfgang Corcoran-Mathe wrote:
>> The original flush-stdin loop (with fgets()) hung until the user
>> entered some extraneous characters for it to kill.
>
> I don't know if it is related or not, but I'm having a similar problem
> with glibc. See this code:
>
> int
> main(void)
> {
> getchar();
> getchar();
> return 0;
> }
>
> If the user writes a ctrl-d in the first getchar, then the second
> getchar blocks until the user writes something else, although the
> file already reached the end of file. I have tested it in NetBSD
> to, and the second getchar returns automatically with EOF. I
> don't know what is said in the C standard, but I think this is an
> error in glibc.
>
>
> Regards,
>
>

According to fgetc(3p) and 7.21.7.1.3 of the C11 standard a call to
fgetc when the EOF indicator is already set should just return EOF. I
agree this seems to be a bug in glibc (not present in musl).

-emg
Received on Tue Jun 16 2015 - 16:42:54 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 18 2015 - 17:37:30 CEST