63 #define WINSIZE 32768U 93 off_t
in, off_t
out,
unsigned left,
unsigned char *window)
101 index->list =
malloc(
sizeof(
struct point) << 3);
102 if (index->list ==
NULL) {
111 else if (index->have == index->size) {
113 next = realloc(index->list,
sizeof(
struct point) * index->size);
122 next = index->list + index->have;
127 memcpy(next->window, window +
WINSIZE - left, left);
129 memcpy(next->window + left, window,
WINSIZE - left);
167 totin = totout = last = 0;
175 goto build_index_error;
179 goto build_index_error;
201 goto build_index_error;
215 (totout == 0 || totout - last > span)) {
220 goto build_index_error;
229 index->list = realloc(index->list,
sizeof(
struct point) * index->have);
230 index->size = index->have;
250 unsigned char *
buf,
int len)
256 unsigned char discard[
WINSIZE];
265 while (--ret && here[1].
out <= offset)
277 ret = fseeko(in, here->in - (here->bits ? 1 : 0),
SEEK_SET);
296 if (offset == 0 && skip) {
306 else if (offset != 0) {
354 int main(
int argc,
char **argv)
364 fprintf(stderr,
"usage: zran file.gz\n");
367 in = fopen(argv[1],
"rb");
369 fprintf(stderr,
"zran: could not open %s for reading\n", argv[1]);
379 fprintf(stderr,
"zran: out of memory\n");
382 fprintf(stderr,
"zran: compressed data error in %s\n", argv[1]);
385 fprintf(stderr,
"zran: read error on %s\n", argv[1]);
388 fprintf(stderr,
"zran: error %d while building index\n", len);
392 fprintf(stderr,
"zran: built index with %d access points\n", len);
395 offset = (index->list[index->have - 1].out << 1) / 3;
398 fprintf(stderr,
"zran: extraction failed: %s error\n",
399 len ==
Z_MEM_ERROR ?
"out of memory" :
"input corrupted");
401 fwrite(buf, 1, len, stdout);
402 fprintf(stderr,
"zran: extracted %d bytes at %llu\n", len, offset);
GLuint GLint GLboolean GLint GLenum access
GLenum GLenum GLvoid GLvoid GLvoid * span
local int extract(FILE *in, struct access *index, off_t offset, unsigned char *buf, int len)
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
int main(int argc, char **argv)
#define inflateInit2(strm, windowBits)
GLenum GLuint GLenum GLsizei const GLchar * buf
local int build_index(FILE *in, off_t span, struct access **built)
int ZEXPORT inflatePrime(z_streamp strm, int bits, int value)
GLenum GLenum GLenum input
local int out(void *out_desc, unsigned char *buf, unsigned len)
int ZEXPORT inflate(z_streamp strm, int flush)
local void free_index(struct access *index)
local void skip(file *in, unsigned n)
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
local struct access * addpoint(struct access *index, int bits, off_t in, off_t out, unsigned left, unsigned char *window)
int ZEXPORT inflateEnd(z_streamp strm)