158f0484fSRodney W. Grimes.\" Copyright (c) 1993 258f0484fSRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 358f0484fSRodney W. Grimes.\" 458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions 658f0484fSRodney W. Grimes.\" are met: 758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 858f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 1058f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 1158f0484fSRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 1258f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 1358f0484fSRodney W. Grimes.\" must display the following acknowledgement: 1458f0484fSRodney W. Grimes.\" This product includes software developed by the University of 1558f0484fSRodney W. Grimes.\" California, Berkeley and its contributors. 1658f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 1758f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 1858f0484fSRodney W. Grimes.\" without specific prior written permission. 1958f0484fSRodney W. Grimes.\" 2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3058f0484fSRodney W. Grimes.\" SUCH DAMAGE. 3158f0484fSRodney W. Grimes.\" 323688be0eSGarrett Wollman.\" From: @(#)err.3 8.1 (Berkeley) 6/9/93 337f3dea24SPeter Wemm.\" $FreeBSD$ 3458f0484fSRodney W. Grimes.\" 356da7e7c6SBruce Evans.Dd Mar 6, 1999 3658f0484fSRodney W. Grimes.Dt ERR 3 3758f0484fSRodney W. Grimes.Os BSD 4 3858f0484fSRodney W. Grimes.Sh NAME 3958f0484fSRodney W. Grimes.Nm err , 4058f0484fSRodney W. Grimes.Nm verr , 41b4b4fb87SGarrett Wollman.Nm errc , 42b4b4fb87SGarrett Wollman.Nm verrc , 4358f0484fSRodney W. Grimes.Nm errx , 4458f0484fSRodney W. Grimes.Nm verrx , 4558f0484fSRodney W. Grimes.Nm warn , 4658f0484fSRodney W. Grimes.Nm vwarn , 47b4b4fb87SGarrett Wollman.Nm warnc , 48b4b4fb87SGarrett Wollman.Nm vwarnc , 4958f0484fSRodney W. Grimes.Nm warnx , 503688be0eSGarrett Wollman.Nm vwarnx , 516da7e7c6SBruce Evans.Nm err_set_exit , 526da7e7c6SBruce Evans.Nm err_set_file 5358f0484fSRodney W. Grimes.Nd formatted error messages 5425bb73e0SAlexey Zelkin.Sh LIBRARY 5525bb73e0SAlexey Zelkin.Lb libc 5658f0484fSRodney W. Grimes.Sh SYNOPSIS 5758f0484fSRodney W. Grimes.Fd #include <err.h> 5858f0484fSRodney W. Grimes.Ft void 5958f0484fSRodney W. Grimes.Fn err "int eval" "const char *fmt" "..." 6058f0484fSRodney W. Grimes.Ft void 616da7e7c6SBruce Evans.Fn err_set_exit "void (*exitf)(int)" 626da7e7c6SBruce Evans.Ft void 636da7e7c6SBruce Evans.Fn err_set_file "void *vfp" 646da7e7c6SBruce Evans.Ft void 65b4b4fb87SGarrett Wollman.Fn errc "int eval" "int code" "const char *fmt" "..." 66b4b4fb87SGarrett Wollman.Ft void 6758f0484fSRodney W. Grimes.Fn errx "int eval" "const char *fmt" "..." 6858f0484fSRodney W. Grimes.Ft void 6958f0484fSRodney W. Grimes.Fn warn "const char *fmt" "..." 7058f0484fSRodney W. Grimes.Ft void 71b4b4fb87SGarrett Wollman.Fn warnc "int code" "const char *fmt" "..." 7258f0484fSRodney W. Grimes.Ft void 73b4b4fb87SGarrett Wollman.Fn warnx "const char *fmt" "..." 747a30f183SBruce Evans.Fd #include <stdarg.h> 757a30f183SBruce Evans.Ft void 767a30f183SBruce Evans.Fn verr "int eval" "const char *fmt" "va_list args" 777a30f183SBruce Evans.Ft void 78b4b4fb87SGarrett Wollman.Fn verrc "int eval" "int code" "const char *fmt" "va_list args" 79b4b4fb87SGarrett Wollman.Ft void 807a30f183SBruce Evans.Fn verrx "int eval" "const char *fmt" "va_list args" 817a30f183SBruce Evans.Ft void 827a30f183SBruce Evans.Fn vwarn "const char *fmt" "va_list args" 837a30f183SBruce Evans.Ft void 84b4b4fb87SGarrett Wollman.Fn vwarnc "int code" "const char *fmt" "va_list args" 85b4b4fb87SGarrett Wollman.Ft void 867a30f183SBruce Evans.Fn vwarnx "const char *fmt" "va_list args" 8758f0484fSRodney W. Grimes.Sh DESCRIPTION 8858f0484fSRodney W. GrimesThe 8958f0484fSRodney W. Grimes.Fn err 9058f0484fSRodney W. Grimesand 9158f0484fSRodney W. Grimes.Fn warn 9258f0484fSRodney W. Grimesfamily of functions display a formatted error message on the standard 933688be0eSGarrett Wollmanerror output, or on another file specified using the 943688be0eSGarrett Wollman.Fn err_set_file 953688be0eSGarrett Wollmanfunction. 9658f0484fSRodney W. GrimesIn all cases, the last component of the program name, a colon character, 9758f0484fSRodney W. Grimesand a space are output. 9858f0484fSRodney W. GrimesIf the 99b4183771SGuy Helmer.Fa fmt 100ac51e282SRobert Nordierargument is not NULL, the formatted error message is output. 101b4183771SGuy HelmerThe output is terminated by a newline character. 102b4183771SGuy Helmer.Pp 103b4183771SGuy HelmerThe 104b4183771SGuy Helmer.Fn err , 105b4183771SGuy Helmer.Fn errc , 106b4183771SGuy Helmer.Fn verr , 107b4183771SGuy Helmer.Fn verrc , 108b4183771SGuy Helmer.Fn warn , 109b4183771SGuy Helmer.Fn warnc , 110b4183771SGuy Helmer.Fn vwarn , 111b4183771SGuy Helmerand 112b4183771SGuy Helmer.Fn vwarnc 113b4183771SGuy Helmerfunctions append an error message obtained from 114b4183771SGuy Helmer.Xr strerror 3 115b4183771SGuy Helmerbased on a code or the global variable 116b4183771SGuy Helmer.Va errno , 117b4183771SGuy Helmerpreceeded by another colon and space unless the 118b4183771SGuy Helmer.Fa fmt 119b4183771SGuy Helmerargument is 120b4183771SGuy Helmer.Dv NULL . 121b4183771SGuy Helmer.Pp 12258f0484fSRodney W. GrimesIn the case of the 123b4b4fb87SGarrett Wollman.Fn errc , 124b4b4fb87SGarrett Wollman.Fn verrc , 125b4b4fb87SGarrett Wollman.Fn warnc , 12658f0484fSRodney W. Grimesand 127b4b4fb87SGarrett Wollman.Fn vwarnc 128ac51e282SRobert Nordierfunctions, 129b4183771SGuy Helmerthe 130b4183771SGuy Helmer.Fa code 131b4183771SGuy Helmerargument is used to look up the error message. 13258f0484fSRodney W. Grimes.Pp 13358f0484fSRodney W. GrimesThe 13458f0484fSRodney W. Grimes.Fn err , 13558f0484fSRodney W. Grimes.Fn verr , 136b4b4fb87SGarrett Wollman.Fn warn , 137b4b4fb87SGarrett Wollmanand 138b4b4fb87SGarrett Wollman.Fn vwarn 139b4b4fb87SGarrett Wollmanfunctions use the global variable 140b4b4fb87SGarrett Wollman.Va errno 141b4183771SGuy Helmerto look up the error message. 142b4183771SGuy Helmer.Pp 143b4183771SGuy HelmerThe 144b4183771SGuy Helmer.Fn errx 145b4183771SGuy Helmerand 146b4183771SGuy Helmer.Fn warnx 147b4183771SGuy Helmerfunctions do not append an error message. 148b4b4fb87SGarrett Wollman.Pp 149b4b4fb87SGarrett WollmanThe 150b4b4fb87SGarrett Wollman.Fn err , 151b4b4fb87SGarrett Wollman.Fn verr , 152b4b4fb87SGarrett Wollman.Fn errc , 153b4b4fb87SGarrett Wollman.Fn verrc , 15458f0484fSRodney W. Grimes.Fn errx , 15558f0484fSRodney W. Grimesand 15658f0484fSRodney W. Grimes.Fn verrx 15758f0484fSRodney W. Grimesfunctions do not return, but exit with the value of the argument 15858f0484fSRodney W. Grimes.Fa eval . 1593688be0eSGarrett WollmanThe 1603688be0eSGarrett Wollman.Fn err_set_exit 1613688be0eSGarrett Wollmanfunction can be used to specify a function which is called before 16278b0b234SMike Pritchard.Xr exit 3 1633688be0eSGarrett Wollmanto perform any necessary cleanup; passing a null function pointer for 1643688be0eSGarrett Wollman.Va exitf 1653688be0eSGarrett Wollmanresets the hook to do nothing. 1666da7e7c6SBruce EvansThe 1676da7e7c6SBruce Evans.Fn err_set_file 1686da7e7c6SBruce Evansfunction sets the output stream used by the other functions. 1696da7e7c6SBruce EvansIts 170b4183771SGuy Helmer.Fa vfp 1716da7e7c6SBruce Evansargument must be either a pointer to an open stream 1726da7e7c6SBruce Evans(possibly already converted to void *) 1736da7e7c6SBruce Evansor a null pointer 1746da7e7c6SBruce Evans(in which case the output stream is set to standard error). 17558f0484fSRodney W. Grimes.Sh EXAMPLES 17658f0484fSRodney W. GrimesDisplay the current errno information string and exit: 17758f0484fSRodney W. Grimes.Bd -literal -offset indent 17858f0484fSRodney W. Grimesif ((p = malloc(size)) == NULL) 17958f0484fSRodney W. Grimes err(1, NULL); 18058f0484fSRodney W. Grimesif ((fd = open(file_name, O_RDONLY, 0)) == -1) 18158f0484fSRodney W. Grimes err(1, "%s", file_name); 18258f0484fSRodney W. Grimes.Ed 18358f0484fSRodney W. Grimes.Pp 18458f0484fSRodney W. GrimesDisplay an error message and exit: 18558f0484fSRodney W. Grimes.Bd -literal -offset indent 18658f0484fSRodney W. Grimesif (tm.tm_hour < START_TIME) 18758f0484fSRodney W. Grimes errx(1, "too early, wait until %s", start_time_string); 18858f0484fSRodney W. Grimes.Ed 18958f0484fSRodney W. Grimes.Pp 19058f0484fSRodney W. GrimesWarn of an error: 19158f0484fSRodney W. Grimes.Bd -literal -offset indent 19258f0484fSRodney W. Grimesif ((fd = open(raw_device, O_RDONLY, 0)) == -1) 19358f0484fSRodney W. Grimes warnx("%s: %s: trying the block device", 19458f0484fSRodney W. Grimes raw_device, strerror(errno)); 19558f0484fSRodney W. Grimesif ((fd = open(block_device, O_RDONLY, 0)) == -1) 19658f0484fSRodney W. Grimes err(1, "%s", block_device); 19758f0484fSRodney W. Grimes.Ed 198b4b4fb87SGarrett Wollman.Pp 199b4b4fb87SGarrett WollmanWarn of an error without using the global variable 200b4b4fb87SGarrett Wollman.Va errno : 201b4b4fb87SGarrett Wollman.Bd -literal -offset indent 202b4b4fb87SGarrett Wollmanerror = my_function(); /* returns a value from <errno.h> */ 203b4b4fb87SGarrett Wollmanif (error != 0) 204b4b4fb87SGarrett Wollman warnc(error, "my_function"); 205b4b4fb87SGarrett Wollman.Ed 20658f0484fSRodney W. Grimes.Sh SEE ALSO 20778b0b234SMike Pritchard.Xr exit 3 , 20858f0484fSRodney W. Grimes.Xr strerror 3 20958f0484fSRodney W. Grimes.Sh HISTORY 21058f0484fSRodney W. GrimesThe 21158f0484fSRodney W. Grimes.Fn err 21258f0484fSRodney W. Grimesand 21358f0484fSRodney W. Grimes.Fn warn 2147bdf80e5SMike Pritchardfunctions first appeared in 2157bdf80e5SMike Pritchard.Bx 4.4 . 216b4b4fb87SGarrett WollmanThe 217b4b4fb87SGarrett Wollman.Fn err_set_exit 2186da7e7c6SBruce Evansand 2196da7e7c6SBruce Evans.Fn err_set_file 220b4b4fb87SGarrett Wollmanfunctions first appeared in 221b4b4fb87SGarrett Wollman.Fx 2.1 . 222b4b4fb87SGarrett WollmanThe 223b4b4fb87SGarrett Wollman.Fn errc 224b4b4fb87SGarrett Wollmanand 225b4b4fb87SGarrett Wollman.Fn warnc 226b4b4fb87SGarrett Wollmanfunctions first appeared in 227b4b4fb87SGarrett Wollman.Fx 3.0 . 228