typedef void (*errf)(const char *, long, const char *, ...);
void
com_err(const char *whoami
, long code
, const char *format
, ...
)
void
com_err_va(const char *whoami
, long code
, const char *format
, ...
)
const
char
*
error_message(long code
)
const
char
*
error_table_name(int num
)
int
init_error_table(const char **msgs
, long base
, int count
)
errf
set_com_err_hook(errf func
)
errf
reset_com_err_hook()
void
add_to_error_table(struct et_list *new_table
)
The error table is registered with the
com_err
library by calling its initialisation function defined in its header
file. The initialisation function is generally defined as
initialize_),
where
name
is the name of the error table.
Any variable which is to contain an error code should be declared
whoami
, code
, format
, ...
)
whoami
string, which should specify the program name, followed by an error
message generated from
code
,
and a string produced using the
printf(3)
format
string and any following arguments. If
format
is NULL, the formatted message will not be
printed. The argument
format
may not be omitted.
whoami
, code
, format
, va_list args
)
),
which may be used by higher-level variadic functions (functions which
accept variable numbers of arguments).
code
)
code
.
If
code
is
associated
with
an
unknown
error
table,
or
if
code
is associated with a known error table but is not in the table, a
string of the form `Unknown code XXXX NN' is returned, where XXXX is
the error table name produced by reversing the compaction performed on
the error table number implied by that error code, and NN is the
offset from that base value.
Although this routine is available for use when needed, its use should
be left to circumstances which render
com_err()
unusable.
num
)
num
into an error table name.
msgs
, base
, count
)
msgs
of length
count
.
The error codes are assigned incrementally from
base
.
This function is useful for using the error-reporting mechanism with
custom error tables that have not been generated with
compile_et(1).
Although this routine is available for use when needed, its use should
be restricted.
func
)
func
to be dynamically substituted for
com_err(
).
After
set_com_err_hook(
)
has been called, calls to
com_err(
)
will turn into calls to the new hook routine. This function is
intended to be used in daemons to use a routine which calls
syslog(3),
or in a window system application to pop up a dialogue box.
)
).
new_table
)
new_table
to the internal error table.
#include "test_err.h"
void
hook(const char *whoami, long code,
const char *format, va_list args)
{
char buffer[BUFSIZ];
static int initialized = 0;
if (!initialized) {
openlog(whoami, LOG_NOWAIT, LOG_DAEMON);
initialized = 1;
}
vsprintf(buffer, format, args);
syslog(LOG_ERR, "%s %s", error_message(code), buffer);
}
int
main(int argc, char *argv[])
{
char *whoami = argv[0];
initialize_test_error_table();
com_err(whoami, TEST_INVAL, "before hook");
set_com_err_hook(hook);
com_err(whoami, TEST_IO, "after hook");
return (0);
}
#include