File: xstd.c

package info (click to toggle)
autotrace 0.31.1-16
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,800 kB
  • sloc: ansic: 15,092; sh: 6,972; makefile: 273
file content (44 lines) | stat: -rw-r--r-- 675 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* xfopen.c: fopen and fclose with error checking. */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* Def: HAVE_CONFIG_H */

#include "xstd.h"
#include <errno.h>

FILE *
xfopen (at_string filename, at_string mode)
{
  FILE *f;

  if (strcmp(filename, "-") == 0)
    f = stdin;
  else
    {
      f = fopen (filename, mode);
      if (f == NULL)
	FATAL_PERROR (filename);
    }

  return f;
}


void
xfclose (FILE *f, at_string filename)
{
  if (f != stdin)
    {
      if (fclose (f) == EOF)
	FATAL_PERROR (filename);
    }
}

void
xfseek (FILE *f, long offset, int wherefrom, at_string filename)
{
  if (fseek (f, offset, wherefrom) < 0)
    FATAL_PERROR (filename);
}