REALLOCARR(3)

REALLOCARR(3) | Library Functions Manual | REALLOCARR(3)

# NAME

reallocarr — reallocate array

# SYNOPSIS

#include <stdlib.h>
int
reallocarr(void *ptr, size_t number, size_t size);

# DESCRIPTION

The reallocarr function reallocates the memory in *ptr.

# RETURN VALUES

On successful completion, returns 0 and updates *ptr. Otherwise, an error code (see errno(2)) is returned and *ptr and the referenced memory is unmodified.

# EXAMPLES

The following uses reallocarr() to initialize an array of INITSIZE integers, then resizes it to NEWSIZE elements:

    int *data = NULL;
    int ret = 0;

    ret = reallocarr(&data, INITSIZE, sizeof(*data));
    if (ret)
        errc(1, ret, "reallocarr failed");

    ret = reallocarr(&data, NEWSIZE, sizeof(*data));
    if (ret)
        errc(1, ret, "reallocarr failed on resize");

# SEE ALSO

calloc(3)

# HISTORY

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.

February 19, 2015 | NetBSD 8.3