home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / libc / efopen.c < prev    next >
C/C++ Source or Header  |  1991-03-12  |  599b  |  35 lines

  1. /*
  2.  * efopen - fopen file, exit with message if impossible
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <errno.h>
  8. #ifndef __STDC__
  9. extern int errno;
  10. #endif
  11.  
  12. /* imports from libc */
  13. extern void error();
  14.  
  15. static char message[] = "can't open file \"%s\" mode ";
  16.  
  17. FILE *
  18. efopen(file, mode)
  19. char *file;
  20. char *mode;
  21. {
  22.     FILE *fp;
  23.     char fullmsg[sizeof(message)+10];
  24.  
  25.     errno = 0;        /* Wipe out residue of earlier errors. */
  26.     fp = fopen(file, mode);
  27.     if (fp == NULL) {
  28.         (void) strcpy(fullmsg, message);
  29.         (void) strncat(fullmsg, mode, 10);
  30.         error(fullmsg, file);
  31.         /* NOTREACHED */
  32.     }
  33.     return(fp);
  34. }
  35.