xref: /src/lib/libc/stdlib/reallocf.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
1a4bd5210SJason Evans.\" Copyright (c) 1980, 1991, 1993
2a4bd5210SJason Evans.\"	The Regents of the University of California.  All rights reserved.
3a4bd5210SJason Evans.\"
4a4bd5210SJason Evans.\" This code is derived from software contributed to Berkeley by
5a4bd5210SJason Evans.\" the American National Standards Committee X3, on Information
6a4bd5210SJason Evans.\" Processing Systems.
7a4bd5210SJason Evans.\"
8a4bd5210SJason Evans.\" Redistribution and use in source and binary forms, with or without
9a4bd5210SJason Evans.\" modification, are permitted provided that the following conditions
10a4bd5210SJason Evans.\" are met:
11a4bd5210SJason Evans.\" 1. Redistributions of source code must retain the above copyright
12a4bd5210SJason Evans.\"    notice, this list of conditions and the following disclaimer.
13a4bd5210SJason Evans.\" 2. Redistributions in binary form must reproduce the above copyright
14a4bd5210SJason Evans.\"    notice, this list of conditions and the following disclaimer in the
15a4bd5210SJason Evans.\"    documentation and/or other materials provided with the distribution.
16a4bd5210SJason Evans.\" 3. Neither the name of the University nor the names of its contributors
17a4bd5210SJason Evans.\"    may be used to endorse or promote products derived from this software
18a4bd5210SJason Evans.\"    without specific prior written permission.
19a4bd5210SJason Evans.\"
20a4bd5210SJason Evans.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21a4bd5210SJason Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22a4bd5210SJason Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23a4bd5210SJason Evans.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24a4bd5210SJason Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25a4bd5210SJason Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26a4bd5210SJason Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27a4bd5210SJason Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28a4bd5210SJason Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29a4bd5210SJason Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30a4bd5210SJason Evans.\" SUCH DAMAGE.
31a4bd5210SJason Evans.\"
32a4bd5210SJason Evans.Dd January 31, 2010
33a4bd5210SJason Evans.Dt MALLOC 3
34a4bd5210SJason Evans.Os
35a4bd5210SJason Evans.Sh NAME
36a4bd5210SJason Evans.Nm reallocf
37a4bd5210SJason Evans.Nd memory reallocation function
38a4bd5210SJason Evans.Sh LIBRARY
39a4bd5210SJason Evans.Lb libc
40a4bd5210SJason Evans.Sh SYNOPSIS
41a4bd5210SJason Evans.In stdlib.h
42a4bd5210SJason Evans.Ft void *
43a4bd5210SJason Evans.Fn reallocf "void *ptr" "size_t size"
44a4bd5210SJason Evans.Sh DESCRIPTION
45a4bd5210SJason EvansThe
46a4bd5210SJason Evans.Fn reallocf
47a4bd5210SJason Evansfunction is identical to the
48a4bd5210SJason Evans.Fn realloc
49a4bd5210SJason Evansfunction, except that it
50a4bd5210SJason Evanswill free the passed pointer when the requested memory cannot be allocated.
51a4bd5210SJason EvansThis is a
52a4bd5210SJason Evans.Fx
53a4bd5210SJason Evansspecific API designed to ease the problems with traditional coding styles
54a4bd5210SJason Evansfor
55a4bd5210SJason Evans.Fn realloc
56a4bd5210SJason Evanscausing memory leaks in libraries.
57a4bd5210SJason Evans.Sh RETURN VALUES
58a4bd5210SJason EvansThe
59a4bd5210SJason Evans.Fn reallocf
60a4bd5210SJason Evansfunction returns a pointer, possibly identical to
61a4bd5210SJason Evans.Fa ptr ,
62a4bd5210SJason Evansto the allocated memory
63a4bd5210SJason Evansif successful; otherwise a
64a4bd5210SJason Evans.Dv NULL
65a4bd5210SJason Evanspointer is returned, and
66a4bd5210SJason Evans.Va errno
67a4bd5210SJason Evansis set to
68a4bd5210SJason Evans.Er ENOMEM
69a4bd5210SJason Evansif the error was the result of an allocation failure.
70a4bd5210SJason EvansThe
71a4bd5210SJason Evans.Fn reallocf
72a4bd5210SJason Evansfunction deletes the original buffer when an error occurs.
73a4bd5210SJason Evans.Sh SEE ALSO
74a4bd5210SJason Evans.Xr realloc 3
75a4bd5210SJason Evans.Sh HISTORY
76a4bd5210SJason EvansThe
77a4bd5210SJason Evans.Fn reallocf
78a4bd5210SJason Evansfunction first appeared in
79a4bd5210SJason Evans.Fx 3.0 .
80