.TH realloc() "" "" "General Function (libc)"
.PC "Reallocate dynamic memory"
.B "#include <stdlib.h>"
\fBchar *realloc(\fIptr\^\fB, \fIsize\^\fB)\fR
\fBchar *\fIptr\fB; unsigned \fIsize\^\fB;\fR
.PP
.B realloc()
helps you manage a program's arena.
It returns a block of \fIsize\fR bytes that holds the contents of the old
block, up to the smaller of the old and new sizes.
.B realloc()
tries to return the same block, truncated or extended; if \fIsize\fR is
smaller than the size of the old block, \fBrealloc()\fR
will return the same \fIptr\fR.
.PP
If
.I ptr
is set to NULL,
.B realloc()
behaves like
.BR malloc() .
.SH Example
For an example of this function, see the entry for \fBcalloc()\fR.
.SH "See Also"
.Xr "alloca()," alloca
.Xr "arena," arena
.Xr "calloc()," calloc
.Xr "free()," free
.Xr "libc," libc
.Xr "malloc()," malloc
.Xr "memok()," memok
.Xr "setbuf()," setbuf
.Xr "stdlib.h" stdlib.h
.br
\*(AS, \(sc7.10.3.4
.br
\*(PX Standard, \(sc8.1
.SH Diagnostics
.B realloc()
returns NULL if insufficient memory is available.
It prints a message and calls
.B abort()
if it discovers that the arena has been corrupted,
which most often occurs by storing past the bounds of an allocated block.
.B realloc()
behaves unpredictably if handed an incorrect
.IR ptr .
