16 static int rdcur
= 0, rdtotal
= 0;
19 # define OUTBUF_SIZE (1024*1024)
21 # define OUTBUF_SIZE 1
23 static uint8_t *wrbuf
;
26 static int bread (void *buf
, int buf_len
, void *udata
) {
27 int res
= read(fdi
, buf
, buf_len
);
30 fprintf(stdout
, "\r[%d/%d] %3d%%", rdcur
, rdtotal
, (int)((uint64_t)100*rdcur
/rdtotal
));
37 int main (int argc
, char *argv
[]) {
43 argv
[1] = "egatiles.dd2.haz";
48 fprintf(stderr
, "usage: %s infile outfile\n", argv
[0]);
51 fdi
= open(argv
[1], O_RDONLY
|O_CLOEXEC
);
53 fprintf(stderr
, "FATAL: can't open file: '%s'\n", argv
[1]);
56 fdo
= open(argv
[2], O_WRONLY
|O_CREAT
|O_TRUNC
|O_CLOEXEC
, 0640);
58 fprintf(stderr
, "FATAL: can't create file: '%s'\n", argv
[2]);
61 rdtotal
= lseek(fdi
, 0, SEEK_END
);
62 lseek(fdi
, 0, SEEK_SET
);
63 hup
= haunp_open_io(bread
, NULL
);
64 wrbuf
= malloc(OUTBUF_SIZE
);
66 int rd
= haunp_read(hup
, wrbuf
, sizeof(wrbuf
));
68 if (rd
< 0) fprintf(stdout
, "\nREAD ERROR!");
69 res
= (rd
< 0 ? -1 : 0);
72 if (write(fdo
, wrbuf
, rd
) != rd
) {
73 fprintf(stdout
, "\nWRITE ERROR!");
79 fprintf(stdout
, "\n");
83 if (res
!= 0) unlink(argv
[2]);