1.\" $NetBSD: err.3,v 1.5 1995/02/25 13:40:57 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 "June 9, 1993" 37.Dt ERR 3 38.Os BSD 4 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 SYNOPSIS 50.Fd #include <err.h> 51.Ft void 52.Fn err "int eval" "const char *fmt" "..." 53.Ft void 54.Fn verr "int eval" "const char *fmt" "va_list args" 55.Ft void 56.Fn errx "int eval" "const char *fmt" "..." 57.Ft void 58.Fn verrx "int eval" "const char *fmt" "va_list args" 59.Ft void 60.Fn warn "const char *fmt" "..." 61.Ft void 62.Fn vwarn "const char *fmt" "va_list args" 63.Ft void 64.Fn warnx "const char *fmt" "..." 65.Ft void 66.Fn vwarnx "const char *fmt" "va_list args" 67.Sh DESCRIPTION 68The 69.Fn err 70and 71.Fn warn 72family of functions display a formatted error message on the standard 73error output. 74In all cases, the last component of the program name, a colon character, 75and a space are output. 76If the 77.Va fmt 78argument is not NULL, the formatted error message, a colon character, 79and a space are output. 80In the case of the 81.Fn err , 82.Fn verr , 83.Fn warn , 84and 85.Fn vwarn 86functions, the error message string affiliated with the current value of 87the global variable 88.Va errno 89is output. 90In all cases, the output is followed by a newline character. 91.Pp 92The 93.Fn err , 94.Fn verr , 95.Fn errx , 96and 97.Fn verrx 98functions do not return, but exit with the value of the argument 99.Fa eval . 100.Sh EXAMPLES 101Display the current errno information string and exit: 102.Bd -literal -offset indent 103if ((p = malloc(size)) == NULL) 104 err(1, NULL); 105if ((fd = open(file_name, O_RDONLY, 0)) == -1) 106 err(1, "%s", file_name); 107.Ed 108.Pp 109Display an error message and exit: 110.Bd -literal -offset indent 111if (tm.tm_hour < START_TIME) 112 errx(1, "too early, wait until %s", start_time_string); 113.Ed 114.Pp 115Warn of an error: 116.Bd -literal -offset indent 117if ((fd = open(raw_device, O_RDONLY, 0)) == -1) 118 warnx("%s: %s: trying the block device", 119 raw_device, strerror(errno)); 120if ((fd = open(block_device, O_RDONLY, 0)) == -1) 121 err(1, "%s", block_device); 122.Ed 123.Sh SEE ALSO 124.Xr strerror 3 125.Sh HISTORY 126The 127.Fn err 128and 129.Fn warn 130functions first appeared in 131.Bx 4.4 . 132