Commit 01eea494 authored by Jonas Termansen's avatar Jonas Termansen

fixup! Initial libdeflate.

parent 75e715e8
......@@ -341,6 +341,21 @@ uint32_t deflate_get_adler32(struct deflate_stream *stream)
return stream->zs.adler;
}
size_t deflate_compress_bound(struct deflate_stream *stream,
size_t uncompressed_size)
{
unsigned long worst_compressed_size;
if ( stream && stream->begun_kind != DEFLATE_BEGUN_KIND_NONE )
worst_compressed_size = deflateBound(&stream->zs, uncompressed_size);
else
worst_compressed_size = deflateBound(NULL, uncompressed_size);
// zlib doesn't protect against overflow. Try to poorly make up for it after
// the fact. We know it at least overflowed an unsigned long so return that.
if ( worst_compressed_size < uncompressed_size )
return ULONG_MAX;
return worst_compressed_size;
}
int deflate_process(struct deflate_stream *stream,
const unsigned char *input,
size_t input_size,
......@@ -517,13 +532,15 @@ const char *deflate_strerror(int errnum)
}
}
void realloc_shrink(void **ptr, size_t size)
static void realloc_shrink(void **ptr_ptr, size_t size)
{
// Avoid realloc returning NULL on success for zero-size allocations by not
// doing any such allocations.
void *newptr = realloc(*ptr, size ? size : 1);
// doing any such allocations.7c2a874e
void *ptr;
memcpy(&ptr, ptr_ptr, sizeof(void*)); // Strict aliasing.
void *newptr = realloc(ptr, size ? size : 1);
if ( newptr )
*ptr = newptr;
memcpy(ptr_ptr, &newptr, sizeof(void*)); // Strict aliasing.
}
int deflate_easy_process(struct deflate_stream *stream,
......
......@@ -53,7 +53,6 @@ enum deflate_flush
#define DEFLATE_LEVEL_FAST 1
#define DEFLATE_LEVEL_BEST 9
/* TODO: deflate_bound? git wants it and probably more. */
struct deflate_stream *deflate_create(void);
struct deflate_stream *deflate_create_compress(int /*level*/);
struct deflate_stream *deflate_create_compress_raw(int /*level*/);
......@@ -83,6 +82,8 @@ int deflate_get_dictionary(struct deflate_stream */*stream*/,
unsigned char */*dictionary*/,
size_t */*dictionary_length*/);
uint32_t deflate_get_adler32(struct deflate_stream */*stream*/);
size_t deflate_compress_bound(struct deflate_stream */*stream*/,
size_t /*uncompressed_size*/);
int deflate_process(struct deflate_stream *stream,
const unsigned char */*input*/,
size_t /*input_size*/,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment