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