Mail Archives: djgpp-workers/2003/02/26/06:19:27

Message-ID: <>
Date: Wed, 26 Feb 2003 04:12:22 -0500
From: CBFalconer <cbfalconer AT yahoo DOT com>
Organization: Ched Research
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: Implementation of fchmod [PATCH]
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1030206081714 DOT 6656L-100000 AT is> <3E54E663 DOT 5F32DFF7 AT phekda DOT freeserve DOT co DOT uk> <2427-Sat22Feb2003220304+0200-eliz AT is DOT elta DOT co DOT il> <3E5B6452 DOT 82F4D938 AT phekda DOT freeserve DOT co DOT uk> <7263-Tue25Feb2003211713+0200-eliz AT elta DOT co DOT il> <3E5C1B27 DOT 47B225B AT phekda DOT freeserve DOT co DOT uk>
Reply-To: djgpp-workers AT delorie DOT com

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
   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.
   <>  USE worldnet address!

- Raw text -

  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019