📄 compress.c
字号:
/* $Id: compress.c,v 1.1 2006/01/03 15:27:00 robilad Exp $ $Log: compress.c,v $ Revision 1.1 2006/01/03 15:27:00 robilad Merged in fastjar 2006-01-03 Dalibor Topic <robilad@kaffe.org> * Makefile.am: (SUBDIRS) Added external subdir. (DIST_SUBDIRS) Added external subdir. * THIRDPARTY: Added information on fastjar. Adapted information on zlib. * configure.ac: (--with-internal-zlib) Replaced by (--with-system-zlib), so that kaffe now uses the merged in zlib by default, like gcc does. (--disable-fastjar) New option. Added fastjar subdir for configuration, and the Makefile for output. * kaffe/scripts/jar.in: Delegate to fastjar * libraries/clib/Makefile.am (SUBDIRS): Removed zlib. * libraries/clib/zip/Makefile.am (COND_INTERNAL_ZLIB) Replaced by (COND_SYSTEM_ZLIB). Adapted to use internal zlib from external/gcc directory. * libraries/javalib/Makefile.am: Regenerated. * libraries/javalib/vmspecific/org/kaffe/tools/jar/Jar.java libraries/javalib/vmspecific/org/kaffe/tools/jar/XPFile.java libraries/javalib/vmspecific/org/kaffe/tools/jar/XPFileInputStream.java libraries/javalib/vmspecific/org/kaffe/tools/jar/XPFileOutputStream.java libraries/javalib/vmspecific/org/kaffe/tools/jar/XPFileReader.java libraries/javalib/vmspecific/org/kaffe/tools/jar/XPFileWriter.java: Removed. * libraries/clib/zlib : Moved over to external/gcc/zlib. * external/gcc/fastjar: New files. Merged in from gcc 4.0.2. Slightly adapted the build system to behave well when merged into Kaffe. 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. Revision 1.6 2000/09/12 22:29:36 cory Jargrep now seems to do what I want it to do. Performs properly on Linux x86, will test some other platforms later. Revision 1.1.1.1 1999/12/06 03:09:16 toast initial checkin.. Revision 1.7 1999/05/10 08:50:05 burnsbr *** empty log message *** Revision 1.6 1999/05/10 08:38:44 burnsbr *** empty log message *** Revision 1.5 1999/05/10 08:30:29 burnsbr added inflation code Revision 1.4 1999/04/27 10:03:33 burnsbr added configure support Revision 1.3 1999/04/26 02:35:32 burnsbr compression now works.. yahoo Revision 1.2 1999/04/23 12:01:59 burnsbr added licence stuff. Revision 1.1 1999/04/23 11:58:25 burnsbr Initial revision*//* 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 as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "config.h"#include <zlib.h>#include <string.h>#include <stdio.h>#include <errno.h>#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"int write_data (int, void *, size_t, struct zipentry *);extern int seekable;extern off_t end_of_entries;static z_stream zs;void init_compression(){ memset(&zs, 0, sizeof(z_stream)); zs.zalloc = Z_NULL; zs.zfree = Z_NULL; zs.opaque = Z_NULL; /* Why -MAX_WBITS? zlib has an undocumented feature, where if the windowbits parameter is negative, it omits the zlib header, which seems to kill any other zip/unzip program. This caused me SO much pain.. */ if(deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, 9, Z_DEFAULT_STRATEGY) != Z_OK){ fprintf(stderr, "Error initializing deflation!\n"); exit(1); }}intwrite_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; zs.avail_in = 0; zs.next_in = in_buff; zs.next_out = out_buff; zs.avail_out = (uInt)RDSZ; ze->crc = crc32(0L, Z_NULL, 0); for(; ;){ /* If deflate is out of input, fill the input buffer for it */ if(zs.avail_in == 0 && zs.avail_out > 0){ if((rtval = read(in_fd, in_buff, RDSZ)) == 0) break; 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); /* update the total amount read sofar */ tr += rdamt; zs.next_in = in_buff; zs.avail_in = rdamt; } /* deflate the data */ if(deflate(&zs, 0) != Z_OK){ fprintf(stderr, "Error deflating! %s:%d\n", __FILE__, __LINE__); exit(1); } /* If the output buffer is full, dump it to disk */ if(zs.avail_out == 0){ if (write_data (out_fd, out_buff, RDSZ, existing) != RDSZ) { perror("write"); exit(1); } /* clear the output buffer */ zs.next_out = out_buff; zs.avail_out = (uInt)RDSZ; } } /* If we have any data waiting in the buffer after we're done with the file we can flush it */ if(zs.avail_out < RDSZ){ wramt = RDSZ - zs.avail_out; 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; } /* finish deflation. This purges zlib's internal data buffers */ while(deflate(&zs, Z_FINISH) == Z_OK){ wramt = RDSZ - zs.avail_out; 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -