-/* $Id: compress.c,v 1.7 2000/09/13 14:02:02 cory Exp $
+/* $Id: compress.c,v 1.2 2000/12/14 18:45:35 ghazi Exp $
$Log: compress.c,v $
+ Revision 1.2 2000/12/14 18:45:35 ghazi
+ Warning fixes:
+
+ * compress.c: Include stdlib.h and compress.h.
+ (rcsid): Delete.
+ (report_str_error): Make static.
+ (ez_inflate_str): Delete unused variable. Add parens in if-stmt.
+ (hrd_inflate_str): Likewise.
+
+ * compress.h (init_compression, end_compression, init_inflation,
+ end_inflation): Prototype void arguments.
+
+ * dostime.c (rcsid): Delete.
+
+ * jargrep.c: Include ctype.h, stdlib.h, zlib.h and compress.h.
+ Make functions static. Cast ctype function argument to `unsigned
+ char'. Add parens in if-stmts. Constify.
+ (Usage): Change into a macro.
+ (jargrep): Remove unused parameter.
+
+ * jartool.c: Constify. Add parens in if-stmts. Align
+ signed/unsigned char pointers in functions calls using casts.
+ (rcsid): Delete.
+ (list_jar): Fix printf format specifier.
+ (usage): Chop long string into bits. Reformat.
+
+ * pushback.c (rcsid): Delete.
+
+ Revision 1.1 2000/12/09 03:08:23 apbianco
+ 2000-12-08 Alexandre Petit-Bianco <apbianco@cygnus.com>
+
+ * fastjar: Imported.
+
Revision 1.7 2000/09/13 14:02:02 cory
Reformatted some of the code to more closly match the layout of the orriginal
fastjar utility.
/*
compress.c - code for handling deflation
Copyright (C) 1999 Bryan Burns
+ Copyright (C) 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef STDC_HEADERS
+#include <stdlib.h>
+#endif
#include <sys/types.h>
#include "jartool.h"
#include "pushback.h"
+#include "compress.h"
+#include "shift.h"
-extern int seekable;
+int write_data (int, void *, size_t, struct zipentry *);
-static char rcsid[] = "$Id: compress.c,v 1.7 2000/09/13 14:02:02 cory Exp $";
+extern int seekable;
+extern off_t end_of_entries;
static z_stream zs;
}
}
-int compress_file(int in_fd, int out_fd, struct zipentry *ze){
+int
+write_data (int fd, void *buf, size_t len, struct zipentry *ze)
+{
+#ifdef WITH_SHIFT_DOWN
+ struct zipentry *next = NULL;
+ off_t here = lseek (fd, 0, SEEK_CUR);
+ /*
+ * If we are updating and there is not enough space before the next
+ * entry, expand the file.
+ */
+ if (ze)
+ {
+ next = ze->next_entry;
+ if (next && here + len >= next->offset)
+ {
+ if (shift_down (fd, next->offset, (here + len) - next->offset, next))
+ {
+ perror ("can't expand file");
+ exit (1);
+ }
+ }
+ }
+#endif /* WITH_SHIFT_DOWN */
+
+ return write (fd, buf, len);
+}
+
+int compress_file(int in_fd, int out_fd, struct zipentry *ze,
+ struct zipentry *existing)
+{
Bytef in_buff[RDSZ];
Bytef out_buff[RDSZ];
unsigned int rdamt, wramt;
unsigned long tr = 0;
+ int rtval;
rdamt = 0;
/* If deflate is out of input, fill the input buffer for it */
if(zs.avail_in == 0 && zs.avail_out > 0){
- if((rdamt = read(in_fd, in_buff, RDSZ)) == 0)
+ if((rtval = read(in_fd, in_buff, RDSZ)) == 0)
break;
- if(rdamt == -1){
+ if(rtval == -1){
perror("read");
exit(1);
}
-
+
+ rdamt = rtval;
+
/* compute the CRC while we're at it */
ze->crc = crc32(ze->crc, in_buff, rdamt);
/* If the output buffer is full, dump it to disk */
if(zs.avail_out == 0){
- if(write(out_fd, out_buff, RDSZ) != RDSZ){
- perror("write");
- exit(1);
- }
+ if (write_data (out_fd, out_buff, RDSZ, existing) != RDSZ)
+ {
+ perror("write");
+ exit(1);
+ }
/* clear the output buffer */
zs.next_out = out_buff;
wramt = RDSZ - zs.avail_out;
- if(write(out_fd, out_buff, wramt) != wramt){
- perror("write");
- exit(1);
- }
+ if (write_data (out_fd, out_buff, wramt, existing) != (int)wramt)
+ {
+ perror("write");
+ exit(1);
+ }
/* clear the output buffer */
zs.next_out = out_buff;
zs.avail_out = (uInt)RDSZ;
while(deflate(&zs, Z_FINISH) == Z_OK){
wramt = RDSZ - zs.avail_out;
- if(write(out_fd, out_buff, wramt) != wramt){
- perror("write");
- exit(1);
- }
+ if (write_data (out_fd, out_buff, wramt, existing) != (int)wramt)
+ {
+ perror("write");
+ exit(1);
+ }
zs.next_out = out_buff;
zs.avail_out = (uInt)RDSZ;
if(zs.avail_out != RDSZ){
wramt = RDSZ - zs.avail_out;
- if(write(out_fd, out_buff, wramt) != wramt){
- perror("write");
- exit(1);
- }
+ if (write_data (out_fd, out_buff, wramt, existing) != (int)wramt)
+ {
+ perror("write");
+ exit(1);
+ }
}
/* update fastjar's entry information */
if(zs.avail_in == 0){
if((rdamt = pb_read(pbf, in_buff, RDSZ)) == 0)
break;
- else if(rdamt < 0){
+ else if((int)rdamt < 0){
perror("read");
exit(1);
}
if(out_fd >= 0)
if(write(out_fd, out_buff, (RDSZ - zs.avail_out)) !=
- (RDSZ - zs.avail_out)){
+ (int)(RDSZ - zs.avail_out)){
perror("write");
exit(1);
}
if(out_fd >= 0)
if(write(out_fd, out_buff, (RDSZ - zs.avail_out)) !=
- (RDSZ - zs.avail_out)){
+ (int)(RDSZ - zs.avail_out)){
perror("write");
exit(1);
}
Be suitably cryptic seeing I don't really know exactly what these errors mean.
*/
-void report_str_error(int val) {
+static void report_str_error(int val) {
switch(val) {
case Z_STREAM_END:
break;
Bytef *out_buff;
Bytef *in_buff;
unsigned int rdamt;
- ub4 crc = 0;
- if(zs.next_in = in_buff = (Bytef *) malloc(csize)) {
- if(zs.next_out = out_buff = (Bytef *) malloc(usize + 1)) {
+ if((zs.next_in = in_buff = (Bytef *) malloc(csize))) {
+ if((zs.next_out = out_buff = (Bytef *) malloc(usize + 1))) {
if((rdamt = pb_read(pbf, zs.next_in, csize)) == csize) {
zs.avail_in = csize;
zs.avail_out = usize;
unsigned int rdamt;
int i;
int zret;
- ub4 crc = 0;
i = 1;
out_buff = NULL;
zs.avail_out = 0;
zs.next_in = in_buff;
do {
- if(tmp = (Bytef *) realloc(out_buff, (RDSZ * i) + 1)) {
+ if((tmp = (Bytef *) realloc(out_buff, (RDSZ * i) + 1))) {
out_buff = tmp;
zs.next_out = &(out_buff[(RDSZ * (i - 1)) - zs.avail_out]);
zs.avail_out += RDSZ;