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. 12*fbbd9655SWarner Losh.\" 3. 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.\" 28faf6e948SEitan Adler.Dd March 29, 2012 2958f0484fSRodney W. Grimes.Dt ERR 3 30a307d598SRuslan Ermilov.Os 3158f0484fSRodney W. Grimes.Sh NAME 3258f0484fSRodney W. Grimes.Nm err , 3358f0484fSRodney W. Grimes.Nm verr , 34b4b4fb87SGarrett Wollman.Nm errc , 35b4b4fb87SGarrett Wollman.Nm verrc , 3658f0484fSRodney W. Grimes.Nm errx , 3758f0484fSRodney W. Grimes.Nm verrx , 3858f0484fSRodney W. Grimes.Nm warn , 3958f0484fSRodney W. Grimes.Nm vwarn , 40b4b4fb87SGarrett Wollman.Nm warnc , 41b4b4fb87SGarrett Wollman.Nm vwarnc , 4258f0484fSRodney W. Grimes.Nm warnx , 433688be0eSGarrett Wollman.Nm vwarnx , 446da7e7c6SBruce Evans.Nm err_set_exit , 456da7e7c6SBruce Evans.Nm err_set_file 4658f0484fSRodney W. Grimes.Nd formatted error messages 4725bb73e0SAlexey Zelkin.Sh LIBRARY 4825bb73e0SAlexey Zelkin.Lb libc 4958f0484fSRodney W. Grimes.Sh SYNOPSIS 5032eef9aeSRuslan Ermilov.In err.h 5158f0484fSRodney W. Grimes.Ft void 5258f0484fSRodney W. Grimes.Fn err "int eval" "const char *fmt" "..." 5358f0484fSRodney W. Grimes.Ft void 546da7e7c6SBruce Evans.Fn err_set_exit "void (*exitf)(int)" 556da7e7c6SBruce Evans.Ft void 566da7e7c6SBruce Evans.Fn err_set_file "void *vfp" 576da7e7c6SBruce Evans.Ft void 58b4b4fb87SGarrett Wollman.Fn errc "int eval" "int code" "const char *fmt" "..." 59b4b4fb87SGarrett Wollman.Ft void 6058f0484fSRodney W. Grimes.Fn errx "int eval" "const char *fmt" "..." 6158f0484fSRodney W. Grimes.Ft void 6258f0484fSRodney W. Grimes.Fn warn "const char *fmt" "..." 6358f0484fSRodney W. Grimes.Ft void 64b4b4fb87SGarrett Wollman.Fn warnc "int code" "const char *fmt" "..." 6558f0484fSRodney W. Grimes.Ft void 66b4b4fb87SGarrett Wollman.Fn warnx "const char *fmt" "..." 6732eef9aeSRuslan Ermilov.In stdarg.h 687a30f183SBruce Evans.Ft void 697a30f183SBruce Evans.Fn verr "int eval" "const char *fmt" "va_list args" 707a30f183SBruce Evans.Ft void 71b4b4fb87SGarrett Wollman.Fn verrc "int eval" "int code" "const char *fmt" "va_list args" 72b4b4fb87SGarrett Wollman.Ft void 737a30f183SBruce Evans.Fn verrx "int eval" "const char *fmt" "va_list args" 747a30f183SBruce Evans.Ft void 757a30f183SBruce Evans.Fn vwarn "const char *fmt" "va_list args" 767a30f183SBruce Evans.Ft void 77b4b4fb87SGarrett Wollman.Fn vwarnc "int code" "const char *fmt" "va_list args" 78b4b4fb87SGarrett Wollman.Ft void 797a30f183SBruce Evans.Fn vwarnx "const char *fmt" "va_list args" 8058f0484fSRodney W. Grimes.Sh DESCRIPTION 8158f0484fSRodney W. GrimesThe 8258f0484fSRodney W. Grimes.Fn err 8358f0484fSRodney W. Grimesand 8458f0484fSRodney W. Grimes.Fn warn 8558f0484fSRodney W. Grimesfamily of functions display a formatted error message on the standard 863688be0eSGarrett Wollmanerror output, or on another file specified using the 873688be0eSGarrett Wollman.Fn err_set_file 883688be0eSGarrett Wollmanfunction. 8958f0484fSRodney W. GrimesIn all cases, the last component of the program name, a colon character, 9058f0484fSRodney W. Grimesand a space are output. 9158f0484fSRodney W. GrimesIf the 92b4183771SGuy Helmer.Fa fmt 9307a9238fSDavid E. O'Brienargument is not NULL, the 9464437d39SRuslan Ermilov.Xr printf 3 Ns 9507a9238fSDavid E. O'Brien-like formatted error message is output. 96b4183771SGuy HelmerThe output is terminated by a newline character. 97b4183771SGuy Helmer.Pp 98b4183771SGuy HelmerThe 99b4183771SGuy Helmer.Fn err , 100b4183771SGuy Helmer.Fn errc , 101b4183771SGuy Helmer.Fn verr , 102b4183771SGuy Helmer.Fn verrc , 103b4183771SGuy Helmer.Fn warn , 104b4183771SGuy Helmer.Fn warnc , 105b4183771SGuy Helmer.Fn vwarn , 106b4183771SGuy Helmerand 107b4183771SGuy Helmer.Fn vwarnc 108b4183771SGuy Helmerfunctions append an error message obtained from 109b4183771SGuy Helmer.Xr strerror 3 110aeecffebSDiomidis Spinellisbased on a supplied error code value or the global variable 111b4183771SGuy Helmer.Va errno , 1127c637968SJeroen Ruigrok van der Wervenpreceded by another colon and space unless the 113b4183771SGuy Helmer.Fa fmt 114b4183771SGuy Helmerargument is 115b4183771SGuy Helmer.Dv NULL . 116b4183771SGuy Helmer.Pp 11758f0484fSRodney W. GrimesIn the case of the 118b4b4fb87SGarrett Wollman.Fn errc , 119b4b4fb87SGarrett Wollman.Fn verrc , 120b4b4fb87SGarrett Wollman.Fn warnc , 12158f0484fSRodney W. Grimesand 122b4b4fb87SGarrett Wollman.Fn vwarnc 123ac51e282SRobert Nordierfunctions, 124b4183771SGuy Helmerthe 125b4183771SGuy Helmer.Fa code 126b4183771SGuy Helmerargument is used to look up the error message. 12758f0484fSRodney W. Grimes.Pp 12858f0484fSRodney W. GrimesThe 12958f0484fSRodney W. Grimes.Fn err , 13058f0484fSRodney W. Grimes.Fn verr , 131b4b4fb87SGarrett Wollman.Fn warn , 132b4b4fb87SGarrett Wollmanand 133b4b4fb87SGarrett Wollman.Fn vwarn 134b4b4fb87SGarrett Wollmanfunctions use the global variable 135b4b4fb87SGarrett Wollman.Va errno 136b4183771SGuy Helmerto look up the error message. 137b4183771SGuy Helmer.Pp 138b4183771SGuy HelmerThe 139b4183771SGuy Helmer.Fn errx 140b4183771SGuy Helmerand 141b4183771SGuy Helmer.Fn warnx 142b4183771SGuy Helmerfunctions do not append an error message. 143b4b4fb87SGarrett Wollman.Pp 144b4b4fb87SGarrett WollmanThe 145b4b4fb87SGarrett Wollman.Fn err , 146b4b4fb87SGarrett Wollman.Fn verr , 147b4b4fb87SGarrett Wollman.Fn errc , 148b4b4fb87SGarrett Wollman.Fn verrc , 14958f0484fSRodney W. Grimes.Fn errx , 15058f0484fSRodney W. Grimesand 15158f0484fSRodney W. Grimes.Fn verrx 15258f0484fSRodney W. Grimesfunctions do not return, but exit with the value of the argument 15358f0484fSRodney W. Grimes.Fa eval . 1546febaa3aSJoseph KoshyIt is recommended that the standard values defined in 1556febaa3aSJoseph Koshy.Xr sysexits 3 1566febaa3aSJoseph Koshybe used for the value of 1576febaa3aSJoseph Koshy.Fa eval . 1583688be0eSGarrett WollmanThe 1593688be0eSGarrett Wollman.Fn err_set_exit 1603688be0eSGarrett Wollmanfunction can be used to specify a function which is called before 16178b0b234SMike Pritchard.Xr exit 3 1623688be0eSGarrett Wollmanto perform any necessary cleanup; passing a null function pointer for 1633688be0eSGarrett Wollman.Va exitf 1643688be0eSGarrett Wollmanresets the hook to do nothing. 1656da7e7c6SBruce EvansThe 1666da7e7c6SBruce Evans.Fn err_set_file 1676da7e7c6SBruce Evansfunction sets the output stream used by the other functions. 1686da7e7c6SBruce EvansIts 169b4183771SGuy Helmer.Fa vfp 1706da7e7c6SBruce Evansargument must be either a pointer to an open stream 1716da7e7c6SBruce Evans(possibly already converted to void *) 1726da7e7c6SBruce Evansor a null pointer 1736da7e7c6SBruce Evans(in which case the output stream is set to standard error). 17458f0484fSRodney W. Grimes.Sh EXAMPLES 17558f0484fSRodney W. GrimesDisplay the current errno information string and exit: 17658f0484fSRodney W. Grimes.Bd -literal -offset indent 17758f0484fSRodney W. Grimesif ((p = malloc(size)) == NULL) 17846658b2bSRobert Watson err(EX_OSERR, NULL); 17958f0484fSRodney W. Grimesif ((fd = open(file_name, O_RDONLY, 0)) == -1) 18046658b2bSRobert Watson err(EX_NOINPUT, "%s", file_name); 18158f0484fSRodney W. Grimes.Ed 18258f0484fSRodney W. Grimes.Pp 18358f0484fSRodney W. GrimesDisplay an error message and exit: 18458f0484fSRodney W. Grimes.Bd -literal -offset indent 18558f0484fSRodney W. Grimesif (tm.tm_hour < START_TIME) 18646658b2bSRobert Watson errx(EX_DATAERR, "too early, wait until %s", 18746658b2bSRobert Watson 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) 19646658b2bSRobert Watson err(EX_OSFILE, "%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 , 208823f68a2SMike Barcroft.Xr fmtmsg 3 , 20907a9238fSDavid E. O'Brien.Xr printf 3 , 2106febaa3aSJoseph Koshy.Xr strerror 3 , 2116febaa3aSJoseph Koshy.Xr sysexits 3 212faf6e948SEitan Adler.Sh STANDARDS 213faf6e948SEitan AdlerThe 214faf6e948SEitan Adler.Fn err 215faf6e948SEitan Adlerand 216faf6e948SEitan Adler.Fn warn 217b9cec40cSEitan Adlerfamilies of functions are 218b9cec40cSEitan Adler.Bx 219b9cec40cSEitan Adlerextensions. 220faf6e948SEitan AdlerAs such they should not be used in truly portable code. 221faf6e948SEitan AdlerUse 222faf6e948SEitan Adler.Fn strerror 223faf6e948SEitan Adleror similar functions instead. 22458f0484fSRodney W. Grimes.Sh HISTORY 22558f0484fSRodney W. GrimesThe 22658f0484fSRodney W. Grimes.Fn err 22758f0484fSRodney W. Grimesand 22858f0484fSRodney W. Grimes.Fn warn 2297bdf80e5SMike Pritchardfunctions first appeared in 2307bdf80e5SMike Pritchard.Bx 4.4 . 231b4b4fb87SGarrett WollmanThe 232b4b4fb87SGarrett Wollman.Fn err_set_exit 2336da7e7c6SBruce Evansand 2346da7e7c6SBruce Evans.Fn err_set_file 235b4b4fb87SGarrett Wollmanfunctions first appeared in 236b4b4fb87SGarrett Wollman.Fx 2.1 . 237b4b4fb87SGarrett WollmanThe 238b4b4fb87SGarrett Wollman.Fn errc 239b4b4fb87SGarrett Wollmanand 240b4b4fb87SGarrett Wollman.Fn warnc 241b4b4fb87SGarrett Wollmanfunctions first appeared in 242b4b4fb87SGarrett Wollman.Fx 3.0 . 243