home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 1 / GoldFishApril1994_CD2.img / d4xx / d473 / cnewssrc / cnews_src.lzh / libc / stdfdopen.c < prev    next >
C/C++ Source or Header  |  1990-12-25  |  949b  |  41 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. #ifndef __STDC__
  9. extern int errno;
  10. #endif
  11. #ifdef unix
  12. # include <sys/types.h>
  13. # include <sys/stat.h>
  14. #endif /* unix */
  15.  
  16. #ifndef NSYSFILE
  17. #define NSYSFILE 3                    /* hmm, not on V8 */
  18. #endif
  19.  
  20. void
  21. stdfdopen()            /* ensure standard descriptors are open */
  22. {
  23. #if !defined(AZTEC_C) && !defined(LATTICE)
  24.     /*
  25.      *    [FIXME] -- stdfdopen()
  26.      *    As far as I know, the best the Amiga could do is
  27.      *    use iomode() to try to change the mode of the 'level 1'
  28.      *    file handle (descriptor) and see if an error was
  29.      *    returned!  ... forget it for now -- assume it's okay.
  30.      *    Could it *really* be a problem anyway???
  31.      */
  32.     register int fd;
  33.     struct stat stbuf;
  34.  
  35.     for (fd = 0; fd < NSYSFILE; fd++)
  36.         if (fstat(fd, &stbuf) < 0 && errno == EBADF)
  37.             if (open("/dev/null", 2) != fd)    /* open read/write */
  38.                 exit(1);        /* bad news */
  39. #endif
  40. }
  41.