9 void report (const char *fmt
, ...)
13 vfprintf (stdout
, fmt
, ap
);
17 void error (const char *fmt
, ...)
21 fprintf (stderr
, "error: ");
22 vfprintf (stderr
, fmt
, ap
);
23 fprintf (stderr
, "\n");
27 void xerror (const char *fmt
, ...)
31 fprintf (stderr
, "error: ");
32 vfprintf (stderr
, fmt
, ap
);
33 fprintf (stderr
, ": %s\n", strerror (errno
));
38 void fatal (const char *fmt
, ...)
42 fprintf (stderr
, "fatal: ");
43 vfprintf (stderr
, fmt
, ap
);
44 fprintf (stderr
, "\n");
49 void xfatal (const char *fmt
, ...)
53 fprintf (stderr
, "fatal: ");
54 vfprintf (stderr
, fmt
, ap
);
55 fprintf (stderr
, ": %s\n", strerror (errno
));
62 void *xmalloc (size_t size
)
64 void *ptr
= malloc (size
);
65 if (!ptr
) fatal ("memory exhausted");
69 void *read_file (const char *path
, size_t *size
)
77 fp
= fopen (path
, "rb");
79 xerror ("can't open file `%s'", path
);
83 if (fseek (fp
, 0L, SEEK_END
)) {
84 xerror ("can't seek file `%s'", path
);
91 xerror ("can't get file size of `%s'", path
);
96 file_size
= (size_t) r
;
97 buffer
= xmalloc (file_size
);
100 read_return
= fread (buffer
, 1, file_size
, fp
);
103 if (read_return
!= file_size
) {
104 error ("can't fully read file `%s'", path
);
109 if (size
) *size
= file_size
;