COM_ERR(3)
π COM_ERR β the common error display routine π
okay bestie, sit down, hydrate, and let me tell you about com_err from section 3 of the library functions manual. this is the girl who prints your error messages. she's been doing it since 1988 and she has never once missed. β¨
πΈ SYNOPSIS πΈ
#include <et/com_err.h>
void (*proc) (const char *, long, const char *, va_list);
void com_err (const char *whoami, long code, const char *format, ...);
proc = set_com_err_hook (proc);
proc = reset_com_err_hook ();
void initialize_XXXX_error_table ();
π DESCRIPTION π
So. What does com_err actually do? She displays an error message on the standard error stream stderr β and yes, that's the one from stdio(3S), iykyk. The message she cooks up is literally a three-course meal:
- the
whoamistring β that's the program name, or some subportion of the program, whatever you're calling yourself today π - an error message generated from the
codevalue β and that code comes straight fromcompile_et(1), no cap - a string produced using the
formatstring plus any following arguments, in the exact same style asfprintf(3)
she's giving printf but make it an error. iconic.
β¨ changing her whole vibe: hooks β¨
The behavior of com_err can be modified using set_com_err_hook. What this does is define a procedure that gets called with the arguments passed to com_err β instead of the default internal procedure, the one that just sends the formatted text to error output. So basically you can reroute all your error messages to another form of diagnostic logging, like syslog(3), and honestly? slay.
reset_com_err_hook is the undo button β it restores the behavior of com_err back to its default form. π«Ά
Both of these procedures return the previous "hook" value, so you can stack them like the little diva they are. And heads up: these "hook" procedures must have the declaration given for proc up in the synopsis. no freestyling, bestie, the compiler will know.
π¦ the initialize_XXXX_error_table routine π¦
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, and that name gets used in place of the XXXX in the name of the routine. π
β οΈ You should call these routines before any of the corresponding error codes are used β otherwise the com_err library won't recognize error codes from these tables when they show up. don't do it late, it's not cute.
π the include + link situation π
The com_err.h header file should be included in any source file that uses routines from the com_err library. And your executable files? They must be linked using -lcom_err in order to cause the com_err library to be included. like, mandatory. periodt.
-lcom_err
π SEE ALSO π
compile_et (1)β the girl who generates your error tablessyslog (3)β the other place your errors can go live
Also, shoutout to Ken Raeburn, author of "A Common Error Description Library for UNIX" β the blueprint, the blueprint. π
com_err, from section 3 of the library functions manual, brought to you by SIPB, dated 22 Nov 1988. yes she's old enough to be your mom and she still ate. π β¨π«Ά
π¦ where this page comes from
- alpine 3.22: e2fsprogs-doc 1.47.2-r2 Β· GPL-2.0-or-later AND LGPL-2.0-or-later AND BSD-3-Clause AND MIT
- alpine 3.23: e2fsprogs-doc 1.47.3-r0 Β· GPL-2.0-or-later AND LGPL-2.0-or-later AND BSD-3-Clause AND MIT
- alpine 3.24: e2fsprogs-doc 1.47.4-r0 Β· GPL-2.0-or-later AND LGPL-2.0-or-later AND BSD-3-Clause AND MIT
- arch rolling: e2fsprogs 1.47.4-1 Β· GPL AND LGPL AND MIT
- centos-stream 10: libcom_err-devel 1.47.1-5.el10 Β· MIT
- centos-stream 9: libcom_err-devel 1.46.5-8.el9 Β· MIT
- centos-stream 9: libcom_err-devel 1.46.5-8.el9 Β· MIT
- debian bookworm: comerr-dev 2.1-1.47.0-2+b2 Β· GPL-2.0-only
- debian trixie: comerr-dev 2.1-1.47.2-3+b12 Β· GPL-2.0-only
- fedora 43: libcom_err-devel 1.47.3-2.fc43 Β· MIT
- fedora 43: libcom_err-devel 1.47.3-2.fc43 Β· MIT
- fedora 44: libcom_err-devel 1.47.3-4.fc44 Β· MIT
- fedora 44: libcom_err-devel 1.47.3-4.fc44 Β· MIT
- nixpkgs unstable: e2fsprogs 1.47.4
- opensuse-leap 16.0: libcom_err-devel 1.47.0-160000.3.2 Β· MIT
- opensuse-leap 16.0: libcom_err-devel 1.47.0-160000.3.2 Β· MIT
- opensuse-leap 16.0: libcom_err-devel 1.47.0-160000.3.2 Β· MIT
- opensuse-leap 16.0: libcom_err-devel 1.47.0-160000.3.2 Β· MIT
- ubuntu jammy: comerr-dev 2.1-1.46.5-2ubuntu1
- ubuntu jammy: comerr-dev 2.1-1.46.5-2ubuntu1.1
- ubuntu jammy: comerr-dev 2.1-1.46.5-2ubuntu1.2
- ubuntu noble: comerr-dev 2.1-1.47.0-2.4~exp1ubuntu4 Β· GPL-2.0-only
- ubuntu noble: comerr-dev 2.1-1.47.0-2.4~exp1ubuntu4.1 Β· GPL-2.0-only
- ubuntu questing: comerr-dev 2.1-1.47.2-3ubuntu2
- ubuntu resolute: comerr-dev 2.1-1.47.2-3ubuntu4 Β· GPL-2.0-only
- ubuntu stonking: comerr-dev 2.1-1.47.4-1 Β· GPL-2.0-only
- Copyright (c) 1988 Massachusetts Institute of Technology
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms