1 /***********************************************************************
2 * This file is part of HA, a general purpose file archiver.
3 * Copyright (C) 1995 Harri Hirvola
4 * Modified by Ketmar // Invisible Vector
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ***********************************************************************/
28 #include <sys/types.h>
36 static uint64_t bytes_done
= 0, bytes_total
= 0;
39 # define OUTBUF_SIZE (1024*1024)
41 # define OUTBUF_SIZE 1
43 static uint8_t *wrbuf
;
46 static int dot_count
= -1;
49 static int bread (void *buf
, int buf_len
, void *udata
) {
50 return read(fdi
, buf
, buf_len
);
54 int main (int argc
, char *argv
[]) {
61 argv
[1] = "egatiles.dd2.haz";
66 fprintf(stderr
, "usage: %s infile outfile\n", argv
[0]);
69 fdi
= open(argv
[1], O_RDONLY
|O_CLOEXEC
);
71 fprintf(stderr
, "FATAL: can't open file: '%s'\n", argv
[1]);
74 if (read(fdi
, sign
, 4) != 4) res
= -1;
75 else if (memcmp(sign
, "LBHZ", 4) != 0) res
= -1;
76 else if (read(fdi
, &bytes_total
, 8) != 8) res
= -1;
79 fprintf(stderr
, "FATAL: not libha file!\n");
82 fdo
= open(argv
[2], O_WRONLY
|O_CREAT
|O_TRUNC
|O_CLOEXEC
, 0640);
84 fprintf(stderr
, "FATAL: can't create file: '%s'\n", argv
[2]);
87 hup
= haunp_open_io(bread
, NULL
);
88 wrbuf
= malloc(OUTBUF_SIZE
);
89 //printf("output buffer size: %d\n", OUTBUF_SIZE);
91 if (pbar_dot_count(bytes_done
, bytes_total
) != dot_count
) {
92 dot_count
= pbar_dot_count(bytes_done
, bytes_total
);
93 pbar_draw(bytes_done
, bytes_total
);
95 int rd
= haunp_read(hup
, wrbuf
, OUTBUF_SIZE
);
98 if (rd
< 0) fprintf(stdout
, "READ ERROR!\n");
99 res
= (rd
< 0 ? -1 : 0);
102 if (write(fdo
, wrbuf
, rd
) != rd
) {
104 fprintf(stdout
, "WRITE ERROR!\n");
115 if (res
!= 0) unlink(argv
[2]);