summaryrefslogtreecommitdiffstats
path: root/src/H5Zdeflate.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
commitb2d661b508a7fc7a2592c13bc6bdc175551f075d (patch)
tree13baeb0d83a7c2a4c6299993c182b1227c2f6114 /src/H5Zdeflate.c
parent29ab58b58dce556639ea3154e262895773a8a8df (diff)
downloadhdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.zip
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.gz
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.bz2
Clang-format of source files
Diffstat (limited to 'src/H5Zdeflate.c')
-rw-r--r--src/H5Zdeflate.c169
1 files changed, 83 insertions, 86 deletions
diff --git a/src/H5Zdeflate.c b/src/H5Zdeflate.c
index d46108f..63a4a7c 100644
--- a/src/H5Zdeflate.c
+++ b/src/H5Zdeflate.c
@@ -16,42 +16,40 @@
* Friday, August 27, 1999
*/
-#include "H5Zmodule.h" /* This source code file is part of the H5Z module */
+#include "H5Zmodule.h" /* This source code file is part of the H5Z module */
-
-#include "H5private.h" /* Generic Functions */
-#include "H5Eprivate.h" /* Error handling */
-#include "H5MMprivate.h" /* Memory management */
-#include "H5Zpkg.h" /* Data filters */
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5MMprivate.h" /* Memory management */
+#include "H5Zpkg.h" /* Data filters */
#ifdef H5_HAVE_FILTER_DEFLATE
#if defined(H5_HAVE_ZLIB_H) && !defined(H5_ZLIB_HEADER)
-# define H5_ZLIB_HEADER "zlib.h"
+#define H5_ZLIB_HEADER "zlib.h"
#endif
#if defined(H5_ZLIB_HEADER)
-# include H5_ZLIB_HEADER /* "zlib.h" */
+#include H5_ZLIB_HEADER /* "zlib.h" */
#endif
/* Local function prototypes */
-static size_t H5Z__filter_deflate (unsigned flags, size_t cd_nelmts,
- const unsigned cd_values[], size_t nbytes, size_t *buf_size, void **buf);
+static size_t H5Z__filter_deflate(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], size_t nbytes,
+ size_t *buf_size, void **buf);
/* This message derives from H5Z */
const H5Z_class2_t H5Z_DEFLATE[1] = {{
- H5Z_CLASS_T_VERS, /* H5Z_class_t version */
- H5Z_FILTER_DEFLATE, /* Filter id number */
- 1, /* encoder_present flag (set to true) */
- 1, /* decoder_present flag (set to true) */
- "deflate", /* Filter name for debugging */
- NULL, /* The "can apply" callback */
- NULL, /* The "set local" callback */
- H5Z__filter_deflate, /* The actual filter function */
+ H5Z_CLASS_T_VERS, /* H5Z_class_t version */
+ H5Z_FILTER_DEFLATE, /* Filter id number */
+ 1, /* encoder_present flag (set to true) */
+ 1, /* decoder_present flag (set to true) */
+ "deflate", /* Filter name for debugging */
+ NULL, /* The "can apply" callback */
+ NULL, /* The "set local" callback */
+ H5Z__filter_deflate, /* The actual filter function */
}};
#define H5Z_DEFLATE_SIZE_ADJUST(s) (HDceil(((double)(s)) * (double)1.001f) + 12)
-
/*-------------------------------------------------------------------------
* Function: H5Z__filter_deflate
*
@@ -67,13 +65,12 @@ const H5Z_class2_t H5Z_DEFLATE[1] = {{
*-------------------------------------------------------------------------
*/
static size_t
-H5Z__filter_deflate(unsigned flags, size_t cd_nelmts,
- const unsigned cd_values[], size_t nbytes,
- size_t *buf_size, void **buf)
+H5Z__filter_deflate(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], size_t nbytes,
+ size_t *buf_size, void **buf)
{
- void *outbuf = NULL; /* Pointer to new buffer */
- int status; /* Status from zlib operation */
- size_t ret_value = 0; /* Return value */
+ void * outbuf = NULL; /* Pointer to new buffer */
+ int status; /* Status from zlib operation */
+ size_t ret_value = 0; /* Return value */
FUNC_ENTER_STATIC
@@ -83,122 +80,122 @@ H5Z__filter_deflate(unsigned flags, size_t cd_nelmts,
HDassert(*buf);
/* Check arguments */
- if (cd_nelmts!=1 || cd_values[0]>9)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid deflate aggression level")
+ if (cd_nelmts != 1 || cd_values[0] > 9)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid deflate aggression level")
if (flags & H5Z_FLAG_REVERSE) {
- /* Input; uncompress */
- z_stream z_strm; /* zlib parameters */
- size_t nalloc = *buf_size; /* Number of bytes for output (compressed) buffer */
+ /* Input; uncompress */
+ z_stream z_strm; /* zlib parameters */
+ size_t nalloc = *buf_size; /* Number of bytes for output (compressed) buffer */
/* Allocate space for the compressed buffer */
- if (NULL==(outbuf = H5MM_malloc(nalloc)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for deflate uncompression")
+ if (NULL == (outbuf = H5MM_malloc(nalloc)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for deflate uncompression")
/* Set the uncompression parameters */
- HDmemset(&z_strm, 0, sizeof(z_strm));
- z_strm.next_in = (Bytef *)*buf;
+ HDmemset(&z_strm, 0, sizeof(z_strm));
+ z_strm.next_in = (Bytef *)*buf;
H5_CHECKED_ASSIGN(z_strm.avail_in, unsigned, nbytes, size_t);
- z_strm.next_out = (Bytef *)outbuf;
+ z_strm.next_out = (Bytef *)outbuf;
H5_CHECKED_ASSIGN(z_strm.avail_out, unsigned, nalloc, size_t);
/* Initialize the uncompression routines */
- if (Z_OK!=inflateInit(&z_strm))
- HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "inflateInit() failed")
+ if (Z_OK != inflateInit(&z_strm))
+ HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "inflateInit() failed")
/* Loop to uncompress the buffer */
- do {
+ do {
/* Uncompress some data */
- status = inflate(&z_strm, Z_SYNC_FLUSH);
+ status = inflate(&z_strm, Z_SYNC_FLUSH);
/* Check if we are done uncompressing data */
- if (Z_STREAM_END==status)
- break; /*done*/
+ if (Z_STREAM_END == status)
+ break; /*done*/
/* Check for error */
- if (Z_OK!=status) {
- (void)inflateEnd(&z_strm);
- HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "inflate() failed")
- }
+ if (Z_OK != status) {
+ (void)inflateEnd(&z_strm);
+ HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "inflate() failed")
+ }
else {
/* If we're not done and just ran out of buffer space, get more */
- if(0 == z_strm.avail_out) {
- void *new_outbuf; /* Pointer to new output buffer */
+ if (0 == z_strm.avail_out) {
+ void *new_outbuf; /* Pointer to new output buffer */
/* Allocate a buffer twice as big */
nalloc *= 2;
- if(NULL == (new_outbuf = H5MM_realloc(outbuf, nalloc))) {
+ if (NULL == (new_outbuf = H5MM_realloc(outbuf, nalloc))) {
(void)inflateEnd(&z_strm);
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for deflate uncompression")
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0,
+ "memory allocation failed for deflate uncompression")
} /* end if */
outbuf = new_outbuf;
/* Update pointers to buffer for next set of uncompressed data */
- z_strm.next_out = (unsigned char*)outbuf + z_strm.total_out;
+ z_strm.next_out = (unsigned char *)outbuf + z_strm.total_out;
z_strm.avail_out = (uInt)(nalloc - z_strm.total_out);
} /* end if */
- } /* end else */
- } while(status==Z_OK);
+ } /* end else */
+ } while (status == Z_OK);
/* Free the input buffer */
- H5MM_xfree(*buf);
+ H5MM_xfree(*buf);
/* Set return values */
- *buf = outbuf;
- outbuf = NULL;
- *buf_size = nalloc;
- ret_value = z_strm.total_out;
+ *buf = outbuf;
+ outbuf = NULL;
+ *buf_size = nalloc;
+ ret_value = z_strm.total_out;
/* Finish uncompressing the stream */
- (void)inflateEnd(&z_strm);
+ (void)inflateEnd(&z_strm);
} /* end if */
else {
- /*
- * Output; compress but fail if the result would be larger than the
- * input. The library doesn't provide in-place compression, so we
- * must allocate a separate buffer for the result.
- */
- const Bytef *z_src = (const Bytef*)(*buf);
- Bytef *z_dst; /*destination buffer */
- uLongf z_dst_nbytes = (uLongf)H5Z_DEFLATE_SIZE_ADJUST(nbytes);
- uLong z_src_nbytes = (uLong)nbytes;
- int aggression; /* Compression aggression setting */
+ /*
+ * Output; compress but fail if the result would be larger than the
+ * input. The library doesn't provide in-place compression, so we
+ * must allocate a separate buffer for the result.
+ */
+ const Bytef *z_src = (const Bytef *)(*buf);
+ Bytef * z_dst; /*destination buffer */
+ uLongf z_dst_nbytes = (uLongf)H5Z_DEFLATE_SIZE_ADJUST(nbytes);
+ uLong z_src_nbytes = (uLong)nbytes;
+ int aggression; /* Compression aggression setting */
/* Set the compression aggression level */
H5_CHECKED_ASSIGN(aggression, int, cd_values[0], unsigned);
/* Allocate output (compressed) buffer */
- if(NULL == (outbuf = H5MM_malloc(z_dst_nbytes)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "unable to allocate deflate destination buffer")
+ if (NULL == (outbuf = H5MM_malloc(z_dst_nbytes)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "unable to allocate deflate destination buffer")
z_dst = (Bytef *)outbuf;
/* Perform compression from the source to the destination buffer */
- status = compress2(z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression);
+ status = compress2(z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression);
/* Check for various zlib errors */
- if(Z_BUF_ERROR == status)
- HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "overflow")
- else if(Z_MEM_ERROR == status)
- HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "deflate memory error")
- else if(Z_OK != status)
- HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "other deflate error")
+ if (Z_BUF_ERROR == status)
+ HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "overflow")
+ else if (Z_MEM_ERROR == status)
+ HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "deflate memory error")
+ else if (Z_OK != status)
+ HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "other deflate error")
/* Successfully uncompressed the buffer */
else {
/* Free the input buffer */
- H5MM_xfree(*buf);
+ H5MM_xfree(*buf);
/* Set return values */
- *buf = outbuf;
- outbuf = NULL;
- *buf_size = nbytes;
- ret_value = z_dst_nbytes;
- } /* end else */
- } /* end else */
+ *buf = outbuf;
+ outbuf = NULL;
+ *buf_size = nbytes;
+ ret_value = z_dst_nbytes;
+ } /* end else */
+ } /* end else */
done:
- if(outbuf)
+ if (outbuf)
H5MM_xfree(outbuf);
FUNC_LEAVE_NOAPI(ret_value)
}
#endif /* H5_HAVE_FILTER_DEFLATE */
-