1.\" Copyright (c) 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" From: @(#)err.3 8.1 (Berkeley) 6/9/93 33.\" $Id: err.3,v 1.7 1997/03/19 00:43:13 bde Exp $ 34.\" 35.Dd April 13, 1995 36.Dt ERR 3 37.Os BSD 4 38.Sh NAME 39.Nm err , 40.Nm verr , 41.Nm errx , 42.Nm verrx , 43.Nm warn , 44.Nm vwarn , 45.Nm warnx , 46.Nm vwarnx , 47.Nm err_set_file , 48.Nm err_set_exit 49.Nd formatted error messages 50.Sh SYNOPSIS 51.Fd #include <err.h> 52.Ft void 53.Fn err "int eval" "const char *fmt" "..." 54.Ft void 55.Fn errx "int eval" "const char *fmt" "..." 56.Ft void 57.Fn warn "const char *fmt" "..." 58.Ft void 59.Fn warnx "const char *fmt" "..." 60.Ft void 61.Fn err_set_file "void *fp" 62.Ft void 63.Fn err_set_exit "void (*exitf)(int)" 64.Fd #include <stdarg.h> 65.Ft void 66.Fn verr "int eval" "const char *fmt" "va_list args" 67.Ft void 68.Fn verrx "int eval" "const char *fmt" "va_list args" 69.Ft void 70.Fn vwarn "const char *fmt" "va_list args" 71.Ft void 72.Fn vwarnx "const char *fmt" "va_list args" 73.Sh DESCRIPTION 74The 75.Fn err 76and 77.Fn warn 78family of functions display a formatted error message on the standard 79error output, or on another file specified using the 80.Fn err_set_file 81function. 82In all cases, the last component of the program name, a colon character, 83and a space are output. 84If the 85.Va fmt 86argument is not NULL, the formatted error message is output. 87In the case of the 88.Fn err , 89.Fn verr , 90.Fn warn , 91and 92.Fn vwarn 93functions, 94the error message string affiliated with the current value of 95the global variable 96.Va errno 97is also output, 98preceded by another colon and space if necessary. 99In all cases, the output is followed by a newline character. 100.Pp 101The 102.Fn err , 103.Fn verr , 104.Fn errx , 105and 106.Fn verrx 107functions do not return, but exit with the value of the argument 108.Fa eval . 109The 110.Fn err_set_exit 111function can be used to specify a function which is called before 112.Xr exit 3 113to perform any necessary cleanup; passing a null function pointer for 114.Va exitf 115resets the hook to do nothing. 116.Sh EXAMPLES 117Display the current errno information string and exit: 118.Bd -literal -offset indent 119if ((p = malloc(size)) == NULL) 120 err(1, NULL); 121if ((fd = open(file_name, O_RDONLY, 0)) == -1) 122 err(1, "%s", file_name); 123.Ed 124.Pp 125Display an error message and exit: 126.Bd -literal -offset indent 127if (tm.tm_hour < START_TIME) 128 errx(1, "too early, wait until %s", start_time_string); 129.Ed 130.Pp 131Warn of an error: 132.Bd -literal -offset indent 133if ((fd = open(raw_device, O_RDONLY, 0)) == -1) 134 warnx("%s: %s: trying the block device", 135 raw_device, strerror(errno)); 136if ((fd = open(block_device, O_RDONLY, 0)) == -1) 137 err(1, "%s", block_device); 138.Ed 139.Sh SEE ALSO 140.Xr exit 3 , 141.Xr strerror 3 142.Sh HISTORY 143The 144.Fn err 145and 146.Fn warn 147functions first appeared in 148.Bx 4.4 . 149