---
name: "com_err"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/com_err"
---

# com\_err(3)

common error display routine

## NAME

com\_err - common error display routine

## SYNOPSIS

```
 #include "com_err.h"
```

void com\_err (whoami, code, format, ...);\
 	const char \*whoami;\
 	long code;\
 	const char \*format;

proc = set\_com\_err\_hook (proc); void (\* *proc* ) (const char \*, long, const char \*, va\_list);

```

```

proc = reset\_com\_err\_hook ();

void initialize\_XXXX\_error\_table ();

## 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 message generated from the *code* value (derived from [*compile\_et*(1)](/compile_et/1.md)), and a string produced using the *format* string and any following arguments, in the same style as [*fprintf*(3)](/fprintf/3.md).

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 formatted 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)](/syslog/3.md). *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)](/compile_et/1.md) 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 **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.

## SEE ALSO

compile\_et (1), syslog (3).

Ken Raeburn, "A Common Error Description Library for UNIX".
