COM_ERR(3)COM_ERR(3)NAMEcom_err - common error display routine
SYNOPSIS
#include <com_err.h>
void initialize_XXXX_error_table(void);
void com_err(const char *whoami, long code,
const char *format, ...);
const char *error_message(long code);
const char *error_message_r(long code, char *buf);
typedef void(*error_handler_t)(const char *whoami,
long code, const char *format, va_list args);
error_handler_t set_com_err_hook(error_handler_t proc);
error_handler_t reset_com_err_hook(void);
DESCRIPTION
Com_err displays an error message on the standard error stream stderr
(see stdio(3S)) composed of the whoami string, which should specify the
program name or some subportion of a program, followed by an error mes‐
sage generated from the code value (derived from compile_et(1)), and a
string produced using the format string and any following arguments, in
the same style as fprintf(3).
The behavior of com_err can be modified using set_com_err_hook; this
defines a procedure which is called with the arguments passed to
com_err, instead of the default internal procedure which sends the for‐
matted text to error output. Thus the error messages from a program
can all easily be diverted to another form of diagnostic logging, such
as syslog(3). Reset_com_err_hook may be used to restore the behavior
of com_err to its default form. Both procedures return the previous
``hook'' value. These ``hook'' procedures must have the declaration
given for proc above in the synopsis.
The initialize_XXXX_error_table routine is generated mechanically by
compile_et(1) from a source file containing names and associated
strings. Each table has a name of up to four characters, which is used
in place of the XXXX in the name of the routine. These routines should
be called before any of the corresponding error codes are used, so that
the com_err library will recognize error codes from these tables when
they are used.
The functions error_message and error_message_r return the error mes‐
sage for an error code. error_message may return its error message
inside a static buffer, and therefore is not reentrant; error_message_r
will in these cases use the storage provided in buf, which should be at
least COM_ERR_BUF_LEN bytes long.
The com_err.h header file should be included in any source file that
uses routines from the com_err library; executable files must be linked
using ``-lcom_err'' in order to cause the com_err library to be
included.
Multithreaded programs must perform all of the initial‐
ize_XXXX_error_table calls serially, but may perform them in parallel
with com_err, error_message, and error_mesesage_r calls as long as the
call to initialize_XXX_error_table for a given table has completed
before any corresponding error codes are used. Calls to
set_com_err_hook and reset_com_err_hook must also be performed serially
or they may return the wrong old hook value.
SEE ALSO
compile_et (1), syslog (3).
Ken Raeburn, "A Common Error Description Library for UNIX".
SIPB 22 Nov 1988 COM_ERR(3)