|
|
1.1.1.2 ! 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: ! 20: /* Use the raw functions for MSDOS and Unix to save on buffer space. ! 21: They're not used for VMS since it doesn't work (raw is weird on VMS). ! 22: (This sort of stuff belongs in fileio.c, but oh well.) */ ! 23: #ifdef VMS ! 24: typedef FILE *ftype; ! 25: # define fhow FOPR ! 26: # define fbad NULL ! 27: # define zopen(n,p) fopen(n,p) ! 28: # define zread(f,b,n) fread(b,1,n,f) ! 29: # define zclose(f) fclose(f) ! 30: # define zerr(f) ferror(f) ! 31: # define zrew(f) rewind(f) ! 32: # define zstdin stdin ! 33: #else /* !VMS */ ! 34: # ifdef MSDOS ! 35: # include <io.h> ! 36: # include <fcntl.h> ! 37: # define fhow (O_RDONLY|O_BINARY) ! 38: # else /* !MSDOS */ ! 39: #ifndef AMIGA ! 40: int open OF((char *, int)); ! 41: int read OF((int, char *, int)); ! 42: int close OF((int)); ! 43: long lseek OF((int, long, int)); ! 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: ! 62: int zipup(FILE *inFile, FILE *y) ! 63: /* Compress the file fileName and write it to the file *y. Return an error ! 64: code in the ZE_ class. Also, update tempzn by the number of bytes written. */ ! 65: /* ??? Does not yet handle non-seekable y */ ! 66: { ! 67: int m; /* method for this entry */ ! 68: long q = -1L; /* size returned by filetime */ ! 69: ush att; /* internal file attributes (dummy only) */ ! 70: ush flg; /* gp compresion flags (dummy only) */ ! 71: ! 72: /* Set input file and find its size */ ! 73: #ifdef VMS ! 74: ifile = inFile; ! 75: fseek(ifile, 0L, SEEK_END); ! 76: q = ftell(ifile); ! 77: fseek(ifile, 0L, SEEK_SET); ! 78: #else ! 79: ifile = fileno( inFile ); ! 80: q = lseek(ifile, 0L, SEEK_END); ! 81: lseek(ifile, 0L, SEEK_SET); ! 82: #endif /* VMS */ ! 83: ! 84: m = (q == 0) ? STORE : DEFLATE; ! 85: ! 86: if (m == DEFLATE) { ! 87: bi_init(y); ! 88: att = UNKNOWN; ! 89: ct_init(&att, &m); ! 90: lm_init(level, &flg); ! 91: /* s = */ deflate(); ! 92: } ! 93: ! 94: return(0); ! 95: } ! 96: ! 97: int read_buf(buf, size) ! 98: char far *buf; ! 99: unsigned size; ! 100: /* Read a new buffer from the current input file, and update the crc and ! 101: * input file size. ! 102: * IN assertion: size >= 2 (for end-of-line translation) */ ! 103: { ! 104: unsigned len; ! 105: ! 106: len = zread(ifile, buf, size); ! 107: if (len == (unsigned)EOF || len == 0) return len; ! 108: return len; ! 109: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.