home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / libcnews / fopenclex.c < prev    next >
C/C++ Source or Header  |  1993-11-20  |  605b  |  31 lines

  1. /*
  2.  * fopen and set close-on-exec (to avoid leaking descriptors into children)
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <fcntl.h>
  8. #include "news.h"
  9.  
  10. FILE *
  11. fopenwclex(name, mode)    /* open name; close-on-exec if OK, else warning */
  12. char *name, *mode;
  13. {
  14.     register FILE *fp;
  15.  
  16.     if ((fp = fopenclex(name, mode)) == NULL)
  17.         warning("can't open `%s'", name);    /* persistent? */
  18.     return fp;
  19. }
  20.  
  21. FILE *
  22. fopenclex(file, mode)        /* open file and if OK, close-on-exec */
  23. char *file, *mode;
  24. {
  25.     register FILE *fp;
  26.  
  27.     if ((fp = fopen(file, mode)) != NULL)
  28.         (void) fcntl(fileno(fp), F_SETFD, 1);
  29.     return fp;
  30. }
  31.