summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2012-03-24 15:19:09 +0100
committerJelmer Vernooij <jelmer@samba.org>2012-03-24 15:19:09 +0100
commit14fdc1c5cd4ca0b3f88b2d407d40ba5be7218085 (patch)
tree4cf27501438c4d717f11ba759adec67da5ab919c
parentc0c52ac1a40db70d8b19cb8d73ed4759b0a4f905 (diff)
downloadsamba-14fdc1c5cd4ca0b3f88b2d407d40ba5be7218085.tar.gz
samba-14fdc1c5cd4ca0b3f88b2d407d40ba5be7218085.tar.bz2
samba-14fdc1c5cd4ca0b3f88b2d407d40ba5be7218085.zip
lib/util: Move calloc_array and memalign_array to top-level libutil.
-rw-r--r--lib/util/samba_util.h4
-rw-r--r--lib/util/util.c28
-rw-r--r--source3/include/proto.h2
-rw-r--r--source3/lib/util_malloc.c32
4 files changed, 32 insertions, 34 deletions
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 9c12f6e8dd..0c3fd1aeaf 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -751,6 +751,10 @@ _PUBLIC_ void *realloc_array(void *ptr, size_t el_size, unsigned count, bool fre
void *malloc_array(size_t el_size, unsigned int count);
+void *memalign_array(size_t el_size, size_t align, unsigned int count);
+
+void *calloc_array(size_t size, size_t nmemb);
+
/* The following definitions come from lib/util/fsusage.c */
diff --git a/lib/util/util.c b/lib/util/util.c
index 960bda0f9b..89d5fc3611 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -646,6 +646,34 @@ void *malloc_array(size_t el_size, unsigned int count)
return realloc_array(NULL, el_size, count, false);
}
+/****************************************************************************
+ Type-safe memalign
+****************************************************************************/
+
+void *memalign_array(size_t el_size, size_t align, unsigned int count)
+{
+ if (count*el_size >= MAX_MALLOC_SIZE) {
+ return NULL;
+ }
+
+ return memalign(align, el_size*count);
+}
+
+/****************************************************************************
+ Type-safe calloc.
+****************************************************************************/
+
+void *calloc_array(size_t size, size_t nmemb)
+{
+ if (nmemb >= MAX_MALLOC_SIZE/size) {
+ return NULL;
+ }
+ if (size == 0 || nmemb == 0) {
+ return NULL;
+ }
+ return calloc(nmemb, size);
+}
+
/**
Trim the specified elements off the front and back of a string.
**/
diff --git a/source3/include/proto.h b/source3/include/proto.h
index e8a0d42b3c..a4fb496ea9 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -489,8 +489,6 @@ NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx,
struct event_context *ev_ctx,
bool parent_longlived);
void *malloc_(size_t size);
-void *memalign_array(size_t el_size, size_t align, unsigned int count);
-void *calloc_array(size_t size, size_t nmemb);
void *Realloc(void *p, size_t size, bool free_old_on_error);
void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size,
void *element, void *_array, uint32 *num_elements,
diff --git a/source3/lib/util_malloc.c b/source3/lib/util_malloc.c
index d773d8ffd6..b2ef49d81e 100644
--- a/source3/lib/util_malloc.c
+++ b/source3/lib/util_malloc.c
@@ -70,38 +70,6 @@ static void *realloc_(void *ptr, size_t size)
#endif /* PARANOID_MALLOC_CHECKER */
/****************************************************************************
- Type-safe memalign
-****************************************************************************/
-
-void *memalign_array(size_t el_size, size_t align, unsigned int count)
-{
- if (count >= MAX_ALLOC_SIZE/el_size) {
- return NULL;
- }
-
- return memalign(align, el_size*count);
-}
-
-/****************************************************************************
- Type-safe calloc.
-****************************************************************************/
-
-void *calloc_array(size_t size, size_t nmemb)
-{
- if (nmemb >= MAX_ALLOC_SIZE/size) {
- return NULL;
- }
- if (size == 0 || nmemb == 0) {
- return NULL;
- }
-#if defined(PARANOID_MALLOC_CHECKER)
- return calloc_(nmemb, size);
-#else
- return calloc(nmemb, size);
-#endif
-}
-
-/****************************************************************************
Expand a pointer to be a particular size.
Note that this version of Realloc has an extra parameter that decides
whether to free the passed in storage on allocation failure or if the