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.
6 * $FreeBSD: src/gnu/usr.bin/gzip/zip.c,v 1.6 1999/08/27 23:35:56 peter Exp $
7 * $DragonFly: src/gnu/usr.bin/gzip/Attic/zip.c,v 1.2 2003/06/17 04:25:46 dillon Exp $
11 #include <sys/types.h>
24 local ulg crc; /* crc on uncompressed file data */
25 long header_bytes; /* number of bytes in gzip header */
27 /* ===========================================================================
29 * IN assertions: the input and output buffers are cleared.
30 * The variables time_stamp and save_orig_name are initialized.
33 int in, out; /* input and output file descriptors */
35 uch flags = 0; /* general purpose bit flags */
36 ush attr = 0; /* ascii/binary flag */
37 ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
43 /* Write the header to the gzip file. See algorithm.doc for the format */
46 put_byte(GZIP_MAGIC[0]); /* magic header */
47 put_byte(GZIP_MAGIC[1]);
48 put_byte(DEFLATED); /* compression method */
53 put_byte(flags); /* general flags */
56 /* Write deflated file to zip file */
60 ct_init(&attr, &method);
61 lm_init(level, &deflate_flags);
63 put_byte((uch)deflate_flags); /* extra flags */
64 put_byte(OS_CODE); /* OS identifier */
67 char *p = basename(ifname); /* Don't save the directory part. */
72 header_bytes = (long)outcnt;
76 #if !defined(NO_SIZE_CHECK) && !defined(RECORD_IO)
77 /* Check input size (but not in VMS -- variable record lengths mess it up)
78 * and not on MSDOS -- diet in TSR mode reports an incorrect file size)
80 if (ifile_size != -1L && isize != (ulg)ifile_size) {
81 Trace((stderr, " actual=%ld, read=%ld ", ifile_size, isize));
82 fprintf(stderr, "%s: %s: file size changed while zipping\n",
87 /* Write the crc and uncompressed size */
90 header_bytes += 2*sizeof(long);
97 /* ===========================================================================
98 * Read a new buffer from the current input file, perform end-of-line
99 * translation, and update the crc and input file size.
100 * IN assertion: size >= 2 (for end-of-line translation)
102 int file_read(buf, size)
108 Assert(insize == 0, "inbuf not empty");
110 len = read(ifd, buf, size);
111 if (len == (unsigned)(-1) || len == 0) return (int)len;
113 crc = updcrc((uch*)buf, len);