stdin

hi,
how does a program know whether some data are available from stdin?
I would like to make a program which could read its data from stdin
and _if_there_is_nothing_at_stdin_ from a file which name is given
as an argument. If there is nothing in stdin and no filename is given as
argument, the program should quit immediatly (not wait.)

I'm on Linux with gcc (g++ in fact.)

TIA if any idea.
Samuel

When opening the file for read, use the following:

open("<path/filename to open>", oflag|O_NONBLOCK,"mode if any");

The O_NONBLOCK will ensure that the reads do not block for data. read will return with -1 if there is no data to be read.

You can check for this and exit.

thanks you !