home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / fmtr / efopen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  591 b   |  28 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: efopen.c,v 1.3 86/05/11 09:50:48 root Exp $";
  3. #endif
  4.  
  5. #include <stdio.h>
  6.  
  7. FILE *
  8. efopen(file, mode)    /* fopen file, die if cannot */
  9. char *file, *mode;    /* from K & P with addition of perror() and handling
  10.                of "-" as stdin */
  11. {
  12.     FILE *fp;
  13.     extern char *progname;
  14.  
  15.     if (strcmp(file, "-") == 0)
  16.     return(stdin);
  17.  
  18.     if ((fp = fopen(file, mode)) != NULL)
  19.     return (fp);
  20.  
  21.     if (progname)
  22.     fprintf(stderr, "%s ", progname);
  23.     fprintf(stderr, "can't open file %s mode %s: ", file, mode);
  24.     perror("");
  25.     exit(1);
  26.     /* NOTREACHED */
  27. }
  28.