xref: /netbsd-src/lib/libc/gen/err.3 (revision cda4f8f6ee55684e8d311b86c99ea59191e6b74f)
1.\" Copyright (c) 1993 The Regents of the University of California.
2.\" 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	5.2 (Berkeley) 3/19/93
33.\"	$Id: err.3,v 1.2 1993/07/30 08:35:44 mycroft Exp $
34.\"
35.Dd "March 19, 1993"
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.Nd formatted error messages
48.Sh SYNOPSIS
49.Fd #include <err.h>
50.Ft void
51.Fn err "int eval" "const char *fmt" "..."
52.Ft void
53.Fn verr "int eval" "const char *fmt" "va_list args"
54.Ft void
55.Fn errx "int eval" "const char *fmt" "..."
56.Ft void
57.Fn verrx "int eval" "const char *fmt" "va_list args"
58.Ft void
59.Fn warn "const char *fmt" "..."
60.Ft void
61.Fn vwarn "const char *fmt" "va_list args"
62.Ft void
63.Fn warnx "const char *fmt" "..."
64.Ft void
65.Fn vwarnx "const char *fmt" "va_list args"
66.Sh DESCRIPTION
67The
68.Fn err
69and
70.Fn warn
71family of functions display a formatted error message on the standard
72error output.
73In all cases, the last component of the program name, a colon character,
74and a space are output.
75If the
76.Va fmt
77argument is not NULL, the formatted error message, a colon character,
78and a space are 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.
89In all cases, the output is followed by a newline character.
90.Pp
91The
92.Fn err ,
93.Fn verr ,
94.Fn errx ,
95and
96.Fn verrx
97functions do not return, but exit with the value of the argument
98.Fa eval .
99.Sh EXAMPLES
100Display the current errno information string and exit:
101.Bd -literal -offset indent
102if ((p = malloc(size)) == NULL)
103	err(1, NULL);
104if ((fd = open(file_name, O_RDONLY, 0)) == -1)
105	err(1, "%s", file_name);
106.Ed
107.Pp
108Display an error message and exit:
109.Bd -literal -offset indent
110if (tm.tm_hour < START_TIME)
111	errx(1, "too early, wait until %s", start_time_string);
112.Ed
113.Pp
114Warn of an error:
115.Bd -literal -offset indent
116if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
117	warnx("%s: %s: trying the block device",
118	    raw_device, strerror(errno));
119if ((fd = open(block_device, O_RDONLY, 0)) == -1)
120	err(1, "%s", block_device);
121.Ed
122.Sh SEE ALSO
123.Xr strerror 3
124.Sh HISTORY
125The
126.Fn err
127and
128.Fn warn
129functions are
130.Ud .
131