1 /* 2 * zipio.h - stdio emulation library for reading zip files 3 * 4 * Version 1.1.2 5 */ 6 7 /* 8 * Copyright (C) 1995, Edward B. Hamrick 9 * 10 * Permission to use, copy, modify, and distribute this software and 11 * its documentation for any purpose and without fee is hereby granted, 12 * provided that the above copyright notice appear in all copies and 13 * that both that copyright notice and this permission notice appear in 14 * supporting documentation, and that the name of the copyright holders 15 * not be used in advertising or publicity pertaining to distribution of 16 * the software without specific, written prior permission. The copyright 17 * holders makes no representations about the suitability of this software 18 * for any purpose. It is provided "as is" without express or implied warranty. 19 * 20 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS 21 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, 22 * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT 23 * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 24 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 25 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 26 * OF THIS SOFTWARE. 27 */ 28 29 /* 30 * Changes from 1.1 to 1.1.1: 31 * Changed "z*" functions to "Z*" to avoid namespace pollution. 32 * Added "zungetc" macro. 33 * John Cowan <cowan@ccil.org> 34 * 35 * Changes from 1.1.1 to 1.1.2: 36 * Relicensed under the MIT license, with consent of the copyright holders. 37 * Claudio Matsuoka (Jan 11 2011) 38 */ 39 40 /* 41 * This library of routines has the same calling sequence as 42 * the stdio.h routines for reading files. If these routines 43 * detect that they are reading from a zip file, they transparently 44 * unzip the file and make the application think they're reading 45 * from the uncompressed file. 46 * 47 * Note that this library is designed to work for zip files that 48 * use the deflate compression method, and to read the first file 49 * within the zip archive. 50 * 51 * There are a number of tunable parameters in the reference 52 * implementation relating to in-memory decompression and the 53 * use of temporary files. 54 * 55 * Particular care was taken to make the Zgetc() macro work 56 * as efficiently as possible. When reading an uncompressed 57 * file with Zgetc(), it has exactly the same performance as 58 * when using getc(). WHen reading a compressed file with 59 * Zgetc(), it has the same performance as fread(). The total 60 * CPU overhead for decompression is about 50 cycles per byte. 61 * 62 * The Zungetc() macro is quite limited. It ignores the character 63 * specified for pushback, and essentially just forces the last 64 * character read to be re-read. This is essential when parsing 65 * numbers and such. (1.1.1) 66 * 67 * There are a few stdio routines that aren't represented here, but 68 * they can be layered on top of these routines if needed. 69 */ 70 71 #ifndef __ZIPIO_H 72 #define __ZIPIO_H 73 74 #include <stdio.h> 75 76 typedef struct { 77 int len; 78 unsigned char *ptr; 79 } ZFILE; 80 81 #define Zgetc(f) \ 82 ((--((f)->len) >= 0) \ 83 ? (unsigned char)(*(f)->ptr++) \ 84 : _Zgetc (f)) 85 86 #define Zungetc(c,f) \ 87 ((f)->ptr--, (f)->len++, (c)) 88 89 #ifdef __cplusplus 90 extern "C" { 91 #endif 92 93 ZFILE *Zopen(const char *path, const char *mode); 94 int _Zgetc(ZFILE *stream); 95 size_t Zread(void *ptr, size_t size, size_t n, ZFILE *stream); 96 int Zseek(ZFILE *stream, long offset, int whence); 97 long Ztell(ZFILE *stream); 98 int Zclose(ZFILE *stream); 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 #endif 105