version 1.12, 2003/07/11 02:31:18 |
version 1.13, 2003/07/17 20:06:01 |
|
|
long zs_ratio; |
long zs_ratio; |
count_int zs_checkpoint; |
count_int zs_checkpoint; |
long zs_in_count; /* Length of input. */ |
long zs_in_count; /* Length of input. */ |
long zs_bytes_out; /* Length of compressed output. */ |
long zs_bytes_out; /* Length of output. */ |
long zs_out_count; /* # of codes output (for debugging).*/ |
long zs_out_count; /* # of codes output (for debugging).*/ |
u_char zs_buf[ZBUFSIZ]; /* I/O buffer */ |
u_char zs_buf[ZBUFSIZ]; /* I/O buffer */ |
u_char *zs_bp; /* Current I/O window in the zs_buf */ |
u_char *zs_bp; /* Current I/O window in the zs_buf */ |
|
|
} |
} |
|
|
int |
int |
zclose(void *cookie) |
z_close(void *cookie, struct z_info *info) |
{ |
{ |
struct s_zstate *zs; |
struct s_zstate *zs; |
int rval; |
int rval; |
|
|
return (-1); |
return (-1); |
} |
} |
} |
} |
|
|
|
if (info != NULL) { |
|
info->mtime = 0; |
|
info->crc = (u_int32_t)-1; |
|
info->hlen = 0; |
|
info->total_in = (off_t)zs->zs_in_count; |
|
info->total_out = (off_t)zs->zs_bytes_out; |
|
} |
|
|
rval = close(zs->zs_fd); |
rval = close(zs->zs_fd); |
free(zs); |
free(zs); |
return (rval); |
return (rval); |
} |
} |
|
|
|
int |
|
zclose(void *cookie) |
|
{ |
|
return z_close(cookie, NULL); |
|
} |
|
|
/*- |
/*- |
* Output the given code. |
* Output the given code. |
* Inputs: |
* Inputs: |
|
|
return (-1); |
return (-1); |
} |
} |
zs->zs_maxbits = header[2]; /* Set -b from file. */ |
zs->zs_maxbits = header[2]; /* Set -b from file. */ |
|
zs->zs_in_count += sizeof(header); |
zs->zs_block_compress = zs->zs_maxbits & BLOCK_MASK; |
zs->zs_block_compress = zs->zs_maxbits & BLOCK_MASK; |
zs->zs_maxbits &= BIT_MASK; |
zs->zs_maxbits &= BIT_MASK; |
zs->zs_maxmaxcode = 1L << zs->zs_maxbits; |
zs->zs_maxmaxcode = 1L << zs->zs_maxbits; |
|
|
|
|
/* And put them out in forward order. */ |
/* And put them out in forward order. */ |
middle: do { |
middle: do { |
if (count-- == 0) |
if (count-- == 0) { |
|
zs->zs_bytes_out += num; |
return (num); |
return (num); |
|
} |
*bp++ = *--zs->zs_stackp; |
*bp++ = *--zs->zs_stackp; |
} while (zs->zs_stackp > de_stack); |
} while (zs->zs_stackp > de_stack); |
|
|
|
|
zs->zs_oldcode = zs->zs_incode; |
zs->zs_oldcode = zs->zs_incode; |
} |
} |
zs->zs_state = S_EOF; |
zs->zs_state = S_EOF; |
|
zs->zs_bytes_out += num - count; |
eof: return (num - count); |
eof: return (num - count); |
} |
} |
|
|
|
|
if ((bits = read(zs->zs_fd, bp, ZBUFSIZ - |
if ((bits = read(zs->zs_fd, bp, ZBUFSIZ - |
(bp - zs->zs_buf))) < 0) |
(bp - zs->zs_buf))) < 0) |
return -1; |
return -1; |
|
zs->zs_in_count += bits; |
zs->zs_bp = zs->zs_buf; |
zs->zs_bp = zs->zs_buf; |
zs->zs_ebp = bp + bits; |
zs->zs_ebp = bp + bits; |
} |
} |
|
|
if ((fd = open(name, (*mode=='r'? O_RDONLY:O_WRONLY|O_CREAT), |
if ((fd = open(name, (*mode=='r'? O_RDONLY:O_WRONLY|O_CREAT), |
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1) |
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1) |
return NULL; |
return NULL; |
if ((cookie = z_open(fd, mode, bits, 0)) == NULL) { |
if ((cookie = z_open(fd, mode, NULL, bits, 0, 0)) == NULL) { |
close(fd); |
close(fd); |
return NULL; |
return NULL; |
} |
} |
|
|
} |
} |
|
|
void * |
void * |
z_open(int fd, const char *mode, int bits, int gotmagic) |
z_open(int fd, const char *mode, char *name, int bits, |
|
u_int32_t mtime, int gotmagic) |
{ |
{ |
struct s_zstate *zs; |
struct s_zstate *zs; |
|
|
|
|
zs->zs_clear_flg = 0; |
zs->zs_clear_flg = 0; |
zs->zs_ratio = 0; |
zs->zs_ratio = 0; |
zs->zs_checkpoint = CHECK_GAP; |
zs->zs_checkpoint = CHECK_GAP; |
zs->zs_in_count = 1; /* Length of input. */ |
zs->zs_in_count = 0; /* Length of input. */ |
zs->zs_out_count = 0; /* # of codes output (for debugging).*/ |
zs->zs_out_count = 0; /* # of codes output (for debugging).*/ |
zs->zs_state = gotmagic ? S_MAGIC : S_START; |
zs->zs_state = gotmagic ? S_MAGIC : S_START; |
zs->zs_offset = 0; |
zs->zs_offset = 0; |