delorie.com/archives/browse.cgi | search |
Message-ID: | <3E0F0CAE.CC28815F@yahoo.com> |
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 |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: Detecting stdin not redirected |
References: | <3E0EA6CF DOT 51896D97 AT yahoo DOT com> <3E0EDC94 DOT 421FD75E AT phekda DOT freeserve DOT co DOT uk> |
Lines: | 28 |
Date: | Sun, 29 Dec 2002 14:55:07 GMT |
NNTP-Posting-Host: | 12.90.174.194 |
X-Complaints-To: | abuse AT worldnet DOT att DOT net |
X-Trace: | bgtnsc05-news.ops.worldnet.att.net 1041173707 12.90.174.194 (Sun, 29 Dec 2002 14:55:07 GMT) |
NNTP-Posting-Date: | Sun, 29 Dec 2002 14:55:07 GMT |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Richard Dawe wrote: > CBFalconer wrote: > > > With gcc and DJGPP, how can a running program detect that stdin > > has not been redirected from the keyboard? How portable is such a > > method, i.e. will it hold up for Linux? To allow for use of > > external terminals, I guess the thing wanted is to detect that > > stdin is actually a disk file (or a pipe) as opposed to a device. > [snip] > > Take a look at isatty: > > info libc alpha isatty That looks promising, except it needs an int file descriptor. After a little research in stdio.h I conclude that "fileno(fp)" is required. So I need to work with "if (isatty(fileno(stdin)))" and that should cover the portability area. Thanks, that did it. I want this for a class of filters that normally shut up, but give help if run with no redirection. -- 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!
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |