1*0a6a1f1dSLionel Sambuc.\" $NetBSD: reallocarr.3,v 1.4 2015/07/28 17:13:34 kamil Exp $ 2*0a6a1f1dSLionel Sambuc.\" 3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2015 The NetBSD Foundation, Inc. 4*0a6a1f1dSLionel Sambuc.\" All rights reserved. 5*0a6a1f1dSLionel Sambuc.\" 6*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 7*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions 8*0a6a1f1dSLionel Sambuc.\" are met: 9*0a6a1f1dSLionel Sambuc.\" 10*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 11*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 12*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 13*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in 14*0a6a1f1dSLionel Sambuc.\" the documentation and/or other materials provided with the 15*0a6a1f1dSLionel Sambuc.\" distribution. 16*0a6a1f1dSLionel Sambuc.\" 17*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18*0a6a1f1dSLionel Sambuc.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19*0a6a1f1dSLionel Sambuc.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 20*0a6a1f1dSLionel Sambuc.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 21*0a6a1f1dSLionel Sambuc.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 22*0a6a1f1dSLionel Sambuc.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 23*0a6a1f1dSLionel Sambuc.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24*0a6a1f1dSLionel Sambuc.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25*0a6a1f1dSLionel Sambuc.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26*0a6a1f1dSLionel Sambuc.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 27*0a6a1f1dSLionel Sambuc.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28*0a6a1f1dSLionel Sambuc.\" SUCH DAMAGE. 29*0a6a1f1dSLionel Sambuc.Dd February 19, 2015 30*0a6a1f1dSLionel Sambuc.Dt REALLOCARR 3 31*0a6a1f1dSLionel Sambuc.Os 32*0a6a1f1dSLionel Sambuc.Sh NAME 33*0a6a1f1dSLionel Sambuc.Nm reallocarr 34*0a6a1f1dSLionel Sambuc.Nd reallocate array 35*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS 36*0a6a1f1dSLionel Sambuc.In stdlib.h 37*0a6a1f1dSLionel Sambuc.Ft int 38*0a6a1f1dSLionel Sambuc.Fo reallocarr 39*0a6a1f1dSLionel Sambuc.Fa "void *ptr" 40*0a6a1f1dSLionel Sambuc.Fa "size_t number" 41*0a6a1f1dSLionel Sambuc.Fa "size_t size" 42*0a6a1f1dSLionel Sambuc.Fc 43*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION 44*0a6a1f1dSLionel SambucThe 45*0a6a1f1dSLionel Sambuc.Nm 46*0a6a1f1dSLionel Sambucfunction reallocates the memory in 47*0a6a1f1dSLionel Sambuc.Fa *ptr . 48*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES 49*0a6a1f1dSLionel SambucOn successful completion, 50*0a6a1f1dSLionel Sambuc.Fn 51*0a6a1f1dSLionel Sambucreturns 0 and updates 52*0a6a1f1dSLionel Sambuc.Fa *ptr . 53*0a6a1f1dSLionel SambucOtherwise, an error code (see 54*0a6a1f1dSLionel Sambuc.Xr errno 2 ) 55*0a6a1f1dSLionel Sambucis returned and 56*0a6a1f1dSLionel Sambuc.Fa *ptr 57*0a6a1f1dSLionel Sambucand the referenced memory is unmodified. 58*0a6a1f1dSLionel Sambuc.Sh EXAMPLES 59*0a6a1f1dSLionel SambucThe following uses 60*0a6a1f1dSLionel Sambuc.Fn reallocarr 61*0a6a1f1dSLionel Sambucto initialize an array of INITSIZE integers, then 62*0a6a1f1dSLionel Sambucresizes it to NEWSIZE elements: 63*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 64*0a6a1f1dSLionel Sambucint *data = NULL; 65*0a6a1f1dSLionel Sambucint ret = 0; 66*0a6a1f1dSLionel Sambuc 67*0a6a1f1dSLionel Sambucret = reallocarr(&data, INITSIZE, sizeof(*data)); 68*0a6a1f1dSLionel Sambucif (ret) 69*0a6a1f1dSLionel Sambuc errc(1, ret, "reallocarr failed"); 70*0a6a1f1dSLionel Sambuc 71*0a6a1f1dSLionel Sambucret = reallocarr(&data, NEWSIZE, sizeof(*data)); 72*0a6a1f1dSLionel Sambucif (ret) 73*0a6a1f1dSLionel Sambuc errc(1, ret, "reallocarr failed on resize"); 74*0a6a1f1dSLionel Sambuc.Ed 75*0a6a1f1dSLionel Sambuc.Sh SEE ALSO 76*0a6a1f1dSLionel Sambuc.Xr calloc 3 77*0a6a1f1dSLionel Sambuc.Sh HISTORY 78*0a6a1f1dSLionel Sambuc.Nm 79*0a6a1f1dSLionel Sambucfirst appeared in 80*0a6a1f1dSLionel Sambuc.Nx 7.0 . 81*0a6a1f1dSLionel Sambuc.Ox 82*0a6a1f1dSLionel Sambucintroduced the 83*0a6a1f1dSLionel Sambuc.Xr reallocarray 3 84*0a6a1f1dSLionel Sambucfunction for the same purpose, but the interface makes it difficult 85*0a6a1f1dSLionel Sambucto correctly handle zero-sized allocations. 86