home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff319.lzh / CNewsSrc / cnews.orig.lzh / libc / stdfdopen.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  539b  |  28 lines

  1. /*
  2.  * stdfdopen - ensure that the standard i/o descriptors are open,
  3.  *    to avoid mayhem.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <errno.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10.  
  11. #ifndef NSYSFILE
  12. #define NSYSFILE 3                    /* hmm, not on V8 */
  13. #endif
  14.  
  15. extern int errno;
  16.  
  17. void
  18. stdfdopen()            /* ensure standard descriptors are open */
  19. {
  20.     register int fd;
  21.     struct stat stbuf;
  22.  
  23.     for (fd = 0; fd < NSYSFILE; fd++)
  24.         if (fstat(fd, &stbuf) < 0 && errno == EBADF)
  25.             if (open("/dev/null", 2) != fd)    /* open read/write */
  26.                 exit(1);        /* bad news */
  27. }
  28.