/* gzlib.c -- zlib functions common to reading and writing gzip files
* Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* $FreeBSD$ */
#include "gzguts.h"
#include "zutil.h"
#if defined(_WIN32) && !defined(__BORLANDC__)
#else
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
#else
#endif
#endif
/* Local functions */
#if defined UNDER_CE
/* Map the Windows error number in ERROR to a locale-dependent error message
string and return a pointer to it. Typically, the values for ERROR come
from GetLastError.
The string pointed to shall not be modified by the application, but may be
overwritten by a subsequent call to gz_strwinerror
The gz_strwinerror function does not change the current setting of
GetLastError. */
{
NULL,
0, /* Default language */
0,
NULL);
if (chars != 0) {
/* If there is an \r\n appended, zap it. */
if (chars >= 2
chars -= 2;
}
}
}
else {
}
return buf;
}
#endif /* UNDER_CE */
/* Reset gzip file state */
{
}
}
/* Open a gzip file either by name or file descriptor. */
const void *path;
int fd;
const char *mode;
{
int oflag;
#ifdef O_CLOEXEC
int cloexec = 0;
#endif
#ifdef O_EXCL
int exclusive = 0;
#endif
/* check input */
return NULL;
/* allocate gzFile structure to return */
return NULL;
/* interpret mode */
while (*mode) {
else
switch (*mode) {
case 'r':
break;
#ifndef NO_GZCOMPRESS
case 'w':
break;
case 'a':
break;
#endif
case '+': /* can't read and write at the same time */
return NULL;
case 'b': /* ignore -- will request binary anyway */
break;
#ifdef O_CLOEXEC
case 'e':
cloexec = 1;
break;
#endif
#ifdef O_EXCL
case 'x':
exclusive = 1;
break;
#endif
case 'f':
break;
case 'h':
break;
case 'R':
break;
case 'F':
break;
case 'T':
break;
default: /* could consider as an error, but just ignore */
;
}
mode++;
}
/* must provide an "r", "w", or "a" */
return NULL;
}
/* can't force transparent read */
return NULL;
}
}
/* save the path name for error messages */
#ifdef _WIN32
if (fd == -2) {
len = 0;
}
else
#endif
return NULL;
}
#ifdef _WIN32
if (fd == -2)
if (len)
else
else
#endif
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
#else
#endif
/* compute the flags for open() */
oflag =
#ifdef O_LARGEFILE
#endif
#ifdef O_BINARY
O_BINARY |
#endif
#ifdef O_CLOEXEC
#endif
O_RDONLY :
#ifdef O_EXCL
#endif
O_TRUNC :
O_APPEND)));
/* open the file with the appropriate flags (or just use fd) */
#ifdef _WIN32
#endif
return NULL;
}
/* save the current position for rewinding (only if reading) */
}
/* initialize stream */
/* return stream */
}
/* -- see zlib.h -- */
const char *path;
const char *mode;
{
}
/* -- see zlib.h -- */
const char *path;
const char *mode;
{
}
/* -- see zlib.h -- */
int fd;
const char *mode;
{
return NULL;
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
#else
#endif
return gz;
}
/* -- see zlib.h -- */
#ifdef _WIN32
const char *mode;
{
}
#endif
/* -- see zlib.h -- */
unsigned size;
{
/* get internal structure and check integrity */
return -1;
return -1;
/* make sure we haven't already allocated memory */
return -1;
/* check and set requested size */
if (size < 2)
return 0;
}
/* -- see zlib.h -- */
{
/* get internal structure */
return -1;
/* check that we're reading and that there's no error */
return -1;
/* back up and start over */
return -1;
return 0;
}
/* -- see zlib.h -- */
int whence;
{
unsigned n;
/* get internal structure and check integrity */
return -1;
return -1;
/* check that there's no error */
return -1;
/* can only seek from start or relative to current position */
return -1;
/* normalize offset to a SEEK_CUR specification */
/* if within raw area while reading, just go there */
if (ret == -1)
return -1;
}
/* calculate skip amount, rewinding if needed for back seek when reading */
if (offset < 0) {
return -1;
if (offset < 0) /* before start of file! */
return -1;
return -1;
}
/* if reading, skip what's in output buffer (one less gzgetc() check) */
offset -= n;
}
/* request skip (if not zero) */
if (offset) {
}
}
/* -- see zlib.h -- */
int whence;
{
}
/* -- see zlib.h -- */
{
/* get internal structure and check integrity */
return -1;
return -1;
/* return position */
}
/* -- see zlib.h -- */
{
}
/* -- see zlib.h -- */
{
/* get internal structure and check integrity */
return -1;
return -1;
/* compute and return effective offset in file */
if (offset == -1)
return -1;
return offset;
}
/* -- see zlib.h -- */
{
}
/* -- see zlib.h -- */
{
/* get internal structure and check integrity */
return 0;
return 0;
/* return end-of-file state */
}
/* -- see zlib.h -- */
int *errnum;
{
/* get internal structure and check integrity */
return NULL;
return NULL;
/* return error information */
}
/* -- see zlib.h -- */
{
/* get internal structure and check integrity */
return;
return;
/* clear error and end-of-file */
}
}
/* Create an error message in allocated memory and set state->err and
state->msg accordingly. Free any previous error message already there. Do
not try to free or allocate space if the error is Z_MEM_ERROR (out of
memory). Simply save the error message as a static string. If there is an
allocation failure constructing the error message, then convert the error to
out of memory. */
int err;
const char *msg;
{
/* free previously allocated message and clear */
}
/* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
/* set error code, and if no message, then done */
return;
/* for an out of memory error, return literal string when requested */
if (err == Z_MEM_ERROR)
return;
/* construct error message with path */
NULL) {
return;
}
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
#else
#endif
return;
}
#ifndef INT_MAX
/* portably return maximum value for an int (when limits.h presumed not
available) -- we need to do this to cover cases where 2's complement not
used, since C standard permits 1's complement and sign-bit representations,
otherwise we could just use ((unsigned)-1) >> 1 */
{
unsigned p, q;
p = 1;
do {
q = p;
p <<= 1;
p++;
} while (p > q);
return q >> 1;
}
#endif