diff --git a/common/gzip_utils/gzip_utils.c b/common/gzip_utils/gzip_utils.c index c3224dd..25012de 100644 --- a/common/gzip_utils/gzip_utils.c +++ b/common/gzip_utils/gzip_utils.c @@ -128,35 +128,22 @@ int gu_decompress_mem(const void *src, long src_size, void **dst, long *dst_size int gu_decompress_file_to_mem(const char *filename, void **dst, long *dst_size) { FILE *f = NULL; - int ret = 0; - gzFile gzf = NULL; - long size = 0; - void *buf = NULL; - - // Open and read file contents + void *src = NULL; + long src_size = 0; if (NULL == (f = fopen(filename, "rb"))) { return 1; } fseek(f, 0, SEEK_END); - size = ftell(f); + src_size = ftell(f); rewind(f); - buf = malloc(size); - if (NULL == buf) { - return 1; - } - fread(buf, 1, size, f); + src = malloc(src_size); + fread(src, 1, src_size, f); fclose(f); - // Attempt decompress of file, returning a copy of buf in dst if - // decompression fails (ofc a bit unoptimized to not just use same pointer) - ret = gu_decompress_mem(buf, size, dst, dst_size); - - free(buf); - - return ret; + return gu_decompress_mem(src, src_size, dst, dst_size); } #ifdef _WIN32 @@ -166,8 +153,7 @@ int gu_decompress_file_to_mem_u(const wchar_t *filename, void **dst, long *dst_s void *src = NULL; long src_size = 0; - if (NULL == (f = _wfopen(filename, L"rb"))) - { + if (NULL == (f = _wfopen(filename, L"rb"))) { return 1; }