1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
|
#ifndef LINT
/* @(#) portable.c 2.24 88/08/24 01:22:06 */
static char sccsid[]="@(#) portable.c 2.24 88/08/24 01:22:06";
#endif /* LINT */
#include "options.h"
/*
Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
(C) Copyright 1988 Rahul Dhesi -- All rights reserved
*/
/**********************
portable.c contains functions needed to make Zoo portable to various
implementations of C.
Note: Provided a 2's complement machine is used, all functions in
this file are themselves machine-independent and need not be changed
when implementing Zoo on a different machine. Some code will choke
on 1's complement machines--I think.
For machine-dependent declarations see files "machine.h" and "options.h".
For machine-dependent functions see file "machine.c"
*/
#include "zoo.h"
#include "zooio.h"
#include "various.h"
#include "zoofns.h"
#include "machine.h"
#include "debug.h"
#include "assert.h"
#ifdef NEEDCTYP
#include <ctype.h> /* for tolower() */
#endif
#include "portable.h"
#ifdef TRACE_IO
extern int verbose;
#endif
/* Functions defined for use within this file only. */
long to_long PARMS((BYTE[]));
int to_int PARMS((BYTE[]));
void b_to_zooh PARMS((struct zoo_header *, BYTE[]));
void b_to_dir PARMS((struct direntry *, BYTE[]));
int dir_to_b PARMS((BYTE[], struct direntry *));
void zooh_to_b PARMS((BYTE[], struct zoo_header *));
void splitlong PARMS((BYTE[], long));
void splitint PARMS((BYTE[], int));
#ifdef TRACE_IO
void show_h PARMS ((struct zoo_header *));
void show_dir PARMS ((struct direntry *));
#endif /* TRACE_IO */
extern unsigned int crccode;
/************************************************************************/
/* I/O functions */
/************************************************************************/
/* some functions get defined only if they aren't already macros */
#ifndef zooread
int zooread (file, buffer, count)
ZOOFILE file; char *buffer; int count;
{ return (fread (buffer, 1, count, file)); }
#endif /* zooread */
#ifndef FIZ
#ifndef zoowrite
int zoowrite (file, buffer, count)
ZOOFILE file; char *buffer; int count;
{
if (file == NULLFILE)
return (count);
else
return (fwrite (buffer, 1, count, file));
}
#endif /* zoowrite */
ZOOFILE zoocreate (fname)
char *fname;
{ return ((ZOOFILE) fopen (fname, Z_NEW)); }
#endif /* FIZ */
#ifndef zooseek
long zooseek (file, offset, whence)
ZOOFILE file; long offset; int whence;
{ return (fseek (file, offset, whence)); }
#endif /* zooseek */
ZOOFILE zooopen (fname, option)
char *fname; char *option;
{ return ((ZOOFILE) fopen (fname, option)); }
#ifndef zootell
long zootell (file)
ZOOFILE file;
{ return ftell (file); }
#endif /* zootell */
int zooclose (file)
ZOOFILE file;
{ return fclose (file); }
/**********************
low_ch() is a macro that returns a lowercased char; it may be
used with any char, whether or not it is uppercase. It will
be used below by one or two functions.
*/
#define low_ch(c) (isupper(c) ? tolower(c) : c)
/************************************************************************/
/*** Following are functions that make up for various implementations ***/
/*** of C not having certain library routines. ***/
/************************************************************************/
#ifndef FIZ
/**********************
str_lwr() converts a string to lowercase and returns a pointer to the string
*/
char *str_lwr (str)
char *str;
{
register char *s;
s = str;
while (*s != '\0') {
*s = toascii(*s);
*s = low_ch(*s);
s++;
}
return (str);
}
/**********************
str_icmp() compares strings just like strcmp() but it does it without regard to
case.
*/
int str_icmp (s1, s2)
register char *s1, *s2;
{
for ( ; low_ch(*s1) == low_ch(*s2); s1++, s2++)
if (*s1 == '\0')
return(0);
return(low_ch(*s1) - low_ch(*s2));
}
#ifdef NEED_MEMSET
/**********************
memset() it sets the first "count" bytes of "dest" to the character
"c" and returns a pointer to "dest".
*/
VOIDPTR memset (dest, c, count)
register VOIDPTR dest;
int c;
unsigned count;
{
register unsigned i;
for (i = 0; i < count; i++) {
*((char *) (dest + i)) = c;
}
return dest;
}
#endif /* NEED_MEMSET */
#ifdef NEED_MEMCPY
/**********************
memcpy() copies "count" bytes from "src" to "dest" and returns
a pointer to "dest". Not necessarily safe for overlapping moves. */
VOIDPTR memcpy(dest, src, count)
register VOIDPTR dest;
register VOIDPTR src;
unsigned count;
{
VOIDPTR savedest = dest;
while (count > 0) {
*((char *) dest++) = *((char *) src++);
count--;
}
}
#endif /* NEED_MEMCPY */
#ifndef FPUTCHAR
/**********************
fputchar() writes a character to stdout. It is identical to putchar
but is a function, not a macro.
*/
int fputchar (c)
int c;
{
return (fputc(c, stdout));
}
#endif /* FPUTCHAR */
#endif /* FIZ */
/***********************************************************************/
/*** Following are declarations and functions that are written in a ***/
/*** machine-independent way but they implement machine-dependent ***/
/*** activities ***/
/***********************************************************************/
#ifndef DIRECT_CONVERT
/**********************
to_long() converts four consecutive bytes, in order of increasing
significance, to a long integer. It is used to make Zoo independent of the
byte order of the system.
*/
long to_long(data)
BYTE data[];
{
return (long) ((unsigned long) data[0] | ((unsigned long) data[1] << 8) |
((unsigned long) data[2] << 16) | ((unsigned long) data[3] << 24));
}
#ifndef FIZ
/********************
splitlong() converts a long integer to four consecutive BYTEs in order
of increasing significance.
*/
void splitlong(bytes, bigword)
BYTE bytes[];
long bigword;
{
int i;
for (i = 0; i < 4; i++) {
bytes[i] = bigword & 0xff;
bigword = (unsigned long) bigword >> 8;
}
}
#endif /* FIZ */
/*******************
splitint() converts an integer to two consecutive BYTEs in order
of increasing significance.
*/
void splitint(bytes, word)
BYTE bytes[];
int word;
{
bytes[0] = word & 0xff;
word = (unsigned int) word >> 8;
bytes[1] = word & 0xff;
}
/**********************
to_int() converts two consecutive bytes, in order of increasing
significance, to an integer, in a machine-independent manner
*/
int to_int(data)
BYTE data[];
{
return (int) ((unsigned int) data[0] | ((unsigned int) data[1] << 8));
}
#else /* else of ifndef DIRECT_CONVERT */
long to_long(data)
BYTE data[];
{
return ( * (long *) data );
}
#ifndef FIZ
/********************
splitlong() converts a long integer to four consecutive BYTEs in order
of increasing significance.
*/
void splitlong(bytes, bigword)
BYTE bytes[];
long bigword;
{
* (long *) bytes = bigword;
}
#endif /* FIZ */
/*******************
splitint() converts an integer to two consecutive BYTEs in order
of increasing significance.
*/
void splitint(bytes, word)
BYTE bytes[];
int word;
{
* (int *) bytes = word;
}
/**********************
to_int() converts two consecutive bytes, in order of increasing
significance, to an integer.
*/
int to_int(data)
BYTE data[];
{
return (*(int *) data);
}
#endif /* ifndef DIRECT_CONVERT .. else ... */
#ifndef FIZ
/**********************
Function frd_zooh() reads the header of a Zoo archive in a machine-
independent manner, from a ZOOFILE.
*/
int frd_zooh(zoo_header, zoo_file)
struct zoo_header *zoo_header;
ZOOFILE zoo_file;
{
int status;
BYTE bytes[SIZ_ZOOH]; /* canonical header representation */
#ifdef TRACE_IO
if (verbose) {
printf("At file position [%8lx] ", ftell(zoo_file));
}
#endif
status = zooread (zoo_file, (char *) bytes, SIZ_ZOOH);
b_to_zooh (zoo_header, bytes); /* convert array to structure */
#ifdef TRACE_IO
if (verbose) {
printf("frd_zooh: reading\n");
show_h(zoo_header);
}
#endif
if (status < MINZOOHSIZ)
return (-1);
else
return (0);
}
#endif /* FIZ */
/**********************
Function frd_dir() reads a directory entry in a machine-independent manner,
from a ZOOFILE.
*/
int frd_dir(direntry, zoo_file)
struct direntry *direntry;
ZOOFILE zoo_file;
{
int status;
BYTE bytes[MAXDIRSIZE]; /* big enough to hold variable part too */
/* To simplify things, we read the maximum possible size of the
directory entry including the variable size and discard what is not
needed */
#ifdef TRACE_IO
if (verbose) {
printf("At file position [%8lx] ", ftell(zoo_file));
}
#endif
status = zooread (zoo_file, (char *) bytes, MAXDIRSIZE);
if (status < SIZ_DIR)
return (-1);
b_to_dir (direntry, bytes);
#ifdef TRACE_IO
if (verbose) {
printf("frd_dir: reading\n");
show_dir(direntry);
}
#endif
/* #########################################################################
*
* THIS CODE WAS WRITTEN TO SOLVE PROBLEM WITH DIRECTORY TRAVERSAL SECURITY
* BUG (CVE id CAN-2005-2349).
*
* ########################################################################
*/
char *p;
/* take off '../' */
while ((p = strstr( direntry->dirname, "../" )) != NULL) {
while (*(p+3) != '\0') {
*p = *(p + 3);
p++;
}
*p = *(p+3); /* move last null */
//printf("zoo: skipped \"../\" path component in '%s'\n", direntry->dirname);
}
/* take off '/' */
if ( direntry->dirname[0] == '/' ) {
p = direntry->dirname;
while (*p != '\0') {
*p = *(p + 1);
p++;
}
*p = *(p+1); /* move last null */
//printf("zoo: skipped \"/\" path component in '%s'\n", direntry->dirname);
}
/* direntry->dirlen = strlen(direntry->dirname); */
/* ##################################################################
*
* END
*
* ###################################################################
*/
return (0);
}
#ifndef FIZ
/***********************
Function fwr_dir() writes a directory entry in a machine-independent manner
to a ZOOFILE. Return value is -1 on error, else 0.
*/
int fwr_dir(direntry, zoo_file)
struct direntry *direntry;
ZOOFILE zoo_file;
{
int size;
BYTE bytes[MAXDIRSIZE];
assert (direntry->type <= 2);
size = dir_to_b (bytes, direntry);
#ifdef TRACE_IO
if (verbose) {
printf("At file position [%8lx] ", ftell(zoo_file));
printf("fwr_dir: writing\n");
show_dir(direntry);
}
#endif
if (zoowrite (zoo_file, (char *) bytes, size) != size)
return (-1);
else
return (0);
}
/***********************
Function fwr_zooh() writes an archive header in a machine-independent manner
to a ZOOFILE. Return value is -1 if error else 0.
*/
int fwr_zooh(zoo_header, zoo_file)
struct zoo_header *zoo_header;
ZOOFILE zoo_file;
{
BYTE bytes[SIZ_ZOOH]; /* was SIZ_DIR -- probably a typo */
int hsize; /* how much to write -- depends on header type */
hsize = MINZOOHSIZ; /* in case it's an old type 0 header */
if (zoo_header->type > 0) /* but if it's a newer header... */
hsize = SIZ_ZOOH; /* ...size of new type 1 header */
zooh_to_b (bytes, zoo_header);
if (zoowrite (zoo_file, (char *) bytes, hsize) != hsize)
return (-1);
else
return (0);
}
/***********************
b_to_zooh() converts an array of BYTE to a zoo_header structure.
*/
void b_to_zooh (zoo_header, bytes)
struct zoo_header *zoo_header;
BYTE bytes[];
{
int i;
for (i = 0; i < SIZ_TEXT; i++) /* copy text */
zoo_header->text[i] = bytes[TEXT_I + i];
zoo_header->zoo_tag = to_long(&bytes[ZTAG_I]); /* copy zoo_tag */
zoo_header->zoo_start = to_long(&bytes[ZST_I]); /* copy zoo_start */
zoo_header->zoo_minus = to_long(&bytes[ZSTM_I]);
zoo_header->major_ver = bytes[MAJV_I]; /* copy versions */
zoo_header->minor_ver = bytes[MINV_I];
/* default is no archive comment and a header type of 0 */
zoo_header->type = 0;
zoo_header->acmt_pos = 0L;
zoo_header->acmt_len = 0;
zoo_header->vdata = 0;
if (zoo_header->zoo_start != FIXED_OFFSET) { /* if newer header */
zoo_header->type = bytes[HTYPE_I];
zoo_header->acmt_pos = to_long(&bytes[ACMTPOS_I]);
zoo_header->acmt_len = to_int(&bytes[ACMTLEN_I]);
zoo_header->vdata = bytes[HVDATA_I];
}
}
/***********************
zooh_to_b() converts a zoo_header structure to an array of BYTE.
*/
void zooh_to_b (bytes, zoo_header)
struct zoo_header *zoo_header;
BYTE bytes[];
{
int i;
for (i = 0; i < SIZ_TEXT; i++) /* copy text */
bytes[TEXT_I + i] = zoo_header->text[i];
splitlong (&bytes[ZTAG_I], zoo_header->zoo_tag);
splitlong (&bytes[ZST_I], zoo_header->zoo_start);
splitlong (&bytes[ZSTM_I], zoo_header->zoo_minus);
bytes[MAJV_I] = zoo_header->major_ver; /* copy versions */
bytes[MINV_I] = zoo_header->minor_ver;
bytes[HTYPE_I] = zoo_header->type; /* header type */
if (zoo_header->type > 0) {
splitlong (&bytes[ACMTPOS_I], zoo_header->acmt_pos); /* comment posn */
splitint (&bytes[ACMTLEN_I], zoo_header->acmt_len); /* comment len */
bytes[HVDATA_I] = zoo_header->vdata; /* version data */
}
} /* zooh_to_b() */
/************************
dir_to_b() converts a directory entry structure to an array of BYTE.
*/
int dir_to_b (bytes, direntry)
struct direntry *direntry;
BYTE bytes[];
{
int i;
int cursize;
int fixsize;
int totalsize;
splitlong(&bytes[DTAG_I], direntry->zoo_tag);
bytes[DTYP_I] = direntry->type ;
bytes[PKM_I] = direntry->packing_method ;
splitlong(&bytes[NXT_I], direntry->next);
splitlong(&bytes[OFS_I], direntry->offset);
splitint(&bytes[DAT_I], direntry->date);
splitint(&bytes[TIM_I], direntry->time);
splitint(&bytes[CRC_I], direntry->file_crc);
splitlong(&bytes[ORGS_I], direntry->org_size);
splitlong(&bytes[SIZNOW_I], direntry->size_now);
bytes[DMAJ_I] = direntry->major_ver;
bytes[DMIN_I] = direntry->minor_ver;
bytes[DEL_I] = direntry->deleted;
bytes[STRUC_I] = direntry->struc;
splitlong(&bytes[CMT_I], direntry->comment);
splitint(&bytes[CMTSIZ_I], direntry->cmt_size);
for (i = 0; i < FNM_SIZ; i++)
bytes[FNAME_I + i] = direntry->fname[i];
bytes[TZ_I] = NO_TZ; /* assume unknown */
bytes[NAMLEN_I] = 0;
bytes[DIRLEN_I] = 0;
cursize = SIZ_DIR; /* to count size of directory */
fixsize = SIZ_DIR; /* size of fixed part */
assert (direntry->type <= 2);
if (direntry->type == 2) { /* handle stuff relevant to type 2 */
cursize = SIZ_DIRL;
fixsize = SIZ_DIRL;
bytes[TZ_I] = direntry->tz;
assert(direntry->namlen < 256 && direntry->namlen >= 0);
cursize += 2; /* space for namlen and dirlen */
if (direntry->namlen != 0) {
bytes[NAMLEN_I] = direntry->namlen;
for (i = 0; i < direntry->namlen; i++)
bytes[LFNAME_I+i] = direntry->lfname[i];
cursize += direntry->namlen;
}
assert(direntry->dirlen < 256 && direntry->dirlen >= 0);
if (direntry->dirlen != 0) {
bytes[DIRLEN_I] = direntry->dirlen;
for (i = 0; i < direntry->dirlen; i++)
bytes[cursize+i] = direntry->dirname[i];
cursize += direntry->dirlen;
}
/* Can't store system id if no namlen & dirlen...BUG!...now fixed.
Fortunately, system_id was always 0 so far so it probably
got interpreted as namlen=0 and dirlen=0 (2 bytes) */
splitint(&bytes[cursize], direntry->system_id);
cursize += 2;
bytes[cursize] = direntry->fattr & 0xff; /* byte 0 */
splitint(&bytes[cursize+1], (int) (direntry->fattr >> 8)); /* 1 & 2 */
cursize += 3;
bytes[cursize] = (direntry->vflag & 0xff); /* version flag */
splitint(&bytes[cursize+1], direntry->version_no); /* version number */
cursize += 3;
}
splitint(&bytes[VARDIRLEN_I], direntry->var_dir_len);
assert(cursize ==
((bytes[DIRLEN_I] > 0 || bytes[NAMLEN_I] > 0) ? 2 : 0) +
fixsize + bytes[DIRLEN_I] + bytes[NAMLEN_I]
);
/* total size of dir entry is size of fixed part + size of var. part */
totalsize = fixsize + direntry->var_dir_len;
/* Do CRC assuming CRC field is zero, and stuff CRC into field. */
splitint(&bytes[DCRC_I], 0); /* fill with zeroes */
crccode = 0;
/* avoid mixing pointers to signed and unsigned char */
addbfcrc((char *) bytes, totalsize); /* update CRC */
splitint(&bytes[DCRC_I], crccode);
/* return total length of directory entry */
return (totalsize);
} /* dir_to_b() */
#endif /* FIZ */
/* b_to_dir() converts bytes to directory entry structure. The CRC of the
directory bytes, if any, is checked and a zero or nonzero value is returned
in direntry->dir_crc according as the check is good or bad */
void b_to_dir(direntry, bytes)
struct direntry *direntry;
BYTE bytes[];
{
int i;
int sysid_offs; /* temp variable */
unsigned int savecrc;
direntry->zoo_tag = to_long(&bytes[DTAG_I]);
direntry->type = bytes[DTYP_I];
direntry->packing_method = bytes[PKM_I];
direntry->next = to_long(&bytes[NXT_I]);
direntry->offset = to_long(&bytes[OFS_I]);
direntry->date = to_int(&bytes[DAT_I]);
direntry->time = to_int(&bytes[TIM_I]);
direntry->file_crc = to_int(&bytes[CRC_I]);
direntry->org_size = to_long(&bytes[ORGS_I]);
direntry->size_now = to_long(&bytes[SIZNOW_I]);
direntry->major_ver = bytes[DMAJ_I];
direntry->minor_ver = bytes[DMIN_I];
direntry->deleted = bytes[DEL_I];
direntry->struc = bytes[STRUC_I];
direntry->comment = to_long(&bytes[CMT_I]);
direntry->cmt_size = to_int(&bytes[CMTSIZ_I]);
/* for now, versions not implemented */
direntry->vflag = 0;
direntry->version_no = 0;
for (i = 0; i < FNM_SIZ; i++)
direntry->fname[i] = bytes[FNAME_I + i];
/* start by assuming variable part is zero bytes */
direntry->var_dir_len = direntry->dir_crc = 0;
direntry->namlen = direntry->dirlen = 0;
direntry->lfname[0] = direntry->dirname[0] = '\0';
direntry->tz = NO_TZ; /* assume unknown */
direntry->system_id = SYSID_NIX; /* default system_id if not present */
direntry->fattr = NO_FATTR; /* assume none */
assert (direntry->type <= 2);
if (direntry->type == 2) {
direntry->var_dir_len = to_int(&bytes[VARDIRLEN_I]);
assert(direntry->var_dir_len <= MAXDIRSIZE);
if (direntry->var_dir_len > MAXDIRSIZE)
direntry->var_dir_len = MAXDIRSIZE;
direntry->tz = bytes[TZ_I];
if (direntry->var_dir_len > 0)
direntry->namlen = bytes[NAMLEN_I];
if (direntry->var_dir_len > 1)
direntry->dirlen = bytes[DIRLEN_I];
for (i = 0; i < direntry->namlen; i++)
direntry->lfname[i] = bytes[LFNAME_I + i];
for (i = 0; i < direntry->dirlen; i++)
direntry->dirname[i] = bytes[DIRNAME_I + direntry->namlen + i];
sysid_offs = DIRNAME_I + direntry->namlen + i; /* offset of system id */
if (direntry->var_dir_len > direntry->namlen + direntry->dirlen + 2) {
direntry->system_id = to_int(&bytes[sysid_offs]);
}
if (direntry->var_dir_len > direntry->namlen + direntry->dirlen + 4) {
direntry->fattr = ((unsigned long) bytes[sysid_offs + 2]) |
((unsigned long) bytes[sysid_offs + 3] << 8) |
((unsigned long) bytes[sysid_offs + 4] << 16);
}
if (direntry->var_dir_len > direntry->namlen + direntry->dirlen + 7) {
direntry->vflag = bytes[sysid_offs + 5];
direntry->version_no = to_int(&bytes[sysid_offs + 6]);
}
/* do CRC calculation */
savecrc = (unsigned int) to_int(&bytes[DCRC_I]);
crccode = 0;
splitint(&bytes[DCRC_I], 0);
addbfcrc((char *) bytes, SIZ_DIRL + direntry->var_dir_len);
direntry->dir_crc = crccode - savecrc;
}
}
#ifdef FILTER
#define TWOBYTES 2 /* better than literal 2; figure out why */
/* rdint() reads two bytes from standard input in archive order */
int rdint (val)
unsigned int *val;
{
BYTE bytes[TWOBYTES];
if (zooread (STDIN, bytes, TWOBYTES) == TWOBYTES) {
*val = to_int(bytes);
return (0);
} else
return (1);
}
/* wrint() writes an unsigned int to standard output in archive order */
int wrint (val)
unsigned int val;
{
BYTE bytes[TWOBYTES];
splitint (bytes, val);
if (zoowrite (STDOUT, bytes, TWOBYTES) == TWOBYTES)
return (0);
else
return (1);
}
#endif /* FILTER */
#ifdef TRACE_IO
/* dump contents of archive header */
void show_h (zoo_header)
struct zoo_header *zoo_header;
{
int i;
printf ("Header text:\n");
for (i = 0; i < SIZ_TEXT; i++) { /* ASSUMES ASCII TEXT */
int c;
c = zoo_header->text[i];
if (c >= ' ' && c < 0x7f)
putchar (c);
else {
putchar ('^');
putchar (i & 0x40);
}
}
putchar('\n');
printf ("zoo_tag = [%8lx] zoo_start = [%8lx] zoo_minus = [%8lx]\n",
zoo_header->zoo_tag, zoo_header->zoo_start,
zoo_header->zoo_minus);
printf ("major_ver.minor_ver = [%d.%d]\n",
zoo_header->major_ver, zoo_header->minor_ver);
if (zoo_header->zoo_start != FIXED_OFFSET) {
printf ("type = [%d] ", zoo_header->type);
printf ("acmt_pos = [%8lx] acmt_len = [%4x] vdata = [%2x]",
zoo_header->acmt_pos, zoo_header->acmt_len, zoo_header->vdata);
printf ("\n");
}
printf ("---------\n");
}
/* dump contents of directory entry */
void show_dir (direntry)
struct direntry *direntry;
{
printf ("Directory entry for file [%s][%s]:\n",
direntry->fname, direntry->lfname);
printf ("tag = [%8lx] type = [%d] PM = [%d] Next = [%8lx] Offset = [%8lx]\n",
direntry->zoo_tag, (int) direntry->type,
(int) direntry->packing_method, direntry->next,
direntry->offset);
printf ("Orig size = [%ld] Size now = [%ld] dmaj_v.dmin_v = [%d.%d]\n",
direntry->org_size, direntry->size_now,
(int) direntry->major_ver, (int) direntry->minor_ver);
printf ("Struc = [%d] DEL = [%d] comment_offset = [%8lx] cmt_size = [%d]\n",
(int) direntry->struc, (int) direntry->deleted, direntry->comment,
direntry->cmt_size);
printf ("var_dir_len = [%d] TZ = [%d] dir_crc = [%4x]\n",
direntry->var_dir_len, (int) direntry->tz, direntry->dir_crc);
printf ("system_id = [%d] dirlen = [%d] namlen = [%d] fattr=[%24lx]\n",
direntry->system_id, direntry->dirlen, direntry->namlen, direntry->fattr);
printf ("vflag = [%4x] version_no = [%4x]\n",
direntry->vflag, direntry->version_no);
if (direntry->dirlen > 0)
printf ("dirname = [%s]\n", direntry->dirname);
printf ("---------\n");
}
#endif /* TRACE_IO */
|