1.\" $NetBSD: err.3,v 1.10 1999/03/22 19:44:40 garbled 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 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 eval" "const char *fmt" "..." 55.Ft void 56.Fn verr "int eval" "const char *fmt" "va_list args" 57.Ft void 58.Fn errx "int eval" "const char *fmt" "..." 59.Ft void 60.Fn verrx "int eval" "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 exit with the value of the argument 102.Fa eval . 103.Sh EXAMPLES 104Display the current errno information string and exit: 105.Bd -literal -offset indent 106if ((p = malloc(size)) == NULL) 107 err(1, NULL); 108if ((fd = open(file_name, O_RDONLY, 0)) == -1) 109 err(1, "%s", file_name); 110.Ed 111.Pp 112Display an error message and exit: 113.Bd -literal -offset indent 114if (tm.tm_hour < START_TIME) 115 errx(1, "too early, wait until %s", start_time_string); 116.Ed 117.Pp 118Warn of an error: 119.Bd -literal -offset indent 120if ((fd = open(raw_device, O_RDONLY, 0)) == -1) 121 warnx("%s: %s: trying the block device", 122 raw_device, strerror(errno)); 123if ((fd = open(block_device, O_RDONLY, 0)) == -1) 124 warn("%s", block_device); 125.Ed 126.Sh SEE ALSO 127.Xr strerror 3 128.Sh HISTORY 129The 130.Fn err 131and 132.Fn warn 133functions first appeared in 134.Bx 4.4 . 135