Mail Archives: djgpp-workers/2003/02/26/06:19:27
Richard Dawe wrote:
> Eli Zaretskii wrote:
> >
... snip ...
> >
> > Call isatty on the handle; if it returns zero, the handle is
> > redirected.
>
> But can we assume file descriptors 0, 1, etc. are actually
> standard handles? What happens if the program closes them and
> then opens some other file? I don't think we can reliably tell
> whether it's a standard handle. So we can't return the
> pipe-specific error.
I use "isatty(fileno(stdin))". In fact, to allow incorporation in
standard C code (the reference to help is for the client program):
/* This is very likely to be non-portable
DOES NOT check fp open for reading
NULL fp is considered a keyboard here!
With "gcc -W -Wall -ansi -pedantic" we can expect
implicit declaration warnings for isatty and fileno.
However the result should link correctly.
If it always returns 0 the system still works
but will not give the automatic help.
*/
static int akeyboard(FILE *fp)
{
#ifndef __TURBOC__ /* TC2 is peculiar */
# ifdef __STDC__
/* This dirty operation allows gcc -ansi -pedantic */
extern int fileno(FILE *fp);
extern int isatty(int fn);
# endif
#endif
return ((fp != NULL) && isatty(fileno(fp)));
} /* akeyboard */
--
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
- Raw text -