Subject: Re: Sensing a disconnected socket
To: Rick Byers <>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: current-users
Date: 06/26/1997 06:28:53
>>> Interestingly enough, ferror and feof both return 0 after EOF is
>>> read (shouldn't one be true?).
>> ferror and feof work on stdio streams.  select, read, and write work
>> on file descriptors.  There is no stdio analog to select(); I can't
>> even see one in the NetBSD extensions to standard stdio.  If you
>> read EOF via read(), stdio won't know anything about it.
> I was using fgetc(stdout), it returned -1, and ferror and feof both
> return 0 afterwards.

That's no surprise.  fgetc on an output-only stream just returns EOF
with errno set to EBADF, without setting either the EOF or error flags
on the stream.  See __srefill() in /usr/src/lib/libc/stdio/refill.c.

					der Mouse

		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B