1 /* zip.c -- compress files to the gzip or pkzip format
2 * Copyright (C) 1992-1993 Jean-loup Gailly
3 * This is free software; you can redistribute it and/or modify it under the
4 * terms of the GNU General Public License, see the file COPYING.
8 static char rcsid[] = "$Id$";
12 #include <sys/types.h>
25 local ulg crc; /* crc on uncompressed file data */
26 long header_bytes; /* number of bytes in gzip header */
28 /* ===========================================================================
30 * IN assertions: the input and output buffers are cleared.
31 * The variables time_stamp and save_orig_name are initialized.
34 int in, out; /* input and output file descriptors */
36 uch flags = 0; /* general purpose bit flags */
37 ush attr = 0; /* ascii/binary flag */
38 ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
44 /* Write the header to the gzip file. See algorithm.doc for the format */
47 put_byte(GZIP_MAGIC[0]); /* magic header */
48 put_byte(GZIP_MAGIC[1]);
49 put_byte(DEFLATED); /* compression method */
54 put_byte(flags); /* general flags */
57 /* Write deflated file to zip file */
61 ct_init(&attr, &method);
62 lm_init(level, &deflate_flags);
64 put_byte((uch)deflate_flags); /* extra flags */
65 put_byte(OS_CODE); /* OS identifier */
68 char *p = basename(ifname); /* Don't save the directory part. */
73 header_bytes = (long)outcnt;
77 #if !defined(NO_SIZE_CHECK) && !defined(RECORD_IO)
78 /* Check input size (but not in VMS -- variable record lengths mess it up)
79 * and not on MSDOS -- diet in TSR mode reports an incorrect file size)
81 if (ifile_size != -1L && isize != (ulg)ifile_size) {
82 Trace((stderr, " actual=%ld, read=%ld ", ifile_size, isize));
83 fprintf(stderr, "%s: %s: file size changed while zipping\n",
88 /* Write the crc and uncompressed size */
91 header_bytes += 2*sizeof(long);
98 /* ===========================================================================
99 * Read a new buffer from the current input file, perform end-of-line
100 * translation, and update the crc and input file size.
101 * IN assertion: size >= 2 (for end-of-line translation)
103 int file_read(buf, size)
109 Assert(insize == 0, "inbuf not empty");
111 len = read(ifd, buf, size);
112 if (len == (unsigned)(-1) || len == 0) return (int)len;
114 crc = updcrc((uch*)buf, len);