|
|
1.1 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>
17: #include "zip.h"
18: #include "zrevisio.h"
19: #ifdef OS2
20: # include "dir_os2.h"
21: #endif /* OS2 */
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: #ifndef AMIGA
43: int open OF((char *, int));
44: int read OF((int, char *, int));
45: int close OF((int));
46: long lseek OF((int, long, int));
47: #endif /* AMIGA */
48: # define fhow 0
49: # endif /* ?MSDOS */
50: typedef int ftype;
51: # define fbad (-1)
52: # define zopen(n,p) open(n,p)
53: # define zread(f,b,n) read(f,b,n)
54: # define zclose(f) close(f)
55: # define zerr(f) (k==(extent)(-1L))
56: # define zrew(f) lseek(f,0L,0)
57: # define zstdin 0
58: #endif /* ?VMS */
59:
60: /* Local data */
61:
62: local ftype ifile; /* file to compress */
63:
64:
65: int zipup(FILE *inFile, FILE *y)
66: /* Compress the file fileName and write it to the file *y. Return an error
67: code in the ZE_ class. Also, update tempzn by the number of bytes written. */
68: /* ??? Does not yet handle non-seekable y */
69: {
70: int m; /* method for this entry */
71: long q = -1L; /* size returned by filetime */
72: ush att; /* internal file attributes (dummy only) */
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:
97: return(0);
98: }
99:
100: int read_buf(buf, size)
101: char far *buf;
102: unsigned size;
103: /* Read a new buffer from the current input file, and update the crc and
104: * input file size.
105: * IN assertion: size >= 2 (for end-of-line translation) */
106: {
107: unsigned len;
108:
109: len = zread(ifile, buf, size);
110: if (len == (unsigned)EOF || len == 0) return len;
111: return len;
112: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.