🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.msdos.programmer
Article #1144

Re: Detecting DOS redirection requests.

#1144
From: Bob Stout
Date: Sun, 03 Sep 1995 20:31
60 lines
2073 bytes
On 3 Sep 1995, Henk den Adel wrote:

> You can use the ioctl function. In order to see whether stdin has
> been redirected, i use the following code:
> 
> int redirected;
> 
> redirected = ((ioctl(0,0)&2) == 0);

Not every DOS C compiler supports the ioctl() call. This is portable 
between all major compilers:

/*
**  iscons()
**
**  A function to determine if a specified stream refers to the console.
**
**  Original Copyright 1988-1991 by Bob Stout as part of
**  the MicroFirm Function Library (MFL)
**
**  This subset version is hereby donated to the public domain.
*/

#include <stdio.h>
#include <dos.h>

#define BOOL(x) (!(!(x)))

int iscons(FILE *fp)
{
      union REGS regs;

      regs.x.ax = 0x4400;
      regs.x.bx = (unsigned)fileno(fp);
      intdos(&regs, &regs);
      if (0 == (regs.x.ax & 0x80))
            return 0;
      return BOOL(regs.x.ax & 0x13);
}

#ifdef TEST

int main(void)
{
      fprintf(stderr, "stdin is%s redirected\n",
            iscons(stdin) ? " not" : "");
      fprintf(stderr, "stdout is%s redirected\n",
            iscons(stdout) ? " not" : "");
}

#endif /* TEST */


-------------------------------------------------------------
MicroFirm: Down to the C in chips...
FidoNet 1:106/2000.6
Internet bobstout@neosoft.com
Home of SNIPPETS - Current release:
	oak.oakland.edu:/SimTel/msdos/c/snip9503.zip
	juge.com:/c/file/c/snip9503.lzh
Technical Details
Message-ID: <Pine.BSD.3.91.950903152817.23959A-100000@Starbase.NeoSoft.COM>
Path: arc1-ca.pugleaf.net!Starbase.NeoSoft.COM!bobstout
References: <92011.microtsk@fox.nstn.ca> <42bg3q$dr0@ixnews6.ix.netcom.com> <42cu2b$dk4@mo6.rc.tudelft.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!Starbase.NeoSoft.COM!bobstout
From: Bob Stout <bobstout@neosoft.com>
Newsgroups: alt.msdos.programmer,comp.lang.c,comp.os.msdos.programmer
Subject: Re: Detecting DOS redirection requests.
Date: Sun, 3 Sep 1995 15:31:46 -0500
Organization: NeoSoft Internet Services   +1 713 968 5800
Message-ID: <Pine.BSD.3.91.950903152817.23959A-100000@Starbase.NeoSoft.COM>
References: <92011.microtsk@fox.nstn.ca> <42bg3q$dr0@ixnews6.ix.netcom.com> <42cu2b$dk4@mo6.rc.tudelft.nl>
NNTP-Posting-Host: starbase.neosoft.com
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
In-Reply-To: <42cu2b$dk4@mo6.rc.tudelft.nl>