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$ 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 verr "int eval" "const char *fmt" "va_list args" 56.Ft void 57.Fn errx "int eval" "const char *fmt" "..." 58.Ft void 59.Fn verrx "int eval" "const char *fmt" "va_list args" 60.Ft void 61.Fn warn "const char *fmt" "..." 62.Ft void 63.Fn vwarn "const char *fmt" "va_list args" 64.Ft void 65.Fn warnx "const char *fmt" "..." 66.Ft void 67.Fn vwarnx "const char *fmt" "va_list args" 68.Ft void 69.Fn err_set_file "void *fp" 70.Ft void 71.Fn err_set_exit "void (*exitf)(int)" 72.Sh DESCRIPTION 73The 74.Fn err 75and 76.Fn warn 77family of functions display a formatted error message on the standard 78error output, or on another file specified using the 79.Fn err_set_file 80function. 81In all cases, the last component of the program name, a colon character, 82and a space are output. 83If the 84.Va fmt 85argument is not NULL, the formatted error message, a colon character, 86and a space are output. 87In the case of the 88.Fn err , 89.Fn verr , 90.Fn warn , 91and 92.Fn vwarn 93functions, the error message string affiliated with the current value of 94the global variable 95.Va errno 96is output. 97In all cases, the output is followed by a newline character. 98.Pp 99The 100.Fn err , 101.Fn verr , 102.Fn errx , 103and 104.Fn verrx 105functions do not return, but exit with the value of the argument 106.Fa eval . 107The 108.Fn err_set_exit 109function can be used to specify a function which is called before 110.Xr exit 2 111to perform any necessary cleanup; passing a null function pointer for 112.Va exitf 113resets the hook to do nothing. 114.Sh EXAMPLES 115Display the current errno information string and exit: 116.Bd -literal -offset indent 117if ((p = malloc(size)) == NULL) 118 err(1, NULL); 119if ((fd = open(file_name, O_RDONLY, 0)) == -1) 120 err(1, "%s", file_name); 121.Ed 122.Pp 123Display an error message and exit: 124.Bd -literal -offset indent 125if (tm.tm_hour < START_TIME) 126 errx(1, "too early, wait until %s", start_time_string); 127.Ed 128.Pp 129Warn of an error: 130.Bd -literal -offset indent 131if ((fd = open(raw_device, O_RDONLY, 0)) == -1) 132 warnx("%s: %s: trying the block device", 133 raw_device, strerror(errno)); 134if ((fd = open(block_device, O_RDONLY, 0)) == -1) 135 err(1, "%s", block_device); 136.Ed 137.Sh SEE ALSO 138.Xr strerror 3 139.Sh HISTORY 140The 141.Fn err 142and 143.Fn warn 144functions first appeared in 4.4BSD. 145