18 static void error_mem_cb (const char *where
) {
20 if (fdi
>= 0) close(fdi
);
21 if (fdo
>= 0) close(fdo
);
22 fprintf(stderr
, "FATAL: out of memory in %s!\n", where
);
27 static S16B
getbyte_cb (void) {
29 if (read(fdi
, &b
, 1) == 1) return b
;
34 static void putbyte_cb (S16B c
) {
40 static void flush_cb (void) {
44 int main (int argc
, char *argv
[]) {
47 fprintf(stderr
, "usage: %s <e|d> infile outfile\n", argv
[0]);
50 if (strcmp(argv
[1], "e") == 0 || strcmp(argv
[1], "c") == 0) dopack
= 1;
51 else if (strcmp(argv
[1], "d") == 0 || strcmp(argv
[1], "x") == 0) dopack
= 0;
53 fprintf(stderr
, "FATAL: unknown mode: '%s'\n", argv
[1]);
56 fdi
= open(argv
[2], O_RDONLY
|O_CLOEXEC
);
58 fprintf(stderr
, "FATAL: can't open file: '%s'\n", argv
[2]);
61 fdo
= open(argv
[3], O_WRONLY
|O_CREAT
|O_TRUNC
|O_CLOEXEC
, 0640);
63 fprintf(stderr
, "FATAL: can't create file: '%s'\n", argv
[3]);
66 error_mem
= error_mem_cb
;