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