Here we present the reporting and logging functions referred to in the text of the book on several occasions, especially in Chapter 11. This particular example is POSIX 1 compliant.
All functions comply with the same syntax and semantics for arguments as the printf() function (i.e., variable number of standard arguments). Functions named in all lowercase (sys_exit(), sys__exit(), msg(), msg_exit(), msg__exit(), and msg()) write their messages to the standard output (i.e., to the screen of the terminal under normal circumstances), whereas functions whose names begin with an uppercase letter (Sys_exit(), Sys__exit(), Sys(), Msg_exit(), Msg__exit(), and Msg()) write into a single log file.
The functions sys(), msg(), Sys(), and Msg() save on entry the current signal mask, block all signals, and than write the message - hence they cannot be “interrupted”. On return, they reinstate the original signal mask.
The functions sys_exit(), sys__exit(), msg_exit(), msg__exit(), Sys_exit(), Sys__exit(), Msg_exit(), and Msg__exit() block all signals on entry. They do not save the original signal mask because they do not return; these functions exit using the system call exit(1) (functions sys_exit(), msg_exit(), Sys_exit(), and Msg_exit()) or _exit(1) (functions sys__exit(), msg__exit(), Sys__exit(), and Msg__exit()).
Functions msg_exit(), msg__exit(), msg(), Msg_exit(), Msg__exit(), and Msg() just write the requested message and either return (msg() and Msg()) or exit using exit(1) (msg_exit() and Msg_exit()) or _exit(1) (msg__exit() and Msg__exit()).
Functions sys_exit(), sys__exit(), sys(), Sys_exit(), Sys__exit(), and Sys() write a more elaborate system error message (together with the requested message) describing the error that happened based on errno.