6 #define die(s, as...) {fprintf(stderr, s, ## as); return EXIT_FAILURE;}
7 #define check_fail(v, s, f) if((v) == f) die("%s(): %s\n", s, strerror(errno))
8 #define check_null(v, s) check_fail(v, s, NULL)
10 #define INITIALBUFSIZE 2
22 int main(int argc
, char *argv
[])
30 die("Usage: %s PROGRAM\n", argv
[0]);
32 check_null(in
= fopen(argv
[1], "r"), "fopen");
33 check_null(p
= calloc(sizeof (struct buf
), 1), "calloc");
38 check_fail(fclose(in
), "fclose", -1);
47 check_null(p
->n
= calloc(
48 sizeof (struct buf
), 1), "calloc");
55 check_null(p
->p
= calloc(
56 sizeof (struct buf
), 1), "calloc");
76 check_null(cs
= malloc(
77 sizeof(struct cs
)), "malloc");
79 check_fail(cs
->pl
= ftell(in
), "ftell", -1);
94 check_fail(fseek(in
, cs
->pl
-1, SEEK_SET
), "fseek", -1);