1ERR(3)                   BSD Library Functions Manual                   ERR(3)
2

NAME

4     err, verr, errx, verrx, warn, vwarn, warnx, vwarnx, — formatted error
5     messages
6

SYNOPSIS

8     #include <err.h>
9
10     void
11     err(int eval, const char *fmt, ...);
12
13     void
14     errx(int eval, const char *fmt, ...);
15
16     void
17     warn(const char *fmt, ...);
18
19     void
20     warnx(const char *fmt, ...);
21
22     #include <stdarg.h>
23
24     void
25     verr(int eval, const char *fmt, va_list args);
26
27     void
28     verrx(int eval, const char *fmt, va_list args);
29
30     void
31     vwarn(const char *fmt, va_list args);
32
33     void
34     vwarnx(const char *fmt, va_list args);
35

DESCRIPTION

37     The err() and warn() family of functions display a formatted error mes‐
38     sage on the standard error output.  In all cases, the last component of
39     the program name, a colon character, and a space are output.  If the fmt
40     argument is not NULL, the printf(3) -like formatted error message is out‐
41     put.  The output is terminated by a newline character.
42
43     The err(), verr(), warn(), and vwarn() functions append an error message
44     obtained from strerror(3) based on a code or the global variable errno,
45     preceded by another colon and space unless the fmt argument is NULL.
46
47     The err(), verr(), warn(), and vwarn() functions use the global variable
48     errno to look up the error message.
49
50     The errx() and warnx() functions do not append an error message.
51
52     The err(), verr(), errx(), and verrx() functions do not return, but exit
53     with the value of the argument eval.
54

EXAMPLES

56     Display the current errno information string and exit:
57
58           if ((p = malloc(size)) == NULL)
59                   err(1, NULL);
60           if ((fd = open(file_name, O_RDONLY, 0)) == -1)
61                   err(1, "%s", file_name);
62
63     Display an error message and exit:
64
65           if (tm.tm_hour < START_TIME)
66                   errx(1, "too early, wait until %s", start_time_string);
67
68     Warn of an error:
69
70           if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
71                   warnx("%s: %s: trying the block device",
72                       raw_device, strerror(errno));
73           if ((fd = open(block_device, O_RDONLY, 0)) == -1)
74                   err(1, "%s", block_device);
75

SEE ALSO

77     error(3), exit(3), printf(3), perror(3), strerror(3)
78

CONFORMING TO

80     These functions are non-standard BSD extensions.
81

HISTORY

83     The err() and warn() functions first appeared in 4.4BSD.
84
85BSD                              March 6, 1999                             BSD
Impressum