Commit | Line | Data |
---|---|---|
2868012a KB |
1 | .\" Copyright (c) 1993 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" %sccs.include.redist.roff% | |
5 | .\" | |
5d4306e6 | 6 | .\" @(#)err.3 5.2 (Berkeley) %G% |
2868012a KB |
7 | .\" |
8 | .Dd "" | |
9 | .Dt ERR 3 | |
10 | .Os BSD 4 | |
11 | .Sh NAME | |
12 | .Nm err , | |
13 | .Nm verr , | |
14 | .Nm errx , | |
15 | .Nm verrx , | |
16 | .Nm warn , | |
17 | .Nm vwarn , | |
18 | .Nm warnx , | |
19 | .Nm vwarnx | |
20 | .Nd formatted error messages | |
21 | .Sh SYNOPSIS | |
22 | .Fd #include <err.h> | |
23 | .Ft void | |
24 | .Fn err "int eval" "const char *fmt" "..." | |
25 | .Ft void | |
26 | .Fn verr "int eval" "const char *fmt" "va_list args" | |
27 | .Ft void | |
28 | .Fn errx "int eval" "const char *fmt" "..." | |
29 | .Ft void | |
30 | .Fn verrx "int eval" "const char *fmt" "va_list args" | |
31 | .Ft void | |
32 | .Fn warn "const char *fmt" "..." | |
33 | .Ft void | |
34 | .Fn vwarn "const char *fmt" "va_list args" | |
35 | .Ft void | |
36 | .Fn warnx "const char *fmt" "..." | |
37 | .Ft void | |
38 | .Fn vwarnx "const char *fmt" "va_list args" | |
39 | .Sh DESCRIPTION | |
40 | The | |
41 | .Fn err | |
42 | and | |
43 | .Fn warn | |
44 | family of functions display a formatted error message on the standard | |
45 | error output. | |
5d4306e6 KB |
46 | In all cases, the last component of the program name, a colon character, |
47 | and a space are output. | |
48 | If the | |
49 | .Va fmt | |
50 | argument is not NULL, the formatted error message, a colon character, | |
51 | and a space are output. | |
2868012a KB |
52 | In the case of the |
53 | .Fn err , | |
54 | .Fn verr , | |
55 | .Fn warn , | |
56 | and | |
57 | .Fn vwarn | |
5d4306e6 KB |
58 | functions, the error message string affiliated with the current value of |
59 | the global variable | |
2868012a | 60 | .Va errno |
5d4306e6 KB |
61 | is output. |
62 | In all cases, the output is followed by a newline character. | |
2868012a KB |
63 | .Pp |
64 | The | |
65 | .Fn err , | |
66 | .Fn verr , | |
67 | .Fn errx , | |
68 | and | |
69 | .Fn verrx | |
70 | functions do not return, but exit with the value of the argument | |
71 | .Fa eval . | |
72 | .Sh EXAMPLES | |
73 | Display the current errno information string and exit: | |
74 | .Bd -literal -offset indent | |
5d4306e6 KB |
75 | if ((p = malloc(size)) == NULL) |
76 | err(1, NULL); | |
2868012a KB |
77 | if ((fd = open(file_name, O_RDONLY, 0)) == -1) |
78 | err(1, "%s", file_name); | |
79 | .Ed | |
80 | .Pp | |
81 | Display an error message and exit: | |
82 | .Bd -literal -offset indent | |
83 | if (tm.tm_hour < START_TIME) | |
84 | errx(1, "too early, wait until %s", start_time_string); | |
85 | .Ed | |
86 | .Pp | |
87 | Warn of an error: | |
88 | .Bd -literal -offset indent | |
89 | if ((fd = open(raw_device, O_RDONLY, 0)) == -1) | |
90 | warnx("%s: %s: trying the block device", | |
91 | raw_device, strerror(errno)); | |
92 | if ((fd = open(block_device, O_RDONLY, 0)) == -1) | |
93 | err(1, "%s", block_device); | |
94 | .Ed | |
95 | .Sh SEE ALSO | |
96 | .Xr strerror 3 | |
97 | .Sh HISTORY | |
98 | The | |
99 | .Fn err | |
100 | and | |
101 | .Fn warn | |
102 | functions are | |
103 | .Ud . |