| 1 |
'\" t |
| 2 |
.\" Copyright 1993, The Regents of the University of California. |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: BSD-4-Clause-UC |
| 6 |
.\" |
| 7 |
.TH err 3 2025-05-17 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
err, verr, errx, verrx, warn, vwarn, warnx, vwarnx \- formatted error messages |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <err.h> |
| 16 |
.P |
| 17 |
.BI "[[noreturn]] void err(int " eval ", const char *" fmt ", ...);" |
| 18 |
.BI "[[noreturn]] void errx(int " eval ", const char *" fmt ", ...);" |
| 19 |
.P |
| 20 |
.BI "void warn(const char *" fmt ", ...);" |
| 21 |
.BI "void warnx(const char *" fmt ", ...);" |
| 22 |
.P |
| 23 |
.B #include <stdarg.h> |
| 24 |
.P |
| 25 |
.BI "[[noreturn]] void verr(int " eval ", const char *" fmt ", va_list " args ); |
| 26 |
.BI "[[noreturn]] void verrx(int " eval ", const char *" fmt ", va_list " args ); |
| 27 |
.P |
| 28 |
.BI "void vwarn(const char *" fmt ", va_list " args ); |
| 29 |
.BI "void vwarnx(const char *" fmt ", va_list " args ); |
| 30 |
.fi |
| 31 |
.SH DESCRIPTION |
| 32 |
The |
| 33 |
.BR err () |
| 34 |
and |
| 35 |
.BR warn () |
| 36 |
family of functions display a formatted error message on the standard |
| 37 |
error output. |
| 38 |
In all cases, the last component of the program name, a colon character, |
| 39 |
and a space are output. |
| 40 |
If the |
| 41 |
.I fmt |
| 42 |
argument is not NULL, the |
| 43 |
.BR printf (3)-like |
| 44 |
formatted error message is output. |
| 45 |
The output is terminated by a newline character. |
| 46 |
.P |
| 47 |
The |
| 48 |
.BR err (), |
| 49 |
.BR verr (), |
| 50 |
.BR warn (), |
| 51 |
and |
| 52 |
.BR vwarn () |
| 53 |
functions append an error message obtained from |
| 54 |
.BR strerror (3) |
| 55 |
based on the global variable |
| 56 |
.IR errno , |
| 57 |
preceded by another colon and space unless the |
| 58 |
.I fmt |
| 59 |
argument is |
| 60 |
NULL. |
| 61 |
.P |
| 62 |
The |
| 63 |
.BR errx () |
| 64 |
and |
| 65 |
.BR warnx () |
| 66 |
functions do not append an error message. |
| 67 |
.P |
| 68 |
The |
| 69 |
.BR err (), |
| 70 |
.BR verr (), |
| 71 |
.BR errx (), |
| 72 |
and |
| 73 |
.BR verrx () |
| 74 |
functions do not return, but exit with the value of the argument |
| 75 |
.IR eval . |
| 76 |
.SH ATTRIBUTES |
| 77 |
For an explanation of the terms used in this section, see |
| 78 |
.BR attributes (7). |
| 79 |
.TS |
| 80 |
allbox; |
| 81 |
lbx lb lb |
| 82 |
l l l. |
| 83 |
Interface Attribute Value |
| 84 |
T{ |
| 85 |
.na |
| 86 |
.nh |
| 87 |
.BR err (), |
| 88 |
.BR errx (), |
| 89 |
.BR warn (), |
| 90 |
.BR warnx (), |
| 91 |
.BR verr (), |
| 92 |
.BR verrx (), |
| 93 |
.BR vwarn (), |
| 94 |
.BR vwarnx () |
| 95 |
T} Thread safety MT-Safe locale |
| 96 |
.TE |
| 97 |
.SH STANDARDS |
| 98 |
BSD. |
| 99 |
.SH HISTORY |
| 100 |
.TP |
| 101 |
.BR err () |
| 102 |
.TQ |
| 103 |
.BR warn () |
| 104 |
4.4BSD. |
| 105 |
.SH EXAMPLES |
| 106 |
Display the current |
| 107 |
.I errno |
| 108 |
information string and exit: |
| 109 |
.P |
| 110 |
.in +4n |
| 111 |
.EX |
| 112 |
p = malloc(size); |
| 113 |
if (p == NULL) |
| 114 |
err(EXIT_FAILURE, NULL); |
| 115 |
fd = open(file_name, O_RDONLY, 0); |
| 116 |
if (fd == \-1) |
| 117 |
err(EXIT_FAILURE, "%s", file_name); |
| 118 |
.EE |
| 119 |
.in |
| 120 |
.P |
| 121 |
Display an error message and exit: |
| 122 |
.P |
| 123 |
.in +4n |
| 124 |
.EX |
| 125 |
if (tm.tm_hour < START_TIME) |
| 126 |
errx(EXIT_FAILURE, "too early, wait until %s", |
| 127 |
start_time_string); |
| 128 |
.EE |
| 129 |
.in |
| 130 |
.P |
| 131 |
Warn of an error: |
| 132 |
.P |
| 133 |
.in +4n |
| 134 |
.EX |
| 135 |
fd = open(raw_device, O_RDONLY, 0); |
| 136 |
if (fd == \-1) |
| 137 |
warnx("%s: %s: trying the block device", |
| 138 |
raw_device, strerror(errno)); |
| 139 |
fd = open(block_device, O_RDONLY, 0); |
| 140 |
if (fd == \-1) |
| 141 |
err(EXIT_FAILURE, "%s", block_device); |
| 142 |
.EE |
| 143 |
.in |
| 144 |
.SH SEE ALSO |
| 145 |
.BR error (3), |
| 146 |
.BR exit (3), |
| 147 |
.BR perror (3), |
| 148 |
.BR printf (3), |
| 149 |
.BR strerror (3) |