1.\" Copyright (c) 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)realloc.3 5.1 (Berkeley) 05/02/91 7.\" 8.Dd 9.Dt REALLOC 3 10.Os 11.Sh NAME 12.Nm realloc 13.Nd reallocation of memory function 14.Sh SYNOPSIS 15.Fd #include <stdlib.h> 16.Ft void * 17.Fn realloc "void *ptr" "size_t size" 18.Sh DESCRIPTION 19The 20.Fn realloc 21function changes the size of the object pointed to by 22.Fa ptr 23to the size specified by 24.Fa size . 25The contents of the object are unchanged up to the lesser 26of the new and old sizes. 27If the new size is larger, the value of the newly allocated portion 28of the object is indeterminate. 29If 30.Fa ptr 31is a null pointer, the 32.Fn realloc 33function behaves like the 34.Xr malloc 3 35function for the specified size. 36Otherwise, if 37.Fa ptr 38does not match a pointer earlier returned by the 39.Xr calloc 3 , 40.Xr malloc 3 , 41or 42.Fn realloc 43function, or if the space has been deallocated 44by a call to the 45.Xr free 46or 47.Fn realloc 48function, unpredictable and usually detrimental 49behaviour will occur. 50If the space cannot be allocated, the object 51pointed to by 52.Fa ptr 53is unchanged. 54If 55.Fa size 56is zero and 57.Fa ptr 58is not a null pointer, the object it points to is freed. 59.Pp 60The 61.Fn realloc 62function returns either a null pointer or a pointer 63to the possibly moved allocated space. 64.Sh SEE ALSO 65.Xr alloca 3 , 66.Xr calloc 3 , 67.Xr free 3 , 68.Xr malloc 3 , 69.Sh STANDARDS 70The 71.Fn realloc 72function conforms to 73.St -ansiC . 74