1*0a6a1f1dSLionel Sambuc.\" $NetBSD: efun.3,v 1.14 2015/07/26 17:37:38 kamil Exp $ 20c3983b2SBen Gras.\" 30c3983b2SBen Gras.\" Copyright (c) 2006 The NetBSD Foundation, Inc. 40c3983b2SBen Gras.\" All rights reserved. 50c3983b2SBen Gras.\" 60c3983b2SBen Gras.\" This code is derived from software contributed to The NetBSD Foundation 70c3983b2SBen Gras.\" by Christos Zoulas. 80c3983b2SBen Gras.\" 90c3983b2SBen Gras.\" Redistribution and use in source and binary forms, with or without 100c3983b2SBen Gras.\" modification, are permitted provided that the following conditions 110c3983b2SBen Gras.\" are met: 120c3983b2SBen Gras.\" 1. Redistributions of source code must retain the above copyright 130c3983b2SBen Gras.\" notice, this list of conditions and the following disclaimer. 140c3983b2SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 150c3983b2SBen Gras.\" notice, this list of conditions and the following disclaimer in the 160c3983b2SBen Gras.\" documentation and/or other materials provided with the distribution. 170c3983b2SBen Gras.\" 180c3983b2SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 190c3983b2SBen Gras.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 200c3983b2SBen Gras.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 210c3983b2SBen Gras.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 220c3983b2SBen Gras.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 230c3983b2SBen Gras.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 240c3983b2SBen Gras.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 250c3983b2SBen Gras.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 260c3983b2SBen Gras.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 270c3983b2SBen Gras.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 280c3983b2SBen Gras.\" POSSIBILITY OF SUCH DAMAGE. 290c3983b2SBen Gras.\" 30*0a6a1f1dSLionel Sambuc.Dd July 26, 2015 310c3983b2SBen Gras.Dt EFUN 3 320c3983b2SBen Gras.Os 330c3983b2SBen Gras.Sh NAME 340c3983b2SBen Gras.Nm esetfunc , 350c3983b2SBen Gras.Nm easprintf , 360c3983b2SBen Gras.Nm efopen , 370c3983b2SBen Gras.Nm emalloc , 380c3983b2SBen Gras.Nm ecalloc , 390c3983b2SBen Gras.Nm erealloc , 40*0a6a1f1dSLionel Sambuc.Nm ereallocarr , 410c3983b2SBen Gras.Nm estrdup , 420c3983b2SBen Gras.Nm estrndup , 430c3983b2SBen Gras.Nm estrlcat , 440c3983b2SBen Gras.Nm estrlcpy , 45*0a6a1f1dSLionel Sambuc.Nm estrtoi , 46*0a6a1f1dSLionel Sambuc.Nm estrtou , 470c3983b2SBen Gras.Nm evasprintf 480c3983b2SBen Gras.Nd error-checked utility functions 490c3983b2SBen Gras.Sh LIBRARY 500c3983b2SBen Gras.Lb libutil 510c3983b2SBen Gras.Sh SYNOPSIS 520c3983b2SBen Gras.In util.h 530c3983b2SBen Gras.Ft void (*)(int, const char *, ...) 540c3983b2SBen Gras.Fn esetfunc "void (*)(int, const char *, ...)" 550c3983b2SBen Gras.Ft int 560c3983b2SBen Gras.Fn easprintf "char ** restrict str" "const char * restrict fmt" "..." 570c3983b2SBen Gras.Ft FILE * 580c3983b2SBen Gras.Fn efopen "const char *p" "const char *m" 590c3983b2SBen Gras.Ft void * 60*0a6a1f1dSLionel Sambuc.Fn ecalloc "size_t n" "size_t s" 610c3983b2SBen Gras.Ft void * 620c3983b2SBen Gras.Fn emalloc "size_t n" 630c3983b2SBen Gras.Ft void * 640c3983b2SBen Gras.Fn erealloc "void *p" "size_t n" 65*0a6a1f1dSLionel Sambuc.Ft void 66*0a6a1f1dSLionel Sambuc.Fn ereallocarr "void *p" "size_t n" "size_t s" 670c3983b2SBen Gras.Ft char * 680c3983b2SBen Gras.Fn estrdup "const char *s" 690c3983b2SBen Gras.Ft char * 700c3983b2SBen Gras.Fn estrndup "const char *s" "size_t len" 710c3983b2SBen Gras.Ft size_t 720c3983b2SBen Gras.Fn estrlcat "char *dst" "const char *src" "size_t len" 730c3983b2SBen Gras.Ft size_t 740c3983b2SBen Gras.Fn estrlcpy "char *dst" "const char *src" "size_t len" 75*0a6a1f1dSLionel Sambuc.Ft intmax_t 76*0a6a1f1dSLionel Sambuc.Fn estrtoi "const char * nptr" "int base" "intmax_t lo" "intmax_t hi" 77*0a6a1f1dSLionel Sambuc.Ft uintmax_t 78*0a6a1f1dSLionel Sambuc.Fn estrtou "const char * nptr" "int base" "uintmax_t lo" "uintmax_t hi" 790c3983b2SBen Gras.Ft int 800c3983b2SBen Gras.Fn evasprintf "char ** restrict str" "const char * restrict fmt" "..." 810c3983b2SBen Gras.Sh DESCRIPTION 820c3983b2SBen GrasThe 830c3983b2SBen Gras.Fn easprintf , 840c3983b2SBen Gras.Fn efopen , 850c3983b2SBen Gras.Fn ecalloc , 860c3983b2SBen Gras.Fn emalloc , 870c3983b2SBen Gras.Fn erealloc , 88*0a6a1f1dSLionel Sambuc.Fn ereallocarr , 890c3983b2SBen Gras.Fn estrdup , 900c3983b2SBen Gras.Fn estrndup , 910c3983b2SBen Gras.Fn estrlcat , 920c3983b2SBen Gras.Fn estrlcpy , 93*0a6a1f1dSLionel Sambuc.Fn estrtoi , 94*0a6a1f1dSLionel Sambuc.Fn estrtou , 950c3983b2SBen Grasand 960c3983b2SBen Gras.Fn evasprintf 970c3983b2SBen Grasfunctions 980c3983b2SBen Grasoperate exactly as the corresponding functions that do not start with an 990c3983b2SBen Gras.Sq e 1000c3983b2SBen Grasexcept that in case of an error, they call 1010c3983b2SBen Grasthe installed error handler that can be configured with 1020c3983b2SBen Gras.Fn esetfunc . 1030c3983b2SBen Gras.Pp 1040c3983b2SBen GrasFor the string handling functions, it is an error when the destination 1050c3983b2SBen Grasbuffer is not large enough to hold the complete string. 1060c3983b2SBen GrasFor functions that allocate memory or open a file, it is an error when 1070c3983b2SBen Grasthey would return a null pointer. 1080c3983b2SBen GrasThe default error handler is 1090c3983b2SBen Gras.Xr err 3 . 1100c3983b2SBen GrasThe function 1110c3983b2SBen Gras.Fn esetfunc 1120c3983b2SBen Grasreturns the previous error handler function. 1130c3983b2SBen GrasA 1140c3983b2SBen Gras.Dv NULL 1150c3983b2SBen Graserror handler will just call 1160c3983b2SBen Gras.Xr exit 3 . 1170c3983b2SBen Gras.Sh SEE ALSO 1180c3983b2SBen Gras.Xr asprintf 3 , 1190c3983b2SBen Gras.Xr calloc 3 , 1200c3983b2SBen Gras.Xr err 3 , 1210c3983b2SBen Gras.Xr exit 3 , 1220c3983b2SBen Gras.Xr fopen 3 , 1230c3983b2SBen Gras.Xr malloc 3 , 1240c3983b2SBen Gras.Xr realloc 3 , 125*0a6a1f1dSLionel Sambuc.Xr reallocarr 3 , 1260c3983b2SBen Gras.Xr strdup 3 , 1270c3983b2SBen Gras.Xr strlcat 3 , 1280c3983b2SBen Gras.Xr strlcpy 3 , 1290c3983b2SBen Gras.Xr strndup 3 , 130*0a6a1f1dSLionel Sambuc.Xr strtoi 3 , 131*0a6a1f1dSLionel Sambuc.Xr strtou 3 , 1320c3983b2SBen Gras.Xr vasprintf 3 133*0a6a1f1dSLionel Sambuc.Sh HISTORY 134*0a6a1f1dSLionel SambucThe 135*0a6a1f1dSLionel Sambuc.Fn estrtoi , 136*0a6a1f1dSLionel Sambuc.Fn estrtou 137*0a6a1f1dSLionel Sambucand 138*0a6a1f1dSLionel Sambuc.Fn ereallocarr 139*0a6a1f1dSLionel Sambucfunctions were added in 140*0a6a1f1dSLionel Sambuc.Nx 8 . 141