aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common/common.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2014-05-25 19:25:57 +0300
committerLasse Collin <lasse.collin@tukaani.org>2014-05-25 19:25:57 +0300
commit28af24e9cf2eb259997c85dce13d4c97b3daa47a (patch)
tree5213b2f8f341a7d5d2abae5cc6815aa872b56cd1 /src/liblzma/common/common.c
parentxz: Fix uint64_t vs. size_t which broke 32-bit build. (diff)
downloadxz-28af24e9cf2eb259997c85dce13d4c97b3daa47a.tar.xz
liblzma: Add the internal function lzma_alloc_zero().
Diffstat (limited to '')
-rw-r--r--src/liblzma/common/common.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/liblzma/common/common.c b/src/liblzma/common/common.c
index efe6c226..28aa2b71 100644
--- a/src/liblzma/common/common.c
+++ b/src/liblzma/common/common.c
@@ -53,6 +53,27 @@ lzma_alloc(size_t size, const lzma_allocator *allocator)
}
+extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
+lzma_alloc_zero(size_t size, const lzma_allocator *allocator)
+{
+ // Some calloc() variants return NULL if called with size == 0.
+ if (size == 0)
+ size = 1;
+
+ void *ptr;
+
+ if (allocator != NULL && allocator->alloc != NULL) {
+ ptr = allocator->alloc(allocator->opaque, 1, size);
+ if (ptr != NULL)
+ memzero(ptr, size);
+ } else {
+ ptr = calloc(1, size);
+ }
+
+ return ptr;
+}
+
+
extern void
lzma_free(void *ptr, const lzma_allocator *allocator)
{