1ERR(3) Linux Programmer's Manual ERR(3)
2
3
4
6 err, verr, errx, verrx, warn, vwarn, warnx, vwarnx - formatted error
7 messages
8
10 #include <err.h>
11
12 noreturn void err(int eval, const char *fmt, ...);
13 noreturn void errx(int eval, const char *fmt, ...);
14
15 void warn(const char *fmt, ...);
16 void warnx(const char *fmt, ...);
17
18 #include <stdarg.h>
19
20 noreturn void verr(int eval, const char *fmt, va_list args);
21 noreturn void verrx(int eval, const char *fmt, va_list args);
22
23 void vwarn(const char *fmt, va_list args);
24 void vwarnx(const char *fmt, va_list args);
25
27 The err() and warn() family of functions display a formatted error mes‐
28 sage on the standard error output. In all cases, the last component of
29 the program name, a colon character, and a space are output. If the
30 fmt argument is not NULL, the printf(3)-like formatted error message is
31 output. The output is terminated by a newline character.
32
33 The err(), verr(), warn(), and vwarn() functions append an error mes‐
34 sage obtained from strerror(3) based on the global variable errno, pre‐
35 ceded by another colon and space unless the fmt argument is NULL.
36
37 The errx() and warnx() functions do not append an error message.
38
39 The err(), verr(), errx(), and verrx() functions do not return, but
40 exit with the value of the argument eval.
41
43 For an explanation of the terms used in this section, see at‐
44 tributes(7).
45
46 ┌─────────────────────────────────────┬───────────────┬────────────────┐
47 │Interface │ Attribute │ Value │
48 ├─────────────────────────────────────┼───────────────┼────────────────┤
49 │err(), errx(), warn(), warnx(), │ Thread safety │ MT-Safe locale │
50 │verr(), verrx(), vwarn(), vwarnx() │ │ │
51 └─────────────────────────────────────┴───────────────┴────────────────┘
52
54 These functions are nonstandard BSD extensions.
55
57 Display the current errno information string and exit:
58
59 p = malloc(size);
60 if (p == NULL)
61 err(EXIT_FAILURE, NULL);
62 fd = open(file_name, O_RDONLY, 0);
63 if (fd == -1)
64 err(EXIT_FAILURE, "%s", file_name);
65
66 Display an error message and exit:
67
68 if (tm.tm_hour < START_TIME)
69 errx(EXIT_FAILURE, "too early, wait until %s",
70 start_time_string);
71
72 Warn of an error:
73
74 fd = open(raw_device, O_RDONLY, 0);
75 if (fd == -1)
76 warnx("%s: %s: trying the block device",
77 raw_device, strerror(errno));
78 fd = open(block_device, O_RDONLY, 0);
79 if (fd == -1)
80 err(EXIT_FAILURE, "%s", block_device);
81
83 error(3), exit(3), perror(3), printf(3), strerror(3)
84
86 This page is part of release 5.13 of the Linux man-pages project. A
87 description of the project, information about reporting bugs, and the
88 latest version of this page, can be found at
89 https://www.kernel.org/doc/man-pages/.
90
91
92
93Linux 2021-03-22 ERR(3)