version 1.1, 2014/08/05 05:48:56 |
version 1.3, 2021/09/17 18:50:21 |
|
|
.Nm mandoc_realloc , |
.Nm mandoc_realloc , |
.Nm mandoc_reallocarray , |
.Nm mandoc_reallocarray , |
.Nm mandoc_calloc , |
.Nm mandoc_calloc , |
|
.Nm mandoc_recallocarray , |
.Nm mandoc_strdup , |
.Nm mandoc_strdup , |
.Nm mandoc_strndup , |
.Nm mandoc_strndup , |
.Nm mandoc_asprintf |
.Nm mandoc_asprintf |
.Nd memory allocation function wrappers used in the mandoc library |
.Nd memory allocation function wrappers used in the mandoc library |
.Sh LIBRARY |
|
.Lb libmandoc |
|
.Sh SYNOPSIS |
.Sh SYNOPSIS |
.In sys/types.h |
.In sys/types.h |
.In mandoc_aux.h |
.In mandoc_aux.h |
|
|
.Fa "size_t nmemb" |
.Fa "size_t nmemb" |
.Fa "size_t size" |
.Fa "size_t size" |
.Fc |
.Fc |
|
.Ft "void *" |
|
.Fo mandoc_recallocarray |
|
.Fa "void *ptr" |
|
.Fa "size_t oldnmemb" |
|
.Fa "size_t nmemb" |
|
.Fa "size_t size" |
|
.Fc |
.Ft "char *" |
.Ft "char *" |
.Fo mandoc_strdup |
.Fo mandoc_strdup |
.Fa "const char *s" |
.Fa "const char *s" |
|
|
.Fa "..." |
.Fa "..." |
.Fc |
.Fc |
.Sh DESCRIPTION |
.Sh DESCRIPTION |
These functions call the |
These functions call the libc functions of the same names, passing |
.Lb libc |
through their return values when successful. |
functions of the same names, passing through their return values when |
|
successful. |
|
In case of failure, they do not return, but instead call |
In case of failure, they do not return, but instead call |
.Xr perror 3 |
.Xr err 3 . |
and |
They can be used both internally by any code in the mandoc libraries |
.Xr exit 3 . |
|
They can be used both internally by any code in the |
|
.Lb libmandoc |
|
and externally by programs using that library, for example |
and externally by programs using that library, for example |
.Xr mandoc 1 , |
.Xr mandoc 1 , |
|
.Xr man 1 , |
.Xr apropos 1 , |
.Xr apropos 1 , |
|
.Xr makewhatis 8 , |
and |
and |
.Xr makewhatis 8 . |
.Xr man.cgi 8 . |
.Pp |
.Pp |
The function |
The function |
.Fn mandoc_malloc |
.Fn mandoc_malloc |
allocates one new object, leaving the memory uninitialized. |
allocates one new object, leaving the memory uninitialized. |
The functions |
The functions |
.Fn mandoc_realloc |
.Fn mandoc_realloc , |
|
.Fn mandoc_reallocarray , |
and |
and |
.Fn mandoc_reallocarray |
.Fn mandoc_recallocarray |
change the size of an existing object or array, possibly moving it. |
change the size of an existing object or array, possibly moving it. |
When shrinking the size, existing data is truncated; when growing, |
When shrinking the size, existing data is truncated; when growing, |
the additional memory is not initialized. |
only |
|
.Fn mandoc_recallocarray |
|
initializes the new elements to zero. |
The function |
The function |
.Fn mandoc_calloc |
.Fn mandoc_calloc |
allocates a new array, initializing it to zero. |
allocates a new array, initializing it to zero. |
|
|
.Fa nmemb |
.Fa nmemb |
is the new number of objects in the array. |
is the new number of objects in the array. |
The argument |
The argument |
|
.Fa oldnmemb |
|
is the number of objects in the array before the call. |
|
The argument |
.Fa ptr |
.Fa ptr |
is a pointer to the existing object or array to be resized; if it is |
is a pointer to the existing object or array to be resized; if it is |
.Dv NULL , |
.Dv NULL , |
Line 149 These functions are implemented in |
|
Line 158 These functions are implemented in |
|
.Pa mandoc_aux.c . |
.Pa mandoc_aux.c . |
.Sh SEE ALSO |
.Sh SEE ALSO |
.Xr asprintf 3 , |
.Xr asprintf 3 , |
.Xr exit 3 , |
.Xr err 3 , |
.Xr malloc 3 , |
.Xr malloc 3 , |
.Xr perror 3 , |
|
.Xr strdup 3 |
.Xr strdup 3 |
.Sh STANDARDS |
.Sh STANDARDS |
The functions |
The functions |
Line 174 is a widespread extension that first appeared in the G |
|
Line 182 is a widespread extension that first appeared in the G |
|
The function |
The function |
.Fn reallocarray |
.Fn reallocarray |
is an extension that first appeared in |
is an extension that first appeared in |
.Ox 5.6 . |
.Ox 5.6 , |
If it is not provided by the operating system, the mandoc build system |
and |
uses a bundled portable implementation. |
.Fn recallocarray |
|
in |
|
.Ox 6.1 . |
|
If these two are not provided by the operating system, |
|
the mandoc build system uses bundled portable implementations. |
.Sh HISTORY |
.Sh HISTORY |
The functions |
The functions |
.Fn mandoc_malloc , |
.Fn mandoc_malloc , |
|
|
have been available since mandoc 1.9.12, |
have been available since mandoc 1.9.12, |
.Fn mandoc_strndup |
.Fn mandoc_strndup |
since 1.11.5, |
since 1.11.5, |
and |
|
.Fn mandoc_asprintf |
.Fn mandoc_asprintf |
and |
since 1.12.4, |
.Fn mandoc_reallocarray |
.Fn mandoc_reallocarray |
since 1.12.4 and 1.13.0. |
since 1.13.0, and |
|
.Fn mandoc_recallocarray |
|
since 1.14.2. |
.Sh AUTHORS |
.Sh AUTHORS |
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv |
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv |
.An Ingo Schwarze Aq Mt schwarze@openbsd.org |
.An Ingo Schwarze Aq Mt schwarze@openbsd.org |