.\" $NetBSD: reallocarr.3,v 1.4 2015/07/28 17:13:34 kamil Exp $ .\" .\" Copyright (c) 2015 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in .\" the documentation and/or other materials provided with the .\" distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, .\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .Dd February 19, 2015 .Dt REALLOCARR 3 .Os .Sh NAME .Nm reallocarr .Nd reallocate array .Sh SYNOPSIS .In stdlib.h .Ft int .Fo reallocarr .Fa "void *ptr" .Fa "size_t number" .Fa "size_t size" .Fc .Sh DESCRIPTION The .Nm function reallocates the memory in .Fa *ptr . .Sh RETURN VALUES On successful completion, .Fn returns 0 and updates .Fa *ptr . Otherwise, an error code (see .Xr errno 2 ) is returned and .Fa *ptr and the referenced memory is unmodified. .Sh EXAMPLES The following uses .Fn reallocarr to initialize an array of INITSIZE integers, then resizes it to NEWSIZE elements: .Bd -literal -offset indent 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"); .Ed .Sh SEE ALSO .Xr calloc 3 .Sh HISTORY .Nm first appeared in .Nx 7.0 . .Ox introduced the .Xr reallocarray 3 function for the same purpose, but the interface makes it difficult to correctly handle zero-sized allocations. |