- NetBSD Manual Pages
REALLOCARR(3) NetBSD Library Functions Manual REALLOCARR(3)
Powered by man-cgi (2021-06-01).
Maintained for NetBSD
by Kimmo Suominen.
Based on man-cgi by Panagiotis Christias.
reallocarr -- reallocate array
reallocarr(void *ptr, size_t number, size_t size);
The reallocarr function reallocates the memory in *ptr.
On successful completion, returns 0 and updates *ptr. Otherwise, an
error code (see errno(2)) is returned and *ptr and the referenced memory
The following uses reallocarr() to initialize an array of INITSIZE inte-
gers, then resizes it to NEWSIZE elements:
int *data = NULL;
int ret = 0;
ret = reallocarr(&data, INITSIZE, sizeof(*data));
errc(1, ret, "reallocarr failed");
ret = reallocarr(&data, NEWSIZE, sizeof(*data));
errc(1, ret, "reallocarr failed on resize");
reallocarr first appeared in NetBSD 7.0. OpenBSD introduced the
reallocarray(3) function for the same purpose, but the interface makes it
difficult to correctly handle zero-sized allocations.
NetBSD 9.3 February 19, 2015 NetBSD 9.3