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
17 int main(int argc
, char *argv
[])
19 size_t offset
, bufsize
, depth
;
25 die("Usage: %s PROGRAM\n", argv
[0]);
27 check_null(in
= fopen(argv
[1], "r"), "fopen");
28 check_null(buf
= calloc(bufsize
= INITIALBUFSIZE
, 1), "calloc");
35 check_fail(fclose(in
), "fclose", -1);
38 if (++ptr
>= buf
+bufsize
){
40 check_null(buf
= realloc(buf
, bufsize
*=2),
43 memset(ptr
, 0, bufsize
/2);
48 die("There is no stack position -1\n");
65 check_null(cs
= malloc(sizeof(struct cs
)),
68 check_fail(cs
->pl
= ftell(in
), "ftell", -1);
83 check_fail(fseek(in
, cs
->pl
-1, SEEK_SET
), "fseek", -1);