1 /* xfopen.c: fopen and fclose with error checking. */
2 
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif /* Def: HAVE_CONFIG_H */
6 
7 #include "xstd.h"
8 #include <errno.h>
9 
10 FILE *
xfopen(at_string filename,at_string mode)11 xfopen (at_string filename, at_string mode)
12 {
13   FILE *f;
14 
15   if (strcmp(filename, "-") == 0)
16     f = stdin;
17   else
18     {
19       f = fopen (filename, mode);
20       if (f == NULL)
21 	FATAL_PERROR (filename);
22     }
23 
24   return f;
25 }
26 
27 
28 void
xfclose(FILE * f,at_string filename)29 xfclose (FILE *f, at_string filename)
30 {
31   if (f != stdin)
32     {
33       if (fclose (f) == EOF)
34 	FATAL_PERROR (filename);
35     }
36 }
37 
38 void
xfseek(FILE * f,long offset,int wherefrom,at_string filename)39 xfseek (FILE *f, long offset, int wherefrom, at_string filename)
40 {
41   if (fseek (f, offset, wherefrom) < 0)
42     FATAL_PERROR (filename);
43 }
44 
45