Category : Batch File Utilities - mostly for DOS
Archive   : RBSETENV.ZIP
Filename : DUP.C
* For some reason I have not figured out, TurboC v2.0 dup() and dup2() functions
* will not let me save and reassign stdin, needed for the write pipe, but they
* will work ok for the read pipe. (freopen works on stdin, but I cannot restore
* it without dup2())
* Here are very simple versions that do the direct DOS calls and seem to work
* R. Brittain (Tested with DOS 4.0, and SHARE installed)
*/
#include
#include
dup ( int fd )
{
/*
* Call DOS function to create a new file handle as a duplicate of
* existing handle fd
*/
union REGS regs;
regs.h.ah = 0x45;
regs.x.bx = fd;
intdos(®s,®s);
if (regs.x.cflag) {
errno = regs.x.ax;
return(-1);
} else {
return(regs.x.ax);
}
}
dup2 (int ofd, int nfd )
{
/*
* Call DOS function to duplicate handle nfd onto existing handle ofd
*/
union REGS regs;
regs.h.ah = 0x46;
regs.x.bx = nfd;
regs.x.cx = ofd;
intdos(®s,®s);
if (regs.x.cflag) {
errno = regs.x.ax;
return(-1);
} else {
return(0);
}
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/