gzip 1.3.5
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 11 Nov 1999 17:57:25 +0000 (17:57 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 11 Nov 1999 17:57:25 +0000 (17:57 +0000)
unlzw.c
zip.c

diff --git a/unlzw.c b/unlzw.c
index d68d0e7fb52efb4f9aed0c50015271481b6d31f6..5aa2eae54cfc8e042fd9ebe8f30645d943e7bfea 100644 (file)
--- a/unlzw.c
+++ b/unlzw.c
 static char rcsid[] = "$Id$";
 #endif
 
-#include <sys/types.h>
-
+#include <config.h>
 #include "tailor.h"
 
 #ifdef HAVE_UNISTD_H
 #  include <unistd.h>
 #endif
-#ifndef NO_FCNTL_H
+#ifdef HAVE_FCNTL_H
 #  include <fcntl.h>
 #endif
 
@@ -258,11 +257,11 @@ int unlzw(in, out)
        posbits = 0;
        
        if (insize < INBUF_EXTRA) {
-           if ((rsize = read(in, (char*)inbuf+insize, INBUFSIZ)) == EOF) {
+           if ((rsize = read(in, (char*)inbuf+insize, INBUFSIZ)) == -1) {
                read_error();
            }
            insize += rsize;
-           bytes_in += (ulg)rsize;
+           bytes_in += (off_t)rsize;
        }
        inbits = ((rsize != 0) ? ((long)insize - insize%n_bits)<<3 : 
                  ((long)insize<<3)-(n_bits-1));
@@ -316,7 +315,7 @@ int unlzw(in, out)
 #endif
                    if (!test && outpos > 0) {
                        write_buf(out, (char*)outbuf, outpos);
-                       bytes_out += (ulg)outpos;
+                       bytes_out += (off_t)outpos;
                    }
                    error(to_stdout ? "corrupt input." :
                          "corrupt input. Use zcat to recover some data.");
@@ -347,7 +346,7 @@ int unlzw(in, out)
                        if (outpos >= OUTBUFSIZ) {
                            if (!test) {
                                write_buf(out, (char*)outbuf, outpos);
-                               bytes_out += (ulg)outpos;
+                               bytes_out += (off_t)outpos;
                            }
                            outpos = 0;
                        }
@@ -371,7 +370,7 @@ int unlzw(in, out)
     
     if (!test && outpos > 0) {
        write_buf(out, (char*)outbuf, outpos);
-       bytes_out += (ulg)outpos;
+       bytes_out += (off_t)outpos;
     }
     return OK;
 }
diff --git a/zip.c b/zip.c
index 145116de1ea62cacc569aac425ab6875fb65967f..9d0b43f9e90cf9bbfd4ec0a1e67bbc64f85a2722 100644 (file)
--- a/zip.c
+++ b/zip.c
@@ -8,8 +8,8 @@
 static char rcsid[] = "$Id$";
 #endif
 
+#include <config.h>
 #include <ctype.h>
-#include <sys/types.h>
 
 #include "tailor.h"
 #include "gzip.h"
@@ -18,12 +18,12 @@ static char rcsid[] = "$Id$";
 #ifdef HAVE_UNISTD_H
 #  include <unistd.h>
 #endif
-#ifndef NO_FCNTL_H
+#ifdef HAVE_FCNTL_H
 #  include <fcntl.h>
 #endif
 
 local ulg crc;       /* crc on uncompressed file data */
-long header_bytes;   /* number of bytes in gzip header */
+off_t header_bytes;   /* number of bytes in gzip header */
 
 /* ===========================================================================
  * Deflate in to out.
@@ -52,7 +52,8 @@ int zip(in, out)
        flags |= ORIG_NAME;
     }
     put_byte(flags);         /* general flags */
-    put_long(time_stamp);
+    put_long(time_stamp == (time_stamp & 0xffffffff)
+            ? (ulg)time_stamp : (ulg)0);
 
     /* Write deflated file to zip file */
     crc = updcrc(0, 0);
@@ -65,12 +66,12 @@ int zip(in, out)
     put_byte(OS_CODE);            /* OS identifier */
 
     if (save_orig_name) {
-       char *p = basename(ifname); /* Don't save the directory part. */
+       char *p = base_name(ifname); /* Don't save the directory part. */
        do {
            put_char(*p);
        } while (*p++);
     }
-    header_bytes = (long)outcnt;
+    header_bytes = (off_t)outcnt;
 
     (void)deflate();
 
@@ -78,8 +79,7 @@ int zip(in, out)
   /* Check input size (but not in VMS -- variable record lengths mess it up)
    * and not on MSDOS -- diet in TSR mode reports an incorrect file size)
    */
-    if (ifile_size != -1L && isize != (ulg)ifile_size) {
-       Trace((stderr, " actual=%ld, read=%ld ", ifile_size, isize));
+    if (ifile_size != -1L && bytes_in != ifile_size) {
        fprintf(stderr, "%s: %s: file size changed while zipping\n",
                progname, ifname);
     }
@@ -87,7 +87,7 @@ int zip(in, out)
 
     /* Write the crc and uncompressed size */
     put_long(crc);
-    put_long(isize);
+    put_long((ulg)bytes_in);
     header_bytes += 2*sizeof(long);
 
     flush_outbuf();
@@ -109,9 +109,13 @@ int file_read(buf, size)
     Assert(insize == 0, "inbuf not empty");
 
     len = read(ifd, buf, size);
-    if (len == (unsigned)(-1) || len == 0) return (int)len;
+    if (len == 0) return (int)len;
+    if (len == (unsigned)-1) {
+       read_error();
+       return EOF;
+    }
 
     crc = updcrc((uch*)buf, len);
-    isize += (ulg)len;
+    bytes_in += (off_t)len;
     return (int)len;
 }