|
|
1.1.1.5 root 1: /*
2:
3: Copyright (C) 1990,1991 Mark Adler, Richard B. Wales, and Jean-loup Gailly.
4: Permission is granted to any individual or institution to use, copy, or
5: redistribute this software so long as all of the original files are included
6: unmodified, that it is not sold for profit, and that this copyright notice
7: is retained.
8:
9: */
10:
11: /*
12: * zipup.c by Mark Adler. Includes modifications by Jean-loup Gailly.
13: */
14:
15: #define NOCPYRT /* this is not a main module */
16: #include <ctype.h>
1.1.1.6 ! root 17: #ifdef __QNX__
! 18: #include <unistd.h>
! 19: #endif
1.1.1.5 root 20: #include "zip.h"
21: #include "zrevisio.h"
22:
23: /* Use the raw functions for MSDOS and Unix to save on buffer space.
24: They're not used for VMS since it doesn't work (raw is weird on VMS).
25: (This sort of stuff belongs in fileio.c, but oh well.) */
26: #ifdef VMS
27: typedef FILE *ftype;
28: # define fhow FOPR
29: # define fbad NULL
30: # define zopen(n,p) fopen(n,p)
31: # define zread(f,b,n) fread(b,1,n,f)
32: # define zclose(f) fclose(f)
33: # define zerr(f) ferror(f)
34: # define zrew(f) rewind(f)
35: # define zstdin stdin
36: #else /* !VMS */
37: # ifdef MSDOS
38: # include <io.h>
39: # include <fcntl.h>
40: # define fhow (O_RDONLY|O_BINARY)
41: # else /* !MSDOS */
42: #if !(defined(AMIGA) || defined(__NetBSD__))
43: long lseek();
44: #endif /* AMIGA */
45: # define fhow 0
46: # endif /* ?MSDOS */
47: typedef int ftype;
48: # define fbad (-1)
49: # define zopen(n,p) open(n,p)
50: # define zread(f,b,n) read(f,b,n)
51: # define zclose(f) close(f)
52: # define zerr(f) (k==(extent)(-1L))
53: # define zrew(f) lseek(f,0L,0)
54: # define zstdin 0
55: #endif /* ?VMS */
56:
57: /* Local data */
58:
59: local ftype ifile; /* file to compress */
60:
61: void lm_free();
62: void ct_free();
63:
64: /* Compress the file fileName and write it to the file *y. Return an error
1.1.1.6 ! root 65: code in the ZE_ class. Also, update tempzn by the number of bytes written.
! 66: */
! 67: int zipup(FILE *inFile, FILE *y)
1.1.1.5 root 68: /* ??? Does not yet handle non-seekable y */
69: {
70: int m; /* method for this entry */
71: long q = -1L; /* size returned by filetime */
1.1.1.6 ! root 72: ush att; /* internal file attributes (dummy only) */
1.1.1.5 root 73: ush flg; /* gp compresion flags (dummy only) */
74:
75: /* Set input file and find its size */
76: #ifdef VMS
77: ifile = inFile;
78: fseek(ifile, 0L, SEEK_END);
79: q = ftell(ifile);
80: fseek(ifile, 0L, SEEK_SET);
81: #else
82: ifile = fileno( inFile );
83: q = lseek(ifile, 0L, SEEK_END);
84: lseek(ifile, 0L, SEEK_SET);
85: #endif /* VMS */
86:
87: m = (q == 0) ? STORE : DEFLATE;
88:
89: if (m == DEFLATE) {
90: bi_init(y);
91: att = UNKNOWN;
92: ct_init(&att, &m);
93: lm_init(level, &flg);
94: /* s = */ deflate();
95: }
96: lm_free();
97: ct_free();
98:
99: return(0);
100: }
101:
102: int read_buf(buf, size)
103: char far *buf;
104: unsigned size;
105: /* Read a new buffer from the current input file, and update the crc and
106: * input file size.
107: * IN assertion: size >= 2 (for end-of-line translation) */
108: {
109: unsigned len;
110:
111: len = zread(ifile, buf, size);
112: if (len == (unsigned)EOF || len == 0) return len;
113: return len;
114: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.