Article View: comp.sys.atari.st
Article #32748Re: File handle info
From: Ken Badertscher
Date: Tue, 31 May 1988 22:59
Date: Tue, 31 May 1988 22:59
29 lines
1435 bytes
1435 bytes
in article <465@ruuinf.UUCP>, piet@ruuinf.UUCP (Piet van Oostrum) says:
> what I think is the easiest way to do it: if you seek to an illegal
> position (like -1), you get an error (-64) if the file is on disk,
> otherwise you get 0. If the file is on disk, its position is not changed,
> so the operation is effectively always a no-op.
That may be an easy way to do it, but I wouldn't recommend relying on
an undocumented feature of what Fseek returns. Hardly safe.
The approved method of determining isatty is to save your current
position in the file, seek to 1 byte from the beginning, then restore
your current position. If the seek to 1 byte from the beginning
returns 1, you're not a tty. It involves a couple more seeks, but
it's safer:
int isatty(fd)
int fd;
{
long savepos;
long seekret;
savepos = Fseek(0L,fd,1); /* save where we are */
seekret = Fseek(1L,fd,0); /* seek to 1 byte from beginning */
Fseek(savepos,fd,0); /* then back to where we were */
return (seekret != 1L); /* if the seek didn't work, it's a tty */
}
Ken Badertscher
Atari Software Test/Support
Technical Details
Message-ID:
<1066@atari.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!portal!atari!kbadReferences:
<465@ruuinf.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!portal!atari!kbad From: kbad@atari.UUCP (Ken Badertscher) Newsgroups: comp.sys.atari.st Subject: Re: File handle info Message-ID: <1066@atari.UUCP> Date: 31 May 88 22:59:37 GMT References: <465@ruuinf.UUCP> Organization: Atari Corp., Sunnyvale, CA Lines: 29