OSDN Git Service

* doc/invoke.texi (-mfix-and-continue): Add support for
[pf3gnuchains/gcc-fork.git] / fastjar / compress.c
index 0f919d7..ec1d5c4 100644 (file)
@@ -1,6 +1,39 @@
-/* $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.
@@ -41,6 +74,7 @@
 /*
   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;
 
@@ -98,11 +138,41 @@ void init_compression(){
   }
 }
 
-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;
 
@@ -118,14 +188,16 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){
     
     /* 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); 
 
@@ -145,10 +217,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){
     /* 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;
@@ -163,10 +236,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){
 
     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;
@@ -177,10 +251,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){
   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;
@@ -190,10 +265,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){
   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 */
@@ -254,7 +330,7 @@ int inflate_file(pb_file *pbf, int out_fd, struct zipentry *ze){
     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);
       }
@@ -280,7 +356,7 @@ int inflate_file(pb_file *pbf, int out_fd, struct zipentry *ze){
 
           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);
             }
@@ -297,7 +373,7 @@ int inflate_file(pb_file *pbf, int out_fd, struct zipentry *ze){
 
         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);
           }
@@ -335,7 +411,7 @@ purpose: Put out an error message corresponding to error code returned from zlib
 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;
@@ -376,10 +452,9 @@ static Bytef *ez_inflate_str(pb_file *pbf, ub4 csize, ub4 usize) {
        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;
@@ -430,7 +505,6 @@ static Bytef *hrd_inflate_str(pb_file *pbf, ub4 *csize, ub4 *usize) {
        unsigned int rdamt;
        int i;
        int zret;
-       ub4 crc = 0;
 
        i = 1; 
        out_buff = NULL;
@@ -441,7 +515,7 @@ static Bytef *hrd_inflate_str(pb_file *pbf, ub4 *csize, ub4 *usize) {
                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;