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.\" 4. Neither the name of the University nor the names of its contributors 1358f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 1458f0484fSRodney W. Grimes.\" without specific prior written permission. 1558f0484fSRodney W. Grimes.\" 1658f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1758f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1858f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1958f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2058f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2158f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2258f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2358f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2458f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2558f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2658f0484fSRodney W. Grimes.\" SUCH DAMAGE. 2758f0484fSRodney W. Grimes.\" 283688be0eSGarrett Wollman.\" From: @(#)err.3 8.1 (Berkeley) 6/9/93 297f3dea24SPeter Wemm.\" $FreeBSD$ 3058f0484fSRodney W. Grimes.\" 31*faf6e948SEitan Adler.Dd March 29, 2012 3258f0484fSRodney W. Grimes.Dt ERR 3 33a307d598SRuslan Ermilov.Os 3458f0484fSRodney W. Grimes.Sh NAME 3558f0484fSRodney W. Grimes.Nm err , 3658f0484fSRodney W. Grimes.Nm verr , 37b4b4fb87SGarrett Wollman.Nm errc , 38b4b4fb87SGarrett Wollman.Nm verrc , 3958f0484fSRodney W. Grimes.Nm errx , 4058f0484fSRodney W. Grimes.Nm verrx , 4158f0484fSRodney W. Grimes.Nm warn , 4258f0484fSRodney W. Grimes.Nm vwarn , 43b4b4fb87SGarrett Wollman.Nm warnc , 44b4b4fb87SGarrett Wollman.Nm vwarnc , 4558f0484fSRodney W. Grimes.Nm warnx , 463688be0eSGarrett Wollman.Nm vwarnx , 476da7e7c6SBruce Evans.Nm err_set_exit , 486da7e7c6SBruce Evans.Nm err_set_file 4958f0484fSRodney W. Grimes.Nd formatted error messages 5025bb73e0SAlexey Zelkin.Sh LIBRARY 5125bb73e0SAlexey Zelkin.Lb libc 5258f0484fSRodney W. Grimes.Sh SYNOPSIS 5332eef9aeSRuslan Ermilov.In err.h 5458f0484fSRodney W. Grimes.Ft void 5558f0484fSRodney W. Grimes.Fn err "int eval" "const char *fmt" "..." 5658f0484fSRodney W. Grimes.Ft void 576da7e7c6SBruce Evans.Fn err_set_exit "void (*exitf)(int)" 586da7e7c6SBruce Evans.Ft void 596da7e7c6SBruce Evans.Fn err_set_file "void *vfp" 606da7e7c6SBruce Evans.Ft void 61b4b4fb87SGarrett Wollman.Fn errc "int eval" "int code" "const char *fmt" "..." 62b4b4fb87SGarrett Wollman.Ft void 6358f0484fSRodney W. Grimes.Fn errx "int eval" "const char *fmt" "..." 6458f0484fSRodney W. Grimes.Ft void 6558f0484fSRodney W. Grimes.Fn warn "const char *fmt" "..." 6658f0484fSRodney W. Grimes.Ft void 67b4b4fb87SGarrett Wollman.Fn warnc "int code" "const char *fmt" "..." 6858f0484fSRodney W. Grimes.Ft void 69b4b4fb87SGarrett Wollman.Fn warnx "const char *fmt" "..." 7032eef9aeSRuslan Ermilov.In stdarg.h 717a30f183SBruce Evans.Ft void 727a30f183SBruce Evans.Fn verr "int eval" "const char *fmt" "va_list args" 737a30f183SBruce Evans.Ft void 74b4b4fb87SGarrett Wollman.Fn verrc "int eval" "int code" "const char *fmt" "va_list args" 75b4b4fb87SGarrett Wollman.Ft void 767a30f183SBruce Evans.Fn verrx "int eval" "const char *fmt" "va_list args" 777a30f183SBruce Evans.Ft void 787a30f183SBruce Evans.Fn vwarn "const char *fmt" "va_list args" 797a30f183SBruce Evans.Ft void 80b4b4fb87SGarrett Wollman.Fn vwarnc "int code" "const char *fmt" "va_list args" 81b4b4fb87SGarrett Wollman.Ft void 827a30f183SBruce Evans.Fn vwarnx "const char *fmt" "va_list args" 8358f0484fSRodney W. Grimes.Sh DESCRIPTION 8458f0484fSRodney W. GrimesThe 8558f0484fSRodney W. Grimes.Fn err 8658f0484fSRodney W. Grimesand 8758f0484fSRodney W. Grimes.Fn warn 8858f0484fSRodney W. Grimesfamily of functions display a formatted error message on the standard 893688be0eSGarrett Wollmanerror output, or on another file specified using the 903688be0eSGarrett Wollman.Fn err_set_file 913688be0eSGarrett Wollmanfunction. 9258f0484fSRodney W. GrimesIn all cases, the last component of the program name, a colon character, 9358f0484fSRodney W. Grimesand a space are output. 9458f0484fSRodney W. GrimesIf the 95b4183771SGuy Helmer.Fa fmt 9607a9238fSDavid E. O'Brienargument is not NULL, the 9764437d39SRuslan Ermilov.Xr printf 3 Ns 9807a9238fSDavid E. O'Brien-like formatted error message is output. 99b4183771SGuy HelmerThe output is terminated by a newline character. 100b4183771SGuy Helmer.Pp 101b4183771SGuy HelmerThe 102b4183771SGuy Helmer.Fn err , 103b4183771SGuy Helmer.Fn errc , 104b4183771SGuy Helmer.Fn verr , 105b4183771SGuy Helmer.Fn verrc , 106b4183771SGuy Helmer.Fn warn , 107b4183771SGuy Helmer.Fn warnc , 108b4183771SGuy Helmer.Fn vwarn , 109b4183771SGuy Helmerand 110b4183771SGuy Helmer.Fn vwarnc 111b4183771SGuy Helmerfunctions append an error message obtained from 112b4183771SGuy Helmer.Xr strerror 3 113aeecffebSDiomidis Spinellisbased on a supplied error code value or the global variable 114b4183771SGuy Helmer.Va errno , 1157c637968SJeroen Ruigrok van der Wervenpreceded by another colon and space unless the 116b4183771SGuy Helmer.Fa fmt 117b4183771SGuy Helmerargument is 118b4183771SGuy Helmer.Dv NULL . 119b4183771SGuy Helmer.Pp 12058f0484fSRodney W. GrimesIn the case of the 121b4b4fb87SGarrett Wollman.Fn errc , 122b4b4fb87SGarrett Wollman.Fn verrc , 123b4b4fb87SGarrett Wollman.Fn warnc , 12458f0484fSRodney W. Grimesand 125b4b4fb87SGarrett Wollman.Fn vwarnc 126ac51e282SRobert Nordierfunctions, 127b4183771SGuy Helmerthe 128b4183771SGuy Helmer.Fa code 129b4183771SGuy Helmerargument is used to look up the error message. 13058f0484fSRodney W. Grimes.Pp 13158f0484fSRodney W. GrimesThe 13258f0484fSRodney W. Grimes.Fn err , 13358f0484fSRodney W. Grimes.Fn verr , 134b4b4fb87SGarrett Wollman.Fn warn , 135b4b4fb87SGarrett Wollmanand 136b4b4fb87SGarrett Wollman.Fn vwarn 137b4b4fb87SGarrett Wollmanfunctions use the global variable 138b4b4fb87SGarrett Wollman.Va errno 139b4183771SGuy Helmerto look up the error message. 140b4183771SGuy Helmer.Pp 141b4183771SGuy HelmerThe 142b4183771SGuy Helmer.Fn errx 143b4183771SGuy Helmerand 144b4183771SGuy Helmer.Fn warnx 145b4183771SGuy Helmerfunctions do not append an error message. 146b4b4fb87SGarrett Wollman.Pp 147b4b4fb87SGarrett WollmanThe 148b4b4fb87SGarrett Wollman.Fn err , 149b4b4fb87SGarrett Wollman.Fn verr , 150b4b4fb87SGarrett Wollman.Fn errc , 151b4b4fb87SGarrett Wollman.Fn verrc , 15258f0484fSRodney W. Grimes.Fn errx , 15358f0484fSRodney W. Grimesand 15458f0484fSRodney W. Grimes.Fn verrx 15558f0484fSRodney W. Grimesfunctions do not return, but exit with the value of the argument 15658f0484fSRodney W. Grimes.Fa eval . 1576febaa3aSJoseph KoshyIt is recommended that the standard values defined in 1586febaa3aSJoseph Koshy.Xr sysexits 3 1596febaa3aSJoseph Koshybe used for the value of 1606febaa3aSJoseph Koshy.Fa eval . 1613688be0eSGarrett WollmanThe 1623688be0eSGarrett Wollman.Fn err_set_exit 1633688be0eSGarrett Wollmanfunction can be used to specify a function which is called before 16478b0b234SMike Pritchard.Xr exit 3 1653688be0eSGarrett Wollmanto perform any necessary cleanup; passing a null function pointer for 1663688be0eSGarrett Wollman.Va exitf 1673688be0eSGarrett Wollmanresets the hook to do nothing. 1686da7e7c6SBruce EvansThe 1696da7e7c6SBruce Evans.Fn err_set_file 1706da7e7c6SBruce Evansfunction sets the output stream used by the other functions. 1716da7e7c6SBruce EvansIts 172b4183771SGuy Helmer.Fa vfp 1736da7e7c6SBruce Evansargument must be either a pointer to an open stream 1746da7e7c6SBruce Evans(possibly already converted to void *) 1756da7e7c6SBruce Evansor a null pointer 1766da7e7c6SBruce Evans(in which case the output stream is set to standard error). 17758f0484fSRodney W. Grimes.Sh EXAMPLES 17858f0484fSRodney W. GrimesDisplay the current errno information string and exit: 17958f0484fSRodney W. Grimes.Bd -literal -offset indent 18058f0484fSRodney W. Grimesif ((p = malloc(size)) == NULL) 18146658b2bSRobert Watson err(EX_OSERR, NULL); 18258f0484fSRodney W. Grimesif ((fd = open(file_name, O_RDONLY, 0)) == -1) 18346658b2bSRobert Watson err(EX_NOINPUT, "%s", file_name); 18458f0484fSRodney W. Grimes.Ed 18558f0484fSRodney W. Grimes.Pp 18658f0484fSRodney W. GrimesDisplay an error message and exit: 18758f0484fSRodney W. Grimes.Bd -literal -offset indent 18858f0484fSRodney W. Grimesif (tm.tm_hour < START_TIME) 18946658b2bSRobert Watson errx(EX_DATAERR, "too early, wait until %s", 19046658b2bSRobert Watson start_time_string); 19158f0484fSRodney W. Grimes.Ed 19258f0484fSRodney W. Grimes.Pp 19358f0484fSRodney W. GrimesWarn of an error: 19458f0484fSRodney W. Grimes.Bd -literal -offset indent 19558f0484fSRodney W. Grimesif ((fd = open(raw_device, O_RDONLY, 0)) == -1) 19658f0484fSRodney W. Grimes warnx("%s: %s: trying the block device", 19758f0484fSRodney W. Grimes raw_device, strerror(errno)); 19858f0484fSRodney W. Grimesif ((fd = open(block_device, O_RDONLY, 0)) == -1) 19946658b2bSRobert Watson err(EX_OSFILE, "%s", block_device); 20058f0484fSRodney W. Grimes.Ed 201b4b4fb87SGarrett Wollman.Pp 202b4b4fb87SGarrett WollmanWarn of an error without using the global variable 203b4b4fb87SGarrett Wollman.Va errno : 204b4b4fb87SGarrett Wollman.Bd -literal -offset indent 205b4b4fb87SGarrett Wollmanerror = my_function(); /* returns a value from <errno.h> */ 206b4b4fb87SGarrett Wollmanif (error != 0) 207b4b4fb87SGarrett Wollman warnc(error, "my_function"); 208b4b4fb87SGarrett Wollman.Ed 20958f0484fSRodney W. Grimes.Sh SEE ALSO 21078b0b234SMike Pritchard.Xr exit 3 , 211823f68a2SMike Barcroft.Xr fmtmsg 3 , 21207a9238fSDavid E. O'Brien.Xr printf 3 , 2136febaa3aSJoseph Koshy.Xr strerror 3 , 2146febaa3aSJoseph Koshy.Xr sysexits 3 215*faf6e948SEitan Adler.Sh STANDARDS 216*faf6e948SEitan AdlerThe 217*faf6e948SEitan Adler.Fn err 218*faf6e948SEitan Adlerand 219*faf6e948SEitan Adler.Fn warn 220*faf6e948SEitan Adlerfamilies of functions are BSD extensions. 221*faf6e948SEitan AdlerAs such they should not be used in truly portable code. 222*faf6e948SEitan AdlerUse 223*faf6e948SEitan Adler.Fn strerror 224*faf6e948SEitan Adleror similar functions instead. 22558f0484fSRodney W. Grimes.Sh HISTORY 22658f0484fSRodney W. GrimesThe 22758f0484fSRodney W. Grimes.Fn err 22858f0484fSRodney W. Grimesand 22958f0484fSRodney W. Grimes.Fn warn 2307bdf80e5SMike Pritchardfunctions first appeared in 2317bdf80e5SMike Pritchard.Bx 4.4 . 232b4b4fb87SGarrett WollmanThe 233b4b4fb87SGarrett Wollman.Fn err_set_exit 2346da7e7c6SBruce Evansand 2356da7e7c6SBruce Evans.Fn err_set_file 236b4b4fb87SGarrett Wollmanfunctions first appeared in 237b4b4fb87SGarrett Wollman.Fx 2.1 . 238b4b4fb87SGarrett WollmanThe 239b4b4fb87SGarrett Wollman.Fn errc 240b4b4fb87SGarrett Wollmanand 241b4b4fb87SGarrett Wollman.Fn warnc 242b4b4fb87SGarrett Wollmanfunctions first appeared in 243b4b4fb87SGarrett Wollman.Fx 3.0 . 244