efun.3: evasprintf() wasn't brought in and easprintf() was missing docs.
[dragonfly.git] / lib / libutil / efun.3
CommitLineData
ba2075d1
VS
1.\" $NetBSD: efun.3,v 1.10 2010/05/03 05:40:37 jruoho Exp $
2.\"
3.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Christos Zoulas.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd April 26, 2011
31.Dt EFUN 3
32.Os
33.Sh NAME
34.Nm esetfunc ,
35.Nm emalloc ,
36.Nm ecalloc ,
37.Nm erealloc ,
38.Nm estrdup ,
39.Nm estrndup ,
40.Nm estrlcat ,
41.Nm estrlcpy ,
feddbc59 42.Nm easprintf
ba2075d1
VS
43.Nd error-checked utility functions
44.Sh LIBRARY
45.Lb libutil
46.Sh SYNOPSIS
47.In libutil.h
48.Ft void (*)(int, const char *, ...)
49.Fn esetfunc "void (*)(int, const char *, ...)"
50.Ft void *
51.Fn ecalloc "size_t n" "size_t c"
52.Ft void *
53.Fn emalloc "size_t n"
54.Ft void *
55.Fn erealloc "void *p" "size_t n"
56.Ft char *
57.Fn estrdup "const char *s"
58.Ft char *
59.Fn estrndup "const char *s" "size_t len"
60.Ft size_t
61.Fn estrlcat "char *dst" "const char *src" "size_t len"
62.Ft size_t
63.Fn estrlcpy "char *dst" "const char *src" "size_t len"
64.Ft int
feddbc59 65.Fn easprintf "char ** restrict str" "const char * restrict fmt" "..."
ba2075d1
VS
66.Sh DESCRIPTION
67The
68.Fn ecalloc ,
69.Fn emalloc ,
70.Fn erealloc ,
71.Fn estrdup ,
72.Fn estrndup ,
73.Fn estrlcat ,
74.Fn estrlcpy ,
75and
feddbc59 76.Fn easprintf
ba2075d1
VS
77functions
78operate exactly as the corresponding functions that do not start with an
79.Sq e
80except that in case of an error, they call
81the installed error handler that can be configured with
82.Fn esetfunc .
83.Pp
84For the string handling functions, it is an error when the destination
85buffer is not large enough to hold the complete string.
86For functions that allocate memory or open a file, it is an error when
87they would return a null pointer.
88The default error handler is
89.Xr err 3 .
90The function
91.Fn esetfunc
92returns the previous error handler function.
93A
94.Dv NULL
95error handler will just call
96.Xr exit 3 .
ba2075d1
VS
97.Sh SEE ALSO
98.Xr asprintf 3 ,
99.Xr calloc 3 ,
100.Xr err 3 ,
101.Xr exit 3 ,
102.Xr fopen 3 ,
103.Xr malloc 3 ,
104.Xr realloc 3 ,
105.Xr strdup 3 ,
106.Xr strlcat 3 ,
107.Xr strlcpy 3 ,
feddbc59
SW
108.Xr strndup 3
109.\".Xr vasprintf 3
98eee0ee
SW
110.Sh HISTORY
111The error functions first appeared in
112.Dx 2.11 .
113They are originally from
114.Nx .