On Mon, Jun 15, 2015 at 11:59 PM, Roberto E. Vargas Caballero
<[email protected]> 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

Reply via email to