xref: /netbsd-src/lib/libutil/efun.3 (revision 7fa608457b817eca6e0977b37f758ae064f3c99c)
1.\"     $NetBSD: efun.3,v 1.5 2007/07/01 21:41:16 pooka 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.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd July 1, 2007
38.Dt EFUN 3
39.Os
40.Sh NAME
41.Nm esetfunc ,
42.Nm easprintf ,
43.Nm efopen ,
44.Nm emalloc ,
45.Nm ecalloc ,
46.Nm erealloc ,
47.Nm estrdup ,
48.Nm estrndup ,
49.Nm estrlcat ,
50.Nm estrlcpy ,
51.Nm evasprintf
52.Nd error-checked utility functions
53.Sh LIBRARY
54.Lb libutil
55.Sh SYNOPSIS
56.In util.h
57.Ft void (*)(int, const char *, ...)
58.Fn esetfunc "void (*)(int, const char *, ...)"
59.Ft int
60.Fn easprintf "char ** restrict str" "const char * restrict fmt" "..."
61.Ft FILE *
62.Fn efopen "const char *p" "const char *m"
63.Ft void *
64.Fn ecalloc "size_t n" "size_t c"
65.Ft void *
66.Fn emalloc "size_t n"
67.Ft void *
68.Fn erealloc "void *p" "size_t n"
69.Ft char *
70.Fn estrdup "const char *s"
71.Ft char *
72.Fn estrndup "const char *s" "size_t len"
73.Ft size_t
74.Fn estrlcat "char *dst" "const char *src" "size_t len"
75.Ft size_t
76.Fn estrlcpy "char *dst" "const char *src" "size_t len"
77.Ft int
78.Fn evasprintf "char ** restrict str" "const char * restrict fmt" "..."
79.Sh DESCRIPTION
80The
81.Nm easprintf ,
82.Nm efopen ,
83.Nm ecalloc ,
84.Nm emalloc ,
85.Nm erealloc ,
86.Nm estrdup ,
87.Nm estrndup ,
88.Nm estrlcat ,
89.Nm estrlcpy ,
90and
91.Nm evasprintf
92functions
93operate exactly as the correspoding functions that do not start with an
94.Sq e
95except that they call
96the installed error handler that can be configured with
97.Nm esetfunc .
98The default error handler is
99.Xr err 3 .
100The function
101.Nm esetfunc
102returns the previous error handler function.
103A
104.Dv NULL
105error handler will just call
106.Xr exit 3 .
107.Sh SEE ALSO
108.Xr asprintf 3 ,
109.Xr calloc 3 ,
110.Xr err 3 ,
111.Xr exit 3 ,
112.Xr fopen 3 ,
113.Xr malloc 3 ,
114.Xr realloc 3 ,
115.Xr strdup 3 ,
116.Xr strndup 3 ,
117.Xr strlcat 3 ,
118.Xr strlcpy 3 ,
119.Xr vasprintf 3
120