err —
format an error message
#include
<errno.h>
extern int errno;
#define EPERM 1
#define ENOENT 2
#define ESRCH 3
#define EINTR 4
#include
<err.h>
void
err(
int
eval,
const char *fmt,
...);
If the variable
errno has the value
ENOENT, the function
err() prints the message “No such
file or directory”.
Note that some of the macros differ between SYNOPSIS and DESCRIPTION:
- When citing the type of a global variable, even when followed by the name,
use
Vt. When citing the name only, use
Va.
- When citing a complete preprocessor definition line in the SYNOPSIS, use
Fd. When mentioning the defined
constant only, use Dv, or
Er if it's an error number.
- The name of a function with multiple arguments appears behind
Fo in the SYNOPSIS. When mentioning the
function name again in isolation, use
Fn.
The error message itself sets a minor trap: It needs to be quoted, either by
prepending a zero-width space (‘\&’), or by enclosing it in
double quotes. Otherwise, the word ‘No’ is misinterpreted as the
macro
No and hence lost from the
output.