summaryrefslogtreecommitdiff
path: root/zutil.c
diff options
context:
space:
mode:
authorHans Kristian Rosbach <hk-git@circlestorm.org>2020-09-12 19:54:38 +0200
committerHans Kristian Rosbach <hk-github@circlestorm.org>2020-09-14 12:04:30 +0200
commit696e387ef1b587376baf9326ad0bb89cd7948236 (patch)
tree1aa2e8a4f0afd2a10477c8358aeca6d4fff13616 /zutil.c
parenta245ef38b8854d8de333f3575158046cc115a6ac (diff)
Simplify zng_calloc and zng_cfree.
Make new static functions zng_alloc and zng_free available to other parts of the code. Always request aligned allocations, even if UNALIGNED_OK is set.
Diffstat (limited to 'zutil.c')
-rw-r--r--zutil.c32
1 files changed, 4 insertions, 28 deletions
diff --git a/zutil.c b/zutil.c
index cb0756f..04e589b 100644
--- a/zutil.c
+++ b/zutil.c
@@ -5,6 +5,7 @@
#include "zbuild.h"
#include "zutil.h"
+#include "zutil_p.h"
#ifdef WITH_GZFILEOP
# include "gzguts.h"
#endif
@@ -102,37 +103,12 @@ const char * Z_EXPORT PREFIX(zError)(int err) {
return ERR_MSG(err);
}
-#ifndef MY_ZCALLOC /* Any system without a special alloc function */
-
-#ifndef UNALIGNED_OK
-# include <malloc.h>
-# if defined(_WIN32)
-# define zng_align_alloc(align, size) _aligned_malloc(size, align)
-# define zng_align_free(ptr) _aligned_free(ptr)
-# else
-# define zng_align_alloc memalign
-# define zng_align_free(ptr) free(ptr)
-# endif
-#endif
-
-void Z_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size)
-{
+void Z_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size) {
(void)opaque;
-#ifndef UNALIGNED_OK
- return zng_align_alloc(16, items * size);
-#else
- return sizeof(unsigned int) > 2 ? (void *)malloc(items * size) :
- (void *)calloc(items, size);
-#endif
+ return zng_alloc((size_t)items * (size_t)size);
}
void Z_INTERNAL zng_cfree(void *opaque, void *ptr) {
(void)opaque;
-#ifndef UNALIGNED_OK
- zng_align_free(ptr);
-#else
- free(ptr);
-#endif
+ zng_free(ptr);
}
-
-#endif /* MY_ZCALLOC */