explain_output(3)
hey bestie, welcome to the explain_output(3) page from the Library Functions Manual π it's giving "how do I make libexplain say stuff and maybe exit?" and honestly? iconic.
β¨ NAME β¨
explain_output β output error messages π£οΈπ¬
β¨ SYNOPSIS β¨
#include <libexplain/output.h>
β¨ DESCRIPTION β¨
These functions are your go-to for writing error messages, fr fr. π¬
explain_output_message π¬
void explain_output_message(const char *text);
The explain_output_message function is used to print text. It is printed via the registered output class, see explain_output_register(3) for how.
text β The text of the message to be printed. It has not been wrapped (yet).
explain_output_error π
void explain_output_error(const char *fmt, ...);
The explain_output_error function is used to print a formatted error message. The printing is done via the explain_output_message(3) function.
fmt β The format text of the message to be printed. See printf(3) for more information.
explain_output_error_and_die π
void explain_output_error_and_die(const char *fmt, ...);
The explain_output_error_and_die function is used to print text, and then terminate immediately. The printing is done via the explain_output_message(3) function, process termination is via the explain_output_exit_failure(3) function.
fmt β The format text of the message to be printed. See printf(3) for more information.
explain_output_warning β οΈ
void explain_output_warning(const char *fmt, ...);
The explain_output_warning function is used to print a formatted error message, including the word βwarningβ. The printing is done via the explain_output_message(3) function.
fmt β The format text of the message to be printed. See printf(3) for more information.
explain_output_exit πͺ
void explain_output_exit(int status);
The explain_output_exit function is used to terminate execution. It is executed via the registered output class, explain_output_register(3) for how.
status β The exist status requested. (yes, it says "exist", keep it cute, don't fix it π
)
explain_output_exit_failure π₯
void explain_output_exit_failure(void);
The explain_output_exit_failure function is used to terminate execution, with exit status EXIT_FAILURE. It is executed via the registered output class, see explain_output_register(3) for how.
explain_option_hanging_indent_set πͺ
void explain_option_hanging_indent_set(int columns);
The explain_option_hanging_indent_set function is used to cause the output wrapping to use hanging indents. By default no hanging indent is used, but this can sometimes obfuscate the end of one error message and the beginning of another. A hanging indent results in continuation lines starting with white space, similar to RFC822 headers.
This can be set using the βhangingβindent=nβ string in the EXPLAIN_OPTIONS environment variable. See explain(3) for more information.
Using this function will override any environment variable setting.
columns β The number of columns of hanging indent to be used. A value of 0 means no hanging indent (all lines flush with left margin). A common value to use is 4: it doesn't consume too much of each line, and it is a clear indent.
π OUTPUT REDIRECTION π
It is possible to change how and where libexplain sends its output, and even how it calls the exit(2) function. This functionality is used by the explain_*_or_die and explain_*_on_error functions.
By default, libexplain will wrap and print error messages on stderr, and call the exit(2) system call to terminate execution.
Clients of the libexplain library may choose to use some message handling facilities provided by libexplain, or they may choose to implement their own.
syslog π‘
To cause all output to be sent to syslog, use
explain_output_register(explain_output_syslog_new());
This is useful for servers and daemons.
stderr and syslog πͺ
The βteeβ output class can be used to duplicate output. To cause all output to be sent to both stderr and syslog, use
explain_output_register
(
explain_output_tee_new
(
explain_output_stderr_new(),
explain_output_syslog_new()
)
);
If you need more than two, use several instances of βteeβ, cascaded.
stderr and a file π
To cause all output to be sent to both stderr and a regular file, use
explain_output_register
(
explain_output_tee_new
(
explain_output_stderr_new(),
explain_output_file_new(filename, 0)
)
);
See the <libexplain/output.h> file for extensive documentation.
explain_output_new π§¬
explain_output_t *explain_output_new(const explain_output_vtable_t
*vtable);
The explain_output_new function may be used to create a new dynamically allocated instance of explain_output_t.
vtable β The struct containing the pointers to the methods of the derived class.
returns NULL on error (i.e. malloc failed), or a pointer to a new dynamically allocated instance of the class.
explain_output_stderr_new π₯οΈ
explain_output_t *explain_output_stderr_new(void);
The explain_output_stderr_new function may be used to create a new dynamically allocated instance of an explain_output_t class that writes to stderr, and exits via exit(2);
This is the default output handler.
returns NULL on error (i.e. malloc failed), or a pointer to a new dynamically allocated instance of the stderr class.
explain_output_syslog_new π‘
explain_output_t *explain_output_syslog_new(void);
The explain_output_syslog_new function may be used to create a new dynamically allocated instance of an explain_output_t class that writes to syslog, and exits via exit(2);
The following values are used:
option = 0
facility = LOG_USER
level = LOG_ERR
See syslog(3) for more information.
returns NULL on error (i.e. malloc(3) failed), or a pointer to a new dynamically allocated instance of the syslog class.
explain_output_syslog_new1 π‘
explain_output_t *explain_output_syslog_new1(int level);
The explain_output_syslog_new1 function may be used to create a new dynamically allocated instance of an explain_output_t class that writes to syslog, and exits via exit(2);
The following values are used:
option = 0
facility = LOG_USER
See syslog(3) for more information.
level β The syslog level to be used, see syslog(3) for a definition.
returns NULL on error (i.e. malloc(3) failed), or a pointer to a new dynamically allocated instance of the syslog class.
explain_output_syslog_new3 π‘
explain_output_t *explain_output_syslog_new3(int option, int facility,
int level);
The explain_output_syslog_new3 function may be used to create a new dynamically allocated instance of an explain_output_t class that writes to syslog, and exits via exit(2);
If you want different facilities or levels, create multiple instances.
option β The syslog option to be used, see syslog(3) for a definition.
facility β The syslog facility to be used, see syslog(3) for a definition.
level β The syslog level to be used, see syslog(3) for a definition.
returns NULL on error (i.e. malloc(3) failed), or a pointer to a new dynamically allocated instance of the syslog class.
explain_output_file_new π
explain_output_t *explain_output_file_new(const char *filename, int
append);
The explain_output_file_new function may be used to create a new dynamically allocated instance of an explain_output_t class that writes to a file, and exits via exit(2).
filename β The file to be opened and written to.
append β true (nonβzero) if messages are to be appended to the file, false (zero) if the file is to be replaced with new contents.
returns NULL on error (i.e. malloc(3) or open(2) failed), or a pointer to a new dynamically allocated instance of the syslog class.
explain_output_tee_new πͺ
explain_output_t *explain_output_tee_new(explain_output_t *first,
explain_output_t *second);
The explain_output_tee_new function may be used to create a new dynamically allocated instance of an explain_output_t class that writes to two other output classes.
first β The first output class to write to.
second β The second output class to write to.
returns NULL on error (i.e. malloc(3) failed), or a pointer to a new dynamically allocated instance of the syslog class.
The output subsystem will βownβ the first and second objects after this call. You may not make any reference to these pointers ever again. The output subsystem will destroy these objects and free the memory when it feels like it.
explain_output_register π
void explain_output_register(explain_output_t *op);
The explain_output_register function is used to change libexplain's default output handling facilities with something else. The NULL pointer restores libexplain's default processing.
If no output class is registered, the default is to wrap and print to stderr, and to exit via the exit(2) system call.
op β Pointer to the explain_output_t instance to be operated on.
The output subsystem will βownβ the pointer after this call. You may not make any reference to this pointer ever again. The output subsystem will destroy the object and free the memory when it feels like it.
π COPYRIGHT π
libexplain version 1.4 Copyright (C) 2010 Peter Miller
βοΈ AUTHOR βοΈ
Written by Peter Miller <pmiller@opensource.org.au>
okay bestie, that's the whole explain_output(3) page β libexplain version 1.4, Copyright (C) 2010 Peter Miller, and the manual page is explain_output(3). 2010 said periodt. bye π
π¦
π¦ where this page comes from
- debian bookworm: libexplain-dev 1.4.D001-12+b1 Β· LGPL-3.0-or-later
- debian trixie: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- ubuntu jammy: libexplain-dev 1.4.D001-12 Β· LGPL-3.0-or-later
- ubuntu noble: libexplain-dev 1.4.D001-13 Β· LGPL-3.0-or-later
- ubuntu resolute: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- Copyright (C) 2010, 2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms