🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #30929

Re: isatty function missing in both Lattice-C and MWC

#30929
From: Allan Pratt
Date: Mon, 29 Feb 1988 19:58
58 lines
2055 bytes
From article <880224-080441-2553@Xerox>,
by "P.J.M._Verbruggen.ven1RX"@XEROX.COM:

> The isatty (check if file is a terminal) function is not in the
> libraries of both MWC and Lattice.  The related function getfc is
> mentioned in the Lattice manual but not incorporated.  I produced a
> poorman's isatty but would like to know if someone did a real isatty for
> the mentioned compilers. 
> 
> isatty(fh)  
> int fh;
> {
> if(fh>2)
>    return(0);
> else
>    return(1);
> } 
> 
> Thanks
> 
> Peter 

There is a better isatty.  It uses the property of tty's that seeking
always returns zero, while seeking forward in a file file either returns
an error code or a new (nonzero) offset in the file. 

This code works for "standard" handles which have been redirected to
files or other tty's, and for "nonstandard" handles which are files or
dup'ed copies of tty handles. 

This function returns EIHNDL if the handle is invalid, 0 if it's a
file, or 1 if it's a tty.

#define ERANGE -64L
#define EIHNDL -37L

isatty(h)
int h;
{
  int rc;
  long oldloc, seekval;

  oldloc = Fseek(h,0L,1);	/* seek zero bytes from current loc */
  if (seekval = Fseek(h,1L,1))	/* try to seek ahead one byte */
    if (seekval > 0 || 
        seekval == ERANGE)
      rc = 0;			/* file, not a tty */
    else 
      rc = EIHNDL;		/* EIHNDL, for instance: invalid handle */
  else
    rc = 1;
  Fseek(h,oldloc,0);		/* seek back to original location */
  return rc;			/* return true or false. */
}

============================================
Opinions expressed above do not necessarily	-- Allan Pratt, Atari Corp.
reflect those of Atari Corp. or anyone else.	  ...ames!atari!apratt
Technical Details
Message-ID: <1000@atari.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!portal!atari!apratt
References: <880224-080441-2553@Xerox>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!portal!atari!apratt
From: apratt@atari.UUCP (Allan Pratt)
Newsgroups: comp.sys.atari.st
Subject: Re: isatty function  missing in both Lattice-C and MWC
Message-ID: <1000@atari.UUCP>
Date: 29 Feb 88 19:58:42 GMT
References: <880224-080441-2553@Xerox>
Organization: Atari Corp., Sunnyvale CA
Lines: 58