/* to use, do: ./configure --cover && make cover */
#include <stdio.h>
-#include <stdlib.h>
+#ifdef HAVE_BSD_STDLIB
+# include <bsd/stdlib.h>
+#else
+# include <stdlib.h>
+#endif
#include <string.h>
#include <assert.h>
#include "zlib.h"
#include "inftrees.h"
#include "inflate.h"
-#define local static
-
/* reallocf is BSD-specific */
#ifndef reallocf
-# define reallocf realloc
+static void *reallocf(void *ptr, size_t size)
+{
+ void *ret = realloc(ptr, size);
+ if ((ret == NULL) && (ptr != NULL) && (size != 0))
+ free(ptr);
+ return ret;
+}
#endif
};
/* memory allocation routine to pass to zlib */
-local void *mem_alloc(void *mem, unsigned count, unsigned size)
+static void *mem_alloc(void *mem, unsigned count, unsigned size)
{
void *ptr;
struct mem_item *item;
}
/* memory free routine to pass to zlib */
-local void mem_free(void *mem, void *ptr)
+static void mem_free(void *mem, void *ptr)
{
struct mem_item *item, *next;
struct mem_zone *zone = mem;
/* set up a controlled memory allocation space for monitoring, set the stream
parameters to the controlled routines, with opaque pointing to the space */
-local void mem_setup(z_stream *strm)
+static void mem_setup(z_stream *strm)
{
struct mem_zone *zone;
}
/* set a limit on the total memory allocation, or 0 to remove the limit */
-local void mem_limit(z_stream *strm, size_t limit)
+static void mem_limit(z_stream *strm, size_t limit)
{
struct mem_zone *zone = strm->opaque;
}
/* show the current total requested allocations in bytes */
-local void mem_used(z_stream *strm, char *prefix)
+static void mem_used(z_stream *strm, char *prefix)
{
struct mem_zone *zone = strm->opaque;
}
/* show the high water allocation in bytes */
-local void mem_high(z_stream *strm, char *prefix)
+static void mem_high(z_stream *strm, char *prefix)
{
struct mem_zone *zone = strm->opaque;
}
/* release the memory allocation zone -- if there are any surprises, notify */
-local void mem_done(z_stream *strm, char *prefix)
+static void mem_done(z_stream *strm, char *prefix)
{
int count = 0;
struct mem_item *item, *next;
delimiter in which case that single digit writes a byte. The returned
data is allocated and must eventually be freed. NULL is returned if out of
memory. If the length is not needed, then len can be NULL. */
-local unsigned char *h2b(const char *hex, unsigned *len)
+static unsigned char *h2b(const char *hex, unsigned *len)
{
unsigned char *in;
unsigned next, val;
header information is collected with inflateGetHeader(). If a zlib stream
is looking for a dictionary, then an empty dictionary is provided.
inflate() is run until all of the input data is consumed. */
-local void inf(char *hex, char *what, unsigned step, int win, unsigned len, int err)
+static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int err)
{
int ret;
unsigned have;
}
/* cover all of the lines in inflate.c up to inflate() */
-local void cover_support(void)
+static void cover_support(void)
{
int ret;
z_stream strm;
}
/* cover all inflate() header and trailer cases and code after inflate() */
-local void cover_wrap(void)
+static void cover_wrap(void)
{
int ret;
z_stream strm, copy;
}
/* input and output functions for inflateBack() */
-local unsigned pull(void *desc, const unsigned char **buf)
+static unsigned pull(void *desc, const unsigned char **buf)
{
static unsigned int next = 0;
static unsigned char dat[] = {0x63, 0, 2, 0};
return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0;
}
-local int push(void *desc, unsigned char *buf, unsigned len)
+static int push(void *desc, unsigned char *buf, unsigned len)
{
buf += len;
return desc != Z_NULL; /* force error if desc not null */
}
/* cover inflateBack() up to common deflate data cases and after those */
-local void cover_back(void)
+static void cover_back(void)
{
int ret;
z_stream strm;
}
/* do a raw inflate of data in hexadecimal with both inflate and inflateBack */
-local int try(char *hex, char *id, int err)
+static int try(char *hex, char *id, int err)
{
int ret;
unsigned len, size;
}
/* cover deflate data cases in both inflate() and inflateBack() */
-local void cover_inflate(void)
+static void cover_inflate(void)
{
try("0 0 0 0 0", "invalid stored block lengths", 1);
try("3 0", "fixed", 0);
}
/* cover remaining lines in inftrees.c */
-local void cover_trees(void)
+static void cover_trees(void)
{
int ret;
unsigned bits;
}
/* cover remaining inffast.c decoding and window copying */
-local void cover_fast(void)
+static void cover_fast(void)
{
inf("e5 e0 81 ad 6d cb b2 2c c9 01 1e 59 63 ae 7d ee fb 4d fd b5 35 41 68"
" ff 7f 0f 0 0 0", "fast length extra bits", 0, -8, 258, Z_DATA_ERROR);