minix/lib/libutil/efun.3
Ben Gras 0c3983b25a update/fix manpage support
. add bsd-style MLINKS to minix man set, restoring aliases
	  (e.g. man add64 -> int64)
	. update daily cron script to run makewhatis and restore makewhatis
	  in man Makefile (makedb), restores functionality of man -k
	. netbsd imports of man, mdocml, makewhatis, libutil, apropos
	. update man.conf with manpage locations, restoring man [-s] <section>
	. throws out some obsolete manpages
2011-09-28 15:24:15 +00:00

117 lines
3.4 KiB
Groff

.\" $NetBSD: efun.3,v 1.10 2010/05/03 05:40:37 jruoho Exp $
.\"
.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Christos Zoulas.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd May 3, 2010
.Dt EFUN 3
.Os
.Sh NAME
.Nm esetfunc ,
.Nm easprintf ,
.Nm efopen ,
.Nm emalloc ,
.Nm ecalloc ,
.Nm erealloc ,
.Nm estrdup ,
.Nm estrndup ,
.Nm estrlcat ,
.Nm estrlcpy ,
.Nm evasprintf
.Nd error-checked utility functions
.Sh LIBRARY
.Lb libutil
.Sh SYNOPSIS
.In util.h
.Ft void (*)(int, const char *, ...)
.Fn esetfunc "void (*)(int, const char *, ...)"
.Ft int
.Fn easprintf "char ** restrict str" "const char * restrict fmt" "..."
.Ft FILE *
.Fn efopen "const char *p" "const char *m"
.Ft void *
.Fn ecalloc "size_t n" "size_t c"
.Ft void *
.Fn emalloc "size_t n"
.Ft void *
.Fn erealloc "void *p" "size_t n"
.Ft char *
.Fn estrdup "const char *s"
.Ft char *
.Fn estrndup "const char *s" "size_t len"
.Ft size_t
.Fn estrlcat "char *dst" "const char *src" "size_t len"
.Ft size_t
.Fn estrlcpy "char *dst" "const char *src" "size_t len"
.Ft int
.Fn evasprintf "char ** restrict str" "const char * restrict fmt" "..."
.Sh DESCRIPTION
The
.Fn easprintf ,
.Fn efopen ,
.Fn ecalloc ,
.Fn emalloc ,
.Fn erealloc ,
.Fn estrdup ,
.Fn estrndup ,
.Fn estrlcat ,
.Fn estrlcpy ,
and
.Fn evasprintf
functions
operate exactly as the corresponding functions that do not start with an
.Sq e
except that in case of an error, they call
the installed error handler that can be configured with
.Fn esetfunc .
.Pp
For the string handling functions, it is an error when the destination
buffer is not large enough to hold the complete string.
For functions that allocate memory or open a file, it is an error when
they would return a null pointer.
The default error handler is
.Xr err 3 .
The function
.Fn esetfunc
returns the previous error handler function.
A
.Dv NULL
error handler will just call
.Xr exit 3 .
.Sh SEE ALSO
.Xr asprintf 3 ,
.Xr calloc 3 ,
.Xr err 3 ,
.Xr exit 3 ,
.Xr fopen 3 ,
.Xr malloc 3 ,
.Xr realloc 3 ,
.Xr strdup 3 ,
.Xr strlcat 3 ,
.Xr strlcpy 3 ,
.Xr strndup 3 ,
.Xr vasprintf 3