mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-24 07:16:43 +00:00
Add erealloc() function to mem.h, mem.c
This commit is contained in:
parent
deed4665fe
commit
94c6562ee1
10
mem.c
10
mem.c
@ -30,6 +30,16 @@ void *_emalloc(struct __sourceloc __whence, size_t bytes)
|
||||
return new;
|
||||
}
|
||||
|
||||
void *_erealloc(struct __sourceloc __whence, void *ptr, size_t bytes)
|
||||
{
|
||||
char *new = realloc(ptr, bytes);
|
||||
if (!new) {
|
||||
WHYF_perror("realloc(%p, %lu)", ptr, (unsigned long)bytes);
|
||||
return NULL;
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
void *_emalloc_zero(struct __sourceloc __whence, size_t bytes)
|
||||
{
|
||||
char *new = _emalloc(__whence, bytes);
|
||||
|
7
mem.h
7
mem.h
@ -40,6 +40,12 @@ void _serval_debug_free(void *p, struct __sourceloc whence);
|
||||
*/
|
||||
void *_emalloc(struct __sourceloc, size_t bytes);
|
||||
|
||||
/* Equivalent to realloc(3), but logs an error before returning NULL.
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
void *_erealloc(struct __sourceloc __whence, void *ptr, size_t bytes);
|
||||
|
||||
/* Equivalent to malloc(3) followed by memset(3) to zerofill, but logs an error
|
||||
* before returning NULL.
|
||||
*
|
||||
@ -58,6 +64,7 @@ char *_str_edup(struct __sourceloc, const char *str);
|
||||
char *_strn_edup(struct __sourceloc, const char *str, size_t len);
|
||||
|
||||
#define emalloc(bytes) _emalloc(__HERE__, (bytes))
|
||||
#define erealloc(ptr, bytes) _erealloc(__HERE__, (ptr), (bytes))
|
||||
#define emalloc_zero(bytes) _emalloc_zero(__HERE__, (bytes))
|
||||
#define str_edup(str) _str_edup(__HERE__, (str))
|
||||
#define strn_edup(str, len) _strn_edup(__HERE__, (str), (len))
|
||||
|
Loading…
Reference in New Issue
Block a user