xref: /netbsd-src/lib/libc/gen/err.3 (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1.\"	$NetBSD: err.3,v 1.8 1997/09/29 05:33:03 enami 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.Fa fmt
78argument is not NULL, the formatted error message is output.
79In the case of the
80.Fn err ,
81.Fn verr ,
82.Fn warn ,
83and
84.Fn vwarn
85functions, the error message string affiliated with the current value of
86the global variable
87.Va errno
88is output next, preceded by a colon character and a space if
89.Fa fmt
90is not NULL.
91In all cases, the output is followed by a newline character.
92.Pp
93The
94.Fn err ,
95.Fn verr ,
96.Fn errx ,
97and
98.Fn verrx
99functions do not return, but exit with the value of the argument
100.Fa eval .
101.Sh EXAMPLES
102Display the current errno information string and exit:
103.Bd -literal -offset indent
104if ((p = malloc(size)) == NULL)
105	err(1, NULL);
106if ((fd = open(file_name, O_RDONLY, 0)) == -1)
107	err(1, "%s", file_name);
108.Ed
109.Pp
110Display an error message and exit:
111.Bd -literal -offset indent
112if (tm.tm_hour < START_TIME)
113	errx(1, "too early, wait until %s", start_time_string);
114.Ed
115.Pp
116Warn of an error:
117.Bd -literal -offset indent
118if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
119	warnx("%s: %s: trying the block device",
120	    raw_device, strerror(errno));
121if ((fd = open(block_device, O_RDONLY, 0)) == -1)
122	warn("%s", block_device);
123.Ed
124.Sh SEE ALSO
125.Xr strerror 3
126.Sh HISTORY
127The
128.Fn err
129and
130.Fn warn
131functions first appeared in
132.Bx 4.4 .
133