home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
VRAC
/
CUJJUN93.ZIP
/
1106133B
< prev
next >
Wrap
Text File
|
1993-04-01
|
590b
|
34 lines
/* stderr.c: Redirect stderr */
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
static int old_handle = -1;
int redir_stderr(char *fname)
{
int fd = open(fname,O_WRONLY|O_CREAT|O_TEXT,S_IWRITE);
assert(fd >= 0);
old_handle = dup(fileno(stderr));
dup2(fd,fileno(stderr));
close(fd);
return fd;
}
void restore_stderr()
{
if (old_handle != -1)
{
dup2(old_handle,fileno(stderr));
close(old_handle);
old_handle = -1;
}
}