mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
added ucrealloc()
This commit is contained in:
@@ -38,5 +38,7 @@ void *ucmalloc(size_t s);
|
|||||||
/* the same but it fills the pointer with random values */
|
/* the same but it fills the pointer with random values */
|
||||||
void *urmalloc(size_t s);
|
void *urmalloc(size_t s);
|
||||||
|
|
||||||
|
/* resize a a pointer and fill the added remainder with zeroes */
|
||||||
|
void *ucrealloc(void *d, size_t oldlen, size_t newlen);
|
||||||
|
|
||||||
#endif /* _HAVE_PCP_MEM */
|
#endif /* _HAVE_PCP_MEM */
|
||||||
|
|||||||
13
libpcp/mem.c
13
libpcp/mem.c
@@ -52,3 +52,16 @@ void *urmalloc(size_t s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *ucrealloc(void *d, size_t oldlen, size_t newlen) {
|
||||||
|
newlen = newlen * sizeof(unsigned char);
|
||||||
|
void *value = realloc (d, newlen);
|
||||||
|
|
||||||
|
if (value == NULL) {
|
||||||
|
err(errno, "Cannot reallocate %ld bytes of memory", newlen);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset (&value[oldlen], 0, newlen-oldlen);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user