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