1 .\" $Id: mandoc_malloc.3,v 1.3 2021/09/17 18:50:21 schwarze Exp $
3 .\" Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
5 .\" Permission to use, copy, modify, and distribute this software for any
6 .\" purpose with or without fee is hereby granted, provided that the above
7 .\" copyright notice and this permission notice appear in all copies.
9 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 .Dd $Mdocdate: September 17 2021 $
23 .Nm mandoc_reallocarray ,
25 .Nm mandoc_recallocarray ,
29 .Nd memory allocation function wrappers used in the mandoc library
43 .Fo mandoc_reallocarray
54 .Fo mandoc_recallocarray
72 .Fa "const char *format"
76 These functions call the libc functions of the same names, passing
77 through their return values when successful.
78 In case of failure, they do not return, but instead call
80 They can be used both internally by any code in the mandoc libraries
81 and externally by programs using that library, for example
91 allocates one new object, leaving the memory uninitialized.
94 .Fn mandoc_reallocarray ,
96 .Fn mandoc_recallocarray
97 change the size of an existing object or array, possibly moving it.
98 When shrinking the size, existing data is truncated; when growing,
100 .Fn mandoc_recallocarray
101 initializes the new elements to zero.
104 allocates a new array, initializing it to zero.
108 is the size of each object.
111 is the new number of objects in the array.
114 is the number of objects in the array before the call.
117 is a pointer to the existing object or array to be resized; if it is
119 a new object or array is allocated.
125 copy a string into newly allocated memory.
128 the string pointed to by
130 needs to be NUL-terminated.
138 writes output formatted according to
140 into newly allocated memory and returns a pointer to the result in
142 For all three string functions, the result is always NUL-terminated.
144 When the objects and strings are no longer needed,
145 the pointers returned by these functions can be passed to
150 always returns the number of characters written, excluding the
154 The other functions always return a valid pointer; they never return
157 These functions are implemented in
180 is a widespread extension that first appeared in the GNU C library.
184 is an extension that first appeared in
190 If these two are not provided by the operating system,
191 the mandoc build system uses bundled portable implementations.
199 have been available since mandoc 1.9.12,
204 .Fn mandoc_reallocarray
206 .Fn mandoc_recallocarray
209 .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
210 .An Ingo Schwarze Aq Mt schwarze@openbsd.org