[comp.unix.questions] Check input buffer in C

852028e@aucs.uucp (Amari M. Elammari) (05/26/90)

 Is there a UNIX C (sun4 C) function that checks if the input buffer 
 is empty???

What I want to do is to check the buffer, if there are some
characters in the buffer then read them; otherwise continue
with the next statement.


-- 
Amari Elammari.     
Acadia University, Wolfville, N.S., Canada
P.O.BOX 1236 Wolfville, N.S. Canada BOP 1X0
BITNET	852028e@Acadia		Internet 852028e@AcadiaU.CA

gwyn@smoke.BRL.MIL (Doug Gwyn) (05/27/90)

In article <1990May26.144958.4395@aucs.uucp> 852028e@aucs.UUCP (Amari  M.  Elammari) writes:
> Is there a UNIX C (sun4 C) function that checks if the input buffer 
> is empty???
>What I want to do is to check the buffer, if there are some
>characters in the buffer then read them; otherwise continue
>with the next statement.

To which "input buffer" do you refer?  There are several different
kinds of "input buffer" possible for a UNIX C program.  If your
program maintains its own buffer, it should be able to test it;
the stdio buffer is not worth testing, because of the way stdio
uses it; kernel disk block buffers are also not worth testing;
streams can be tested with select() or poll(); under some
circumstances the terminal handler MIN & TIME parameters might be
appropriate.

alan@george.Jpl.Nasa.Gov (Alan S. Mazer) (05/30/90)

In article <1990May26.144958.4395@aucs.uucp>, 852028e@aucs.uucp (Amari  M.  Elammari) writes:
>  Is there a UNIX C (sun4 C) function that checks if the input buffer 
>  is empty???

Under 4.2 there was an FIONREAD ioctl -- not sure if this is still available.
That returned the number of characters waiting to be read.  You can also
use select() to find out if something is there.

-- Alan				# "But seriously, what could go wrong?"
   ..!ames!elroy!alan
   alan@elroy.jpl.nasa.gov