1 .\" $Id: mandoc_malloc.3,v 1.2 2016/07/07 19:19:01 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: July 7 2016 $
23 .Nm mandoc_reallocarray ,
28 .Nd memory allocation function wrappers used in the mandoc library
42 .Fo mandoc_reallocarray
64 .Fa "const char *format"
68 These functions call the libc functions of the same names, passing
69 through their return values when successful.
70 In case of failure, they do not return, but instead call
72 They can be used both internally by any code in the mandoc libraries
73 and externally by programs using that library, for example
83 allocates one new object, leaving the memory uninitialized.
87 .Fn mandoc_reallocarray
88 change the size of an existing object or array, possibly moving it.
89 When shrinking the size, existing data is truncated; when growing,
90 the additional memory is not initialized.
93 allocates a new array, initializing it to zero.
97 is the size of each object.
100 is the new number of objects in the array.
103 is a pointer to the existing object or array to be resized; if it is
105 a new object or array is allocated.
111 copy a string into newly allocated memory.
114 the string pointed to by
116 needs to be NUL-terminated.
124 writes output formatted according to
126 into newly allocated memory and returns a pointer to the result in
128 For all three string functions, the result is always NUL-terminated.
130 When the objects and strings are no longer needed,
131 the pointers returned by these functions can be passed to
136 always returns the number of characters written, excluding the
140 The other functions always return a valid pointer; they never return
143 These functions are implemented in
166 is a widespread extension that first appeared in the GNU C library.
170 is an extension that first appeared in
172 If it is not provided by the operating system, the mandoc build system
173 uses a bundled portable implementation.
181 have been available since mandoc 1.9.12,
187 .Fn mandoc_reallocarray
188 since 1.12.4 and 1.13.0.
190 .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
191 .An Ingo Schwarze Aq Mt schwarze@openbsd.org