#include "lha.h"
int
-decode_lzhuf(infp, outfp, original_size, packed_size, name, method)
+decode_lzhuf(infp, outfp, original_size, packed_size, name, method, read_sizep)
FILE *infp;
FILE *outfp;
long original_size;
long packed_size;
char *name;
int method;
+ size_t *read_sizep;
{
unsigned int crc;
interface.outfile = outfp;
interface.original = original_size;
interface.packed = packed_size;
+ interface.read_size = 0;
+
+ *read_sizep = packed_size;
switch (method) {
case LZHUFF0_METHOD_NUM:
case LARC4_METHOD_NUM:
start_indicator(name, original_size
,verify_mode ? "Testing " : "Melting ", 2048);
- copyfile(infp, (verify_mode ? NULL : outfp), original_size, 2, &crc);
+ *read_sizep = copyfile(infp, (verify_mode ? NULL : outfp),
+ original_size, 2, &crc);
break;
case LARC_METHOD_NUM: /* -lzs- */
interface.dicbit = 11;
,verify_mode ? "Testing " : "Melting "
,1 << interface.dicbit);
crc = decode(&interface);
+ *read_sizep = interface.read_size;
break;
case LZHUFF1_METHOD_NUM: /* -lh1- */
case LZHUFF4_METHOD_NUM: /* -lh4- */
,verify_mode ? "Testing " : "Melting "
,1 << interface.dicbit);
crc = decode(&interface);
+ *read_sizep = interface.read_size;
break;
case LZHUFF6_METHOD_NUM: /* -lh6- */ /* Added N.Watazaki (^_^) */
#ifdef SUPPORT_LH7
case LZHUFF7_METHOD_NUM: /* -lh7- */
#endif
interface.dicbit = (method - LZHUFF6_METHOD_NUM) + 15;
-
+ /* fall through */
default:
start_indicator(name, original_size
,verify_mode ? "Testing " : "Melting "
,1 << interface.dicbit);
crc = decode(&interface);
+ *read_sizep = interface.read_size;
}
finish_indicator(name, verify_mode ? "Tested " : "Melted ");
return FALSE;
}
else if (!force) {
- if (!isatty(0))
+ if (!isatty(0)) {
+ warning("skip to extract %s.", name);
return FALSE;
+ }
switch (inquire("OverWrite ?(Yes/[No]/All/Skip)", name, "YyNnAaSs\n")) {
case 0:
}
}
}
+
if (noexec)
printf("EXTRACT %s\n", name);
}
/* ------------------------------------------------------------------------ */
-static void
+static size_t
extract_one(afp, hdr)
FILE *afp; /* archive file */
LzHeader *hdr;
int method;
boolean save_quiet, save_verbose, up_flag;
char *q = hdr->name, c;
+ size_t read_size = 0;
if (ignore_directory && strrchr(hdr->name, '/')) {
q = (char *) strrchr(hdr->name, '/') + 1;
if (methods[method] == NULL) {
error("Unknown method \"%.*s\"; \"%s\" will be skiped ...",
5, hdr->method, name);
- return;
+ return read_size;
}
if (memcmp(hdr->method, methods[method], 5) == 0)
break;
if (methods[method] == NULL) {
error("Unknown method \"%.*s\"; \"%s\" will be skiped ...",
5, hdr->method, name);
- return;
+ return read_size;
}
if (memcmp(hdr->method, methods[method], 5) == 0)
break;
if (output_to_stdout || verify_mode) {
if (noexec) {
printf("%s %s\n", verify_mode ? "VERIFY" : "EXTRACT", name);
- if (afp == stdin) {
- int i = hdr->packed_size;
- while (i--)
- fgetc(afp);
- }
- return;
+ return read_size;
}
save_quiet = quiet;
old_mode = setmode(fileno(stdout), O_BINARY);
#endif
- crc = decode_lzhuf
- (afp, stdout, hdr->original_size, hdr->packed_size, name, method);
+ crc = decode_lzhuf(afp, stdout,
+ hdr->original_size, hdr->packed_size,
+ name, method, &read_size);
#if __MINGW32__
fflush(stdout);
setmode(fileno(stdout), old_mode);
if (skip_flg == FALSE) {
up_flag = inquire_extract(name);
if (up_flag == FALSE && force == FALSE) {
- return;
+ return read_size;
}
}
if (stbuf.st_mtime >= hdr->unix_last_modified_stamp) {
if (quiet != TRUE)
printf("%s : Skipped...\n", name);
- return;
+ return read_size;
}
}
}
if (noexec) {
- if (afp == stdin) {
- int i = hdr->packed_size;
- while (i--)
- fgetc(afp);
- }
- return;
+ return read_size;
}
signal(SIGINT, interrupt);
remove_extracting_file_when_interrupt = TRUE;
if ((fp = open_with_make_path(name)) != NULL) {
- crc = decode_lzhuf
- (afp, fp, hdr->original_size, hdr->packed_size, name, method);
+ crc = decode_lzhuf(afp, fp,
+ hdr->original_size, hdr->packed_size,
+ name, method, &read_size);
fclose(fp);
}
remove_extracting_file_when_interrupt = FALSE;
signal(SIGHUP, SIG_DFL);
#endif
if (!fp)
- return;
+ return read_size;
}
if (hdr->has_crc && crc != hdr->crc)
if (noexec) {
if (quiet != TRUE)
printf("EXTRACT %s (directory)\n", name);
- return;
+ return read_size;
}
/* NAME has trailing SLASH '/', (^_^) */
if ((hdr->unix_mode & UNIX_FILE_TYPEMASK) == UNIX_FILE_SYMLINK) {
if (skip_flg == FALSE) {
up_flag = inquire_extract(name);
if (up_flag == FALSE && force == FALSE) {
- return;
+ return read_size;
}
} else {
if (GETSTAT(name, &stbuf) == 0 && force != TRUE) {
if (stbuf.st_mtime >= hdr->unix_last_modified_stamp) {
if (quiet != TRUE)
printf("%s : Skipped...\n", name);
- return;
+ return read_size;
}
}
}
#else
warning("Can't make Symbolic Link %s -> %s",
hdr->realname, name);
- return;
+ return read_size;
#endif
} else { /* make directory */
if (!output_to_stdout && !make_parent_path(name))
- return;
+ return read_size;
}
}
}
if (!output_to_stdout)
adjust_info(name, hdr);
+
+ return read_size;
}
/* ------------------------------------------------------------------------ */
LzHeader hdr;
long pos;
FILE *afp;
+ size_t read_size;
/* open archive file */
if ((afp = open_old_archive()) == NULL)
while (get_header(afp, &hdr)) {
if (need_file(hdr.name)) {
pos = ftell(afp);
- extract_one(afp, &hdr);
- /* when error occurred in extract_one(), should adjust
- point of file stream */
- if (afp != stdin)
- fseek(afp, pos + hdr.packed_size, SEEK_SET);
- else {
- /* FIXME: assume that the extract_one() has read
- packed_size bytes from stdin. */
- long i = 0;
- while (i--) fgetc(afp);
+ read_size = extract_one(afp, &hdr);
+ if (read_size != hdr.packed_size) {
+ /* when error occurred in extract_one(), should adjust
+ point of file stream */
+ if (pos != -1 && afp != stdin)
+ fseek(afp, pos + hdr.packed_size - read_size, SEEK_SET);
+ else {
+ size_t i = hdr.packed_size - read_size;
+ while (i--) fgetc(afp);
+ }
}
} else {
if (afp != stdin)
fseek(afp, hdr.packed_size, SEEK_CUR);
else {
- int i = hdr.packed_size;
- while (i--)
- fgetc(afp);
+ size_t i = hdr.packed_size;
+ while (i--) fgetc(afp);
}
}
}