NetBSD/lib/libutil/efun.3

141 lines
3.9 KiB
Groff
Raw Normal View History

2015-07-26 20:37:38 +03:00
.\" $NetBSD: efun.3,v 1.14 2015/07/26 17:37:38 kamil Exp $
2006-08-26 22:11:45 +04:00
.\"
.\" 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.
.\"
2015-07-26 20:37:38 +03:00
.Dd July 26, 2015
2006-08-26 22:11:45 +04:00
.Dt EFUN 3
.Os
.Sh NAME
.Nm esetfunc ,
.Nm easprintf ,
.Nm efopen ,
.Nm emalloc ,
.Nm ecalloc ,
.Nm erealloc ,
.Nm ereallocarr ,
2006-08-26 22:11:45 +04:00
.Nm estrdup ,
2007-07-02 01:41:16 +04:00
.Nm estrndup ,
2006-08-26 22:11:45 +04:00
.Nm estrlcat ,
.Nm estrlcpy ,
2015-01-18 21:09:36 +03:00
.Nm estrtoi ,
.Nm estrtou ,
2006-08-26 22:11:45 +04:00
.Nm evasprintf
.Nd error-checked utility functions
.Sh LIBRARY
.Lb libutil
.Sh SYNOPSIS
2006-10-06 19:31:20 +04:00
.In util.h
2006-08-26 22:11:45 +04:00
.Ft void (*)(int, const char *, ...)
2006-10-20 21:40:18 +04:00
.Fn esetfunc "void (*)(int, const char *, ...)"
2006-08-26 22:11:45 +04:00
.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 s"
2006-08-26 22:11:45 +04:00
.Ft void *
.Fn emalloc "size_t n"
.Ft void *
.Fn erealloc "void *p" "size_t n"
.Ft void
.Fn ereallocarr "void *p" "size_t n" "size_t s"
2006-08-26 22:11:45 +04:00
.Ft char *
.Fn estrdup "const char *s"
2007-07-02 01:41:16 +04:00
.Ft char *
.Fn estrndup "const char *s" "size_t len"
2006-08-26 22:11:45 +04:00
.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"
2015-01-18 21:09:36 +03:00
.Ft intmax_t
.Fn estrtoi "const char * nptr" "int base" "intmax_t lo" "intmax_t hi"
.Ft uintmax_t
.Fn estrtou "const char * nptr" "int base" "uintmax_t lo" "uintmax_t hi"
2006-08-26 22:11:45 +04:00
.Ft int
.Fn evasprintf "char ** restrict str" "const char * restrict fmt" "..."
.Sh DESCRIPTION
The
2010-05-03 09:40:37 +04:00
.Fn easprintf ,
.Fn efopen ,
.Fn ecalloc ,
.Fn emalloc ,
.Fn erealloc ,
.Fn ereallocarr ,
2010-05-03 09:40:37 +04:00
.Fn estrdup ,
.Fn estrndup ,
.Fn estrlcat ,
.Fn estrlcpy ,
2015-01-18 21:09:36 +03:00
.Fn estrtoi ,
.Fn estrtou ,
and
2010-05-03 09:40:37 +04:00
.Fn evasprintf
functions
2008-02-23 21:35:04 +03:00
operate exactly as the corresponding functions that do not start with an
.Sq e
except that in case of an error, they call
2006-08-26 22:11:45 +04:00
the installed error handler that can be configured with
2010-05-03 09:40:37 +04:00
.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.
2006-08-26 22:11:45 +04:00
The default error handler is
.Xr err 3 .
The function
2010-05-03 09:40:37 +04:00
.Fn esetfunc
2006-08-26 22:11:45 +04:00
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 ,
2006-08-26 22:11:45 +04:00
.Xr err 3 ,
.Xr exit 3 ,
2006-08-26 22:11:45 +04:00
.Xr fopen 3 ,
.Xr malloc 3 ,
.Xr realloc 3 ,
.Xr reallocarr 3 ,
2006-08-26 22:11:45 +04:00
.Xr strdup 3 ,
.Xr strlcat 3 ,
.Xr strlcpy 3 ,
2009-05-04 23:15:36 +04:00
.Xr strndup 3 ,
2015-01-18 21:09:36 +03:00
.Xr strtoi 3 ,
.Xr strtou 3 ,
.Xr vasprintf 3
2015-01-18 21:09:36 +03:00
.Sh HISTORY
The
.Fn estrtoi ,
2015-01-18 21:09:36 +03:00
.Fn estrtou
and
.Fn ereallocarr
2015-01-18 21:09:36 +03:00
functions were added in
.Nx 8 .