COM_ERR(3)

πŸ“¦
version 2.1-1.47.4 Β· 3 versions
  • 2.1-1.47.4 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 14.5 Β· freebsd 14.5
  • 15.1 Β· freebsd 15.1
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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:

  1. the whoami string β€” that's the program name, or some subportion of the program, whatever you're calling yourself today πŸ’…
  2. an error message generated from the code value β€” and that code comes straight from compile_et(1), no cap
  3. a string produced using the format string plus any following arguments, in the exact same style as fprintf(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 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 tables
  • syslog (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