mirror of
https://github.com/samba-team/samba.git
synced 2025-02-28 01:58:17 +03:00
lib/util: Move calloc_array and memalign_array to top-level libutil.
This commit is contained in:
parent
c0c52ac1a4
commit
14fdc1c5cd
@ -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 */
|
||||
|
||||
|
||||
|
@ -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.
|
||||
**/
|
||||
|
@ -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,
|
||||
|
@ -69,38 +69,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
|
||||
|
Loading…
x
Reference in New Issue
Block a user