home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / CUJJUN93.ZIP / 1106133B < prev    next >
Text File  |  1993-04-01  |  590b  |  34 lines

  1. /* stderr.c:    Redirect stderr */
  2.  
  3. #include <stdio.h>
  4. #include <io.h>
  5. #include <fcntl.h>
  6. #include <assert.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9.  
  10. static int old_handle = -1;
  11.  
  12. int redir_stderr(char *fname)
  13. {
  14.     int fd = open(fname,O_WRONLY|O_CREAT|O_TEXT,S_IWRITE);
  15.  
  16.     assert(fd >= 0);
  17.     old_handle = dup(fileno(stderr));
  18.     dup2(fd,fileno(stderr));
  19.     close(fd);
  20.     return fd;
  21. }
  22.  
  23. void restore_stderr()
  24. {
  25.     if (old_handle != -1)
  26.     {
  27.         dup2(old_handle,fileno(stderr));
  28.         close(old_handle);
  29.         old_handle = -1;
  30.     }
  31. }
  32.  
  33.  
  34.