9 copy_stream_crc(FILE *arcfile, FILE *outfile,
10 unsigned long remainder, unsigned int *crc)
14 while (remainder != 0) {
15 uint n = (uint)MIN(remainder, BUFSIZ);
18 if (fread(buf, 1, n, arcfile) != n)
20 fwrite_crc(buf, n, outfile, crc);
21 if (outfile != stdout && opts.quiet < 1) {
29 extract(struct lzh_istream *rp, FILE *outfile, struct lzh_header *h)
34 if (opts.method->dicbit != 0)
35 decode(rp, outfile, h->origsize, &crc);
37 copy_stream_crc(rp->fp, outfile, h->origsize, &crc);
39 if ((crc ^ INIT_CRC) != h->file_crc)
44 extract_to_file(struct lzh_istream *rp, struct lzh_header *h)
50 makepath(filename, sizeof(filename),
51 opts.outdir, h->filename, NULL);
53 string_copy(filename, h->filename, sizeof(filename));
55 if (memcmp(h->method, "-lhd-", sizeof(h->method)) == 0) {
58 printf("Extracting %s\n", filename);
62 /* create regular file */
63 if (file_exists(filename)) {
64 if (!opts.force_extract) {
65 message("'%s' has been already exist. skip", filename);
71 if (mkdir_parent(filename) == -1) {
73 error("cannot make directory \"%s\"", opts.outdir);
76 outfile = fopen(filename, "wb");
77 if (outfile == NULL) {
78 fprintf(stderr, "Can't open %s (skip)\n", filename);
84 printf("Extracting %s ", filename);
86 extract(rp, outfile, h);
89 /* adjust file information (timestamp etc) */
93 ut.actime = ut.modtime = h->mtime;
98 fprintf(stdout, "\n");
102 extract_to_stdout(struct lzh_istream *rp, struct lzh_header *h)
104 if (memcmp(h->method, "-lhd-", sizeof(h->method)) == 0) {
109 printf("===== %s =====\n", h->filename);
112 extract(rp, stdout, h);