+2007-09-03 Koji Arai <arai@users.sourceforge.jp>
+
+ * src/append.c, src/extract.c, src/header.c, src/indicator.c, src/lha.h, src/lhadd.c, src/lhext.c, src/lhlist.c, src/prototypes.h, src/slide.c, src/util.c:
+ Possible to extract 4G over files, use UNLHA32.DLL specific extended header.
+
2007-05-23 Koji Arai <arai@users.sourceforge.jp>
* tests/lha-test.in: added an optional numeric command-line
name, hdr_method)
FILE *infp;
FILE *outfp;
- size_t size;
- size_t *original_size_var;
- size_t *packed_size_var;
+ off_t size;
+ off_t *original_size_var;
+ off_t *packed_size_var;
char *name;
char *hdr_method;
{
decode_lzhuf(infp, outfp, original_size, packed_size, name, method, read_sizep)
FILE *infp;
FILE *outfp;
- size_t original_size;
- size_t packed_size;
+ off_t original_size;
+ off_t packed_size;
char *name;
int method;
- size_t *read_sizep;
+ off_t *read_sizep;
{
unsigned int crc;
struct interfacing interface;
put_byte(v >> 24);
}
+#ifdef HAVE_UINT64_T
+static uint64_t
+get_longlongword()
+{
+ uint64_t b0, b1, b2, b3, b4, b5, b6, b7;
+ uint64_t l;
+
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1)
+ printf("%02d %2d: ", get_ptr - start_ptr, 4);
+#endif
+ b0 = GET_BYTE();
+ b1 = GET_BYTE();
+ b2 = GET_BYTE();
+ b3 = GET_BYTE();
+ b4 = GET_BYTE();
+ b5 = GET_BYTE();
+ b6 = GET_BYTE();
+ b7 = GET_BYTE();
+
+ l = (b7 << 24) + (b6 << 16) + (b5 << 8) + b4;
+ l <<= 32;
+ l |= (b3 << 24) + (b2 << 16) + (b1 << 8) + b0;
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1)
+ printf("%lld(%#016llx)\n", l, l);
+#endif
+ return l;
+}
+
+static void
+put_longlongword(uint64_t v)
+{
+ put_byte(v);
+ put_byte(v >> 8);
+ put_byte(v >> 16);
+ put_byte(v >> 24);
+ put_byte(v >> 32);
+ put_byte(v >> 40);
+ put_byte(v >> 48);
+ put_byte(v >> 56);
+}
+#endif
+
static int
get_bytes(buf, len, size)
char *buf;
name_length = strlen(hdr->name);
while (header_size) {
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1)
+ printf("---\n");
+#endif
setup_get(data);
if (sizeof(data) < header_size) {
error("header size (%ld) too large.", header_size);
ext_type = get_byte();
switch (ext_type) {
case 0:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < header crc >\n");
+#endif
/* header crc (CRC-16) */
hdr->header_crc = get_word();
/* clear buffer for CRC calculation. */
skip_bytes(header_size - n - 2);
break;
case 1:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < filename >\n");
+#endif
/* filename */
name_length =
get_bytes(hdr->name, header_size-n, sizeof(hdr->name)-1);
hdr->name[name_length] = 0;
break;
case 2:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < directory >\n");
+#endif
/* directory */
dir_length = get_bytes(dirname, header_size-n, sizeof(dirname)-1);
dirname[dir_length] = 0;
break;
case 0x40:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < MS-DOS attribute >\n");
+#endif
/* MS-DOS attribute */
hdr->attribute = get_word();
break;
case 0x41:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < Windows time stamp (FILETIME) >\n");
+#endif
/* Windows time stamp (FILETIME structure) */
/* it is time in 100 nano seconds since 1601-01-01 00:00:00 */
skip_bytes(8); /* last access time is ignored */
break;
+ case 0x42:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < Windows file size header>\n");
+#endif
+#ifdef HAVE_UINT64_T
+ /* Windows file size header (UNLHA32 extension) */
+ hdr->packed_size = get_longlongword();
+ hdr->original_size = get_longlongword();
+#else
+ skip_bytes(8);
+ skip_bytes(8);
+#endif
+
+ break;
case 0x50:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < UNIX permission >\n");
+#endif
/* UNIX permission */
hdr->unix_mode = get_word();
break;
case 0x51:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < UNIX gid and uid >\n");
+#endif
/* UNIX gid and uid */
hdr->unix_gid = get_word();
hdr->unix_uid = get_word();
break;
case 0x52:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < UNIX group name >\n");
+#endif
/* UNIX group name */
i = get_bytes(hdr->group, header_size-n, sizeof(hdr->group)-1);
hdr->group[i] = '\0';
break;
case 0x53:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < UNIX user name >\n");
+#endif
/* UNIX user name */
i = get_bytes(hdr->user, header_size-n, sizeof(hdr->user)-1);
hdr->user[i] = '\0';
break;
case 0x54:
+#if DUMP_HEADER
+ if (verbose_listing && verbose > 1) printf(" < UNIX last modifed time (time_t) >\n");
+#endif
/* UNIX last modified time */
hdr->unix_last_modified_stamp = (time_t) get_longword();
break;
#define MAX_INDICATOR_COUNT 58
-static size_t reading_size;
+static off_t reading_size;
#ifdef NEED_INCREMENTAL_INDICATOR
-static size_t indicator_count;
+static off_t indicator_count;
static long indicator_threshold;
#endif
void
start_indicator(name, size, msg, def_indicator_threshold)
char *name;
- size_t size;
+ off_t size;
char *msg;
long def_indicator_threshold;
{
size_t header_size;
int size_field_length;
char method[METHOD_TYPE_STORAGE];
- size_t packed_size;
- size_t original_size;
+ off_t packed_size;
+ off_t original_size;
unsigned char attribute;
unsigned char header_level;
char name[FILENAME_LENGTH];
struct interfacing {
FILE *infile;
FILE *outfile;
- size_t original;
- size_t packed;
- size_t read_size;
+ off_t original;
+ off_t packed;
+ off_t read_size;
int dicbit;
int method;
};
/* slide.c */
EXTERN int unpackable;
-EXTERN size_t origsize, compsize;
+EXTERN off_t origsize, compsize;
EXTERN unsigned short dicbit;
EXTERN unsigned short maxmatch;
-EXTERN size_t decode_count;
+EXTERN off_t decode_count;
EXTERN unsigned long loc; /* short -> long .. Changed N.Watazaki */
EXTERN unsigned char *text;
LzHeader *hdr;
{
off_t header_pos, next_pos, org_pos, data_pos;
- size_t v_original_size, v_packed_size;
+ off_t v_original_size, v_packed_size;
reading_filename = hdr->name;
writing_filename = temporary_name;
/* ------------------------------------------------------------------------ */
void
temporary_to_new_archive_file(new_archive_size)
- size_t new_archive_size;
+ off_t new_archive_size;
{
FILE *oafp, *nafp;
int i;
long old_header;
boolean old_archive_exist;
- size_t new_archive_size;
+ off_t new_archive_size;
/* exit if no operation */
if (!update_if_newer && cmd_filec == 0) {
cmd_delete()
{
FILE *oafp, *nafp;
- size_t new_archive_size;
+ off_t new_archive_size;
/* open old archive if exist */
if ((oafp = open_old_archive()) == NULL)
}
/* ------------------------------------------------------------------------ */
-static size_t
+static off_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;
+ off_t read_size = 0;
if (ignore_directory && strrchr(hdr->name, '/')) {
q = (char *) strrchr(hdr->name, '/') + 1;
LzHeader hdr;
off_t pos;
FILE *afp;
- size_t read_size;
+ off_t read_size;
/* open archive file */
if ((afp = open_old_archive()) == NULL)
if (pos != -1 && afp != stdin)
fseeko(afp, pos + hdr.packed_size - read_size, SEEK_SET);
else {
- size_t i = hdr.packed_size - read_size;
+ off_t i = hdr.packed_size - read_size;
while (i--) fgetc(afp);
}
}
if (afp != stdin)
fseeko(afp, hdr.packed_size, SEEK_CUR);
else {
- size_t i = hdr.packed_size;
+ off_t i = hdr.packed_size;
while (i--) fgetc(afp);
}
}
static boolean
decode_macbinary(ofp, size, outPath)
FILE *ofp;
- size_t size;
+ off_t size;
const char *outPath;
{
af_file_t *afp = NULL;
FILE *ifp = NULL;
unsigned char *datap;
- size_t dlen;
+ off_t dlen;
if ((afp = af_open(temporary_name)) != NULL) {
/* fetch datafork */
static void
list_tailer(list_files, packed_size_total, original_size_total)
int list_files;
- unsigned long packed_size_total, original_size_total;
+ off_t packed_size_total, original_size_total;
{
struct stat stbuf;
LzHeader hdr;
int i;
- unsigned long packed_size_total;
- unsigned long original_size_total;
+ off_t packed_size_total;
+ off_t original_size_total;
int list_files;
/* initialize total count */
#endif
/* append.c */
-int encode_lzhuf P_((FILE *infp, FILE *outfp, size_t size, size_t *original_size_var, size_t *packed_size_var, char *name, char *hdr_method));
+int encode_lzhuf P_((FILE *infp, FILE *outfp, off_t size, off_t *original_size_var, off_t *packed_size_var, char *name, char *hdr_method));
/* bitio.c */
void fillbuf P_((int n));
unsigned short getbits P_((int n));
void output_dyn P_((unsigned int code, unsigned int pos));
void encode_end_dyn P_((void));
/* extract.c */
-int decode_lzhuf P_((FILE *infp, FILE *outfp, size_t original_size, size_t packed_size, char *name, int method, size_t *read_sizep));
+int decode_lzhuf P_((FILE *infp, FILE *outfp, off_t original_size, off_t packed_size, char *name, int method, off_t *read_sizep));
/* header.c */
int calc_sum P_((void *p, int len));
void convert_filename P_((char *name, int len, int size, int from_code, int to_code, char *from_delim, char *to_delim, int case_to));
unsigned short decode_p_st1 P_((void));
void decode_start_st1 P_((void));
/* indicator.c */
-void start_indicator P_((char *name, size_t size, char *msg, long def_indicator_threshold));
+void start_indicator P_((char *name, off_t size, char *msg, long def_indicator_threshold));
void put_indicator P_((long int count));
void finish_indicator2 P_((char *name, char *msg, int pcnt));
void finish_indicator P_((char *name, char *msg));
/* lhadd.c */
FILE *append_it P_((char *name, FILE *oafp, FILE *nafp));
FILE *build_temporary_file P_((void));
-void temporary_to_new_archive_file P_((size_t new_archive_size));
+void temporary_to_new_archive_file P_((off_t new_archive_size));
void cmd_add P_((void));
void cmd_delete P_((void));
/* lharc.c */
unsigned int encode P_((struct interfacing *interface));
unsigned int decode P_((struct interfacing *interface));
/* util.c */
-size_t copyfile P_((FILE *f1, FILE *f2, size_t size, int text_flg, unsigned int *crcp));
-int encode_stored_crc P_((FILE *ifp, FILE *ofp, size_t size, size_t *original_size_var, size_t *write_size_var));
+off_t copyfile P_((FILE *f1, FILE *f2, off_t size, int text_flg, unsigned int *crcp));
+int encode_stored_crc P_((FILE *ifp, FILE *ofp, off_t size, off_t *original_size_var, off_t *write_size_var));
boolean archive_is_msdos_sfx1 P_((char *name));
int xsnprintf P_((char *dest, size_t size, char *fmt, ...));
char *xstrchr P_((const char *s, int c));
char *xstrrchr P_((const char *s, int c));
-char *xmemchr P_((const char *s, int c, size_t n));
-char *xmemrchr P_((const char *s, int c, size_t n));
+char *xmemchr P_((const char *s, int c, off_t n));
+char *xmemrchr P_((const char *s, int c, off_t n));
int str_safe_copy P_((char *dst, const char *src, int dstsz));
/* util.c */
#if !HAVE_MEMMOVE
-void *memmove P_((void *dst, const void *src, size_t cnt));
+void *memmove P_((void *dst, const void *src, off_t cnt));
#endif
#if !HAVE_STRDUP
char *strdup P_((const char *buf));
#endif
#if !HAVE_MEMSET
-char *memset P_((char *s, int c, size_t n));
+char *memset P_((char *s, int c, off_t n));
#endif
#if !HAVE_STRCASECMP
int strcasecmp P_((const char *p1, const char *p2));
struct interfacing *interface;
{
unsigned int token, pos, crc;
- size_t count;
+ off_t count;
struct matchdata match, last;
#ifdef DEBUG
*/
#include <errno.h>
-size_t
+off_t
copyfile(f1, f2, size, text_flg, crcp) /* return: size of source file */
FILE *f1;
FILE *f2;
- size_t size;
+ off_t size;
int text_flg; /* 0: binary, 1: read text, 2: write text */
unsigned int *crcp;
{
unsigned short xsize;
char *buf;
- size_t rsize = 0;
+ off_t rsize = 0;
if (!text_mode)
text_flg = 0;
int
encode_stored_crc(ifp, ofp, size, original_size_var, write_size_var)
FILE *ifp, *ofp;
- size_t size;
- size_t *original_size_var;
- size_t *write_size_var;
+ off_t size;
+ off_t *original_size_var;
+ off_t *write_size_var;
{
int save_quiet;
unsigned int crc;