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 9958f0484fSRodney W. Grimes.Va fmt 100ac51e282SRobert Nordierargument is not NULL, the formatted error message is output. 10158f0484fSRodney W. GrimesIn the case of the 102b4b4fb87SGarrett Wollman.Fn errc , 103b4b4fb87SGarrett Wollman.Fn verrc , 104b4b4fb87SGarrett Wollman.Fn warnc , 10558f0484fSRodney W. Grimesand 106b4b4fb87SGarrett Wollman.Fn vwarnc 107ac51e282SRobert Nordierfunctions, 108b4b4fb87SGarrett Wollmanthe error message string affiliated with the 109b4b4fb87SGarrett Wollman.Va code 110b4b4fb87SGarrett Wollmanargument is also output, 111ac51e282SRobert Nordierpreceded by another colon and space if necessary. 11258f0484fSRodney W. GrimesIn all cases, the output is followed by a newline character. 11358f0484fSRodney W. Grimes.Pp 11458f0484fSRodney W. GrimesThe 11558f0484fSRodney W. Grimes.Fn err , 11658f0484fSRodney W. Grimes.Fn verr , 117b4b4fb87SGarrett Wollman.Fn warn , 118b4b4fb87SGarrett Wollmanand 119b4b4fb87SGarrett Wollman.Fn vwarn 120b4b4fb87SGarrett Wollmanfunctions use the global variable 121b4b4fb87SGarrett Wollman.Va errno 122b4b4fb87SGarrett Wollmanrather than the 123b4b4fb87SGarrett Wollman.Va code 124b4b4fb87SGarrett Wollmanargument of the 125b4b4fb87SGarrett Wollman.Fn errc 126b4b4fb87SGarrett Wollmanfamily 127b4b4fb87SGarrett Wollman.Pp 128b4b4fb87SGarrett WollmanThe 129b4b4fb87SGarrett Wollman.Fn err , 130b4b4fb87SGarrett Wollman.Fn verr , 131b4b4fb87SGarrett Wollman.Fn errc , 132b4b4fb87SGarrett Wollman.Fn verrc , 13358f0484fSRodney W. Grimes.Fn errx , 13458f0484fSRodney W. Grimesand 13558f0484fSRodney W. Grimes.Fn verrx 13658f0484fSRodney W. Grimesfunctions do not return, but exit with the value of the argument 13758f0484fSRodney W. Grimes.Fa eval . 1383688be0eSGarrett WollmanThe 1393688be0eSGarrett Wollman.Fn err_set_exit 1403688be0eSGarrett Wollmanfunction can be used to specify a function which is called before 14178b0b234SMike Pritchard.Xr exit 3 1423688be0eSGarrett Wollmanto perform any necessary cleanup; passing a null function pointer for 1433688be0eSGarrett Wollman.Va exitf 1443688be0eSGarrett Wollmanresets the hook to do nothing. 1456da7e7c6SBruce EvansThe 1466da7e7c6SBruce Evans.Fn err_set_file 1476da7e7c6SBruce Evansfunction sets the output stream used by the other functions. 1486da7e7c6SBruce EvansIts 1496da7e7c6SBruce Evans.Va vfp 1506da7e7c6SBruce Evansargument must be either a pointer to an open stream 1516da7e7c6SBruce Evans(possibly already converted to void *) 1526da7e7c6SBruce Evansor a null pointer 1536da7e7c6SBruce Evans(in which case the output stream is set to standard error). 15458f0484fSRodney W. Grimes.Sh EXAMPLES 15558f0484fSRodney W. GrimesDisplay the current errno information string and exit: 15658f0484fSRodney W. Grimes.Bd -literal -offset indent 15758f0484fSRodney W. Grimesif ((p = malloc(size)) == NULL) 15858f0484fSRodney W. Grimes err(1, NULL); 15958f0484fSRodney W. Grimesif ((fd = open(file_name, O_RDONLY, 0)) == -1) 16058f0484fSRodney W. Grimes err(1, "%s", file_name); 16158f0484fSRodney W. Grimes.Ed 16258f0484fSRodney W. Grimes.Pp 16358f0484fSRodney W. GrimesDisplay an error message and exit: 16458f0484fSRodney W. Grimes.Bd -literal -offset indent 16558f0484fSRodney W. Grimesif (tm.tm_hour < START_TIME) 16658f0484fSRodney W. Grimes errx(1, "too early, wait until %s", start_time_string); 16758f0484fSRodney W. Grimes.Ed 16858f0484fSRodney W. Grimes.Pp 16958f0484fSRodney W. GrimesWarn of an error: 17058f0484fSRodney W. Grimes.Bd -literal -offset indent 17158f0484fSRodney W. Grimesif ((fd = open(raw_device, O_RDONLY, 0)) == -1) 17258f0484fSRodney W. Grimes warnx("%s: %s: trying the block device", 17358f0484fSRodney W. Grimes raw_device, strerror(errno)); 17458f0484fSRodney W. Grimesif ((fd = open(block_device, O_RDONLY, 0)) == -1) 17558f0484fSRodney W. Grimes err(1, "%s", block_device); 17658f0484fSRodney W. Grimes.Ed 177b4b4fb87SGarrett Wollman.Pp 178b4b4fb87SGarrett WollmanWarn of an error without using the global variable 179b4b4fb87SGarrett Wollman.Va errno : 180b4b4fb87SGarrett Wollman.Bd -literal -offset indent 181b4b4fb87SGarrett Wollmanerror = my_function(); /* returns a value from <errno.h> */ 182b4b4fb87SGarrett Wollmanif (error != 0) 183b4b4fb87SGarrett Wollman warnc(error, "my_function"); 184b4b4fb87SGarrett Wollman.Ed 18558f0484fSRodney W. Grimes.Sh SEE ALSO 18678b0b234SMike Pritchard.Xr exit 3 , 18758f0484fSRodney W. Grimes.Xr strerror 3 18858f0484fSRodney W. Grimes.Sh HISTORY 18958f0484fSRodney W. GrimesThe 19058f0484fSRodney W. Grimes.Fn err 19158f0484fSRodney W. Grimesand 19258f0484fSRodney W. Grimes.Fn warn 1937bdf80e5SMike Pritchardfunctions first appeared in 1947bdf80e5SMike Pritchard.Bx 4.4 . 195b4b4fb87SGarrett WollmanThe 196b4b4fb87SGarrett Wollman.Fn err_set_exit 1976da7e7c6SBruce Evansand 1986da7e7c6SBruce Evans.Fn err_set_file 199b4b4fb87SGarrett Wollmanfunctions first appeared in 200b4b4fb87SGarrett Wollman.Fx 2.1 . 201b4b4fb87SGarrett WollmanThe 202b4b4fb87SGarrett Wollman.Fn errc 203b4b4fb87SGarrett Wollmanand 204b4b4fb87SGarrett Wollman.Fn warnc 205b4b4fb87SGarrett Wollmanfunctions first appeared in 206b4b4fb87SGarrett Wollman.Fx 3.0 . 207