Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!husc6!mit-eddie!ll-xn!ames!oliveb!sun!gorodish!guy
From: guy%gorodish@Sun.COM (Guy Harris)
Newsgroups: comp.lang.c,comp.unix.questions
Subject: Re: Keyboard Input (Revised Question) ...
Message-ID: <23758@sun.uucp>
Date: Fri, 17-Jul-87 17:29:23 EDT
Article-I.D.: sun.23758
Posted: Fri Jul 17 17:29:23 1987
Date-Received: Sat, 18-Jul-87 17:12:53 EDT
References: <1043@bucsb.bu.edu.UUCP> <805@nu3b2.UUCP> <142@bby-bc.UUCP>
Sender: news@sun.uucp
Followup-To: comp.unix.questions
Lines: 43
Xref: mnetor comp.lang.c:3131 comp.unix.questions:3230

> > SERIOUSLY: use the function ioctl to set O_NDELAY on standard input,
> > use read to read your character. if there are no characters waiting, and you
> > are not at an EOF condition read will return -1 and errno will be set to
> > EAGAIN.

> Isn't it supposed to return 0  if there are no characters read.

It's like this:

In systems that implement 4.[23]BSD-style no-delay I/O, if there are
no characters waiting, "read" will return -1 and "errno" will be set
to EWOULDBLOCK.

In systems that implement System V-style no-delay I/O:

	if the descriptor doesn't refer to a stream, "read" will
	return 0;

	if the descriptor does refer to a stream, "read" will return
	-1 and "errno" will be set to EAGAIN.

S5 prior to R3 didn't have streams.

(Note that some systems may implement both styles of no-delay I/O.)

In POSIX-style non-blocking I/O (selected with O_NONBLOCK, not
O_NDELAY), "read" will return -1 and "errno" will be set to EAGAIN.
I don't know if any systems implement this yet.  (If your system
doesn't define O_NONBLOCK, it doesn't implement it.)

> Also isn't there an ioctl() settable value that specifies the minimum number
> of characters which must be in the buffer before a request is satisfied,
> along with a time period after which this many characters don't need to
> be there?

There is, but not under 4.[23]BSD; the person in question is running
systems based on 4.[23]BSD.  In those systems, there is an "ioctl"
call FIONREAD that will tell you how many characters are waiting to
be read; with this, you don't have to go into no-delay mode (and thus
don't have to leave it, either).  This is arguably more convenient.
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com