/usr/include/libexplain/output.h is in libexplain-dev 1.4.D001-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | /*
* libexplain - Explain errno values returned by libc functions
* Copyright (C) 2010-2013 Peter Miller
* Written by Peter Miller <pmiller@opensource.org.au>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBEXPLAIN_OUTPUT_H
#define LIBEXPLAIN_OUTPUT_H
#include <libexplain/gcc_attributes.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file
* @brief 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.
*
* @section syslog syslog
* To cause all output to be sent to syslog, use
* @code
* explain_output_register(explain_output_syslog_new());
* @endcode
*
* @section stderr "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
* @code
* explain_output_register
* (
* explain_output_tee_new
* (
* explain_output_stderr_new(),
* explain_output_syslog_new()
* )
* );
* @endcode
* If you need more than two, use several instances of "tee", cascaded.
*
* @section file "stderr and a file"
* To cause all output to be sent to both stderr and a regular file, use
* @code
* explain_output_register
* (
* explain_output_tee_new
* (
* explain_output_stderr_new(),
* explain_output_file_new(filename, 0)
* )
* );
* @endcode
*
* @section cxx C++
* It would be possible to create an error handler that accumulated
* a string when its message method was called, and threw an
* exception when its "exit" method was called. This is why
* "message" and "exit" are tied together in this way.
*
* FIXME: write such a thing, and include it in the library
*/
/**
* The explain_output_t type is a synonym for struct explain_output_t.
*/
typedef struct explain_output_t explain_output_t;
/**
* The explain_output_t struct is used to remember state for the
* classes that control libexplain's output and exit methods.
*
* Derived classes may choose to add additonal instance variables.
*/
struct explain_output_t
{
/**
* The vtable instance variable is used to remember the location
* if this instance's class's method pointers.
*/
const struct explain_output_vtable_t *vtable;
/**
* POSIX and the C standard both say that it should not call
* 'exit', because the behavior is undefined if 'exit' is called
* more than once. So we call '_exit' instead of 'exit'.
*
* This important if a libexplain funcion is called by an atexit
* hander, where exit has been called by libexplain.
*/
int exit_has_been_used;
};
/**
* The explain_output_vtable_t type is a synonym for struct
* explain_output_vtable_t.
*/
typedef struct explain_output_vtable_t explain_output_vtable_t;
/**
* The explain_output_vtable_t struct describes the methods of a
* class derived from the explain_output_t pure abstract class.
*/
struct explain_output_vtable_t
{
/**
* The destructor method is called when (if) the output instance is
* destroyed. May be NULL, if no cleanup is required.
*
* @param op
* Pointer to the explain_output_t instance to be operated on.
*/
void (*destructor)(explain_output_t *op);
/**
* The message method is ised to print text. Different
* output "classes" handle this differently.
*
* @param op
* Pointer to the explain_output_t instance to be "printed" on.
* @param text
* The text of the message to be printed.
* It has not been wrapped.
*/
void (*message)(explain_output_t *op, const char *text);
/**
* The exit method is used to terminate execution. Different
* "classes" handle this differently.
* May be NULL, in which case exit(status) will be called.
*
* @param op
* Pointer to the explain_output_t instance to be operated on.
* @param status
* The exist status requested.
*
* @note
* The "exit" method shall not return. if it does, exit(status)
* will be called anyway. This is because the rest of the
* libexplain code assumes that "exit" means "::exit".
*/
void (*exit)(explain_output_t *op, int status);
/**
* The size instance variable is used to remember how large
* this instance is, in bytes. Used by the #explain_output_new
* function, below.
*/
unsigned int size;
};
/**
* The explain_output_new function may be used to create a new
* dynamically allocated instance of explain_output_t.
*
* @param 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_t *explain_output_new(const explain_output_vtable_t *vtable);
/**
* 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.
*
* Long error messages will be wrapped to fit the size of the current
* terminal line.
*
* You can select whether or not the second and subsequent lines of wrapped
* error messages are indented.
* <ul>
* <li> calling the #explain_option_hanging_indent_set function at the
* beginning of main(); or,
* <li> setting the EXPLAIN_OPTIONS environment variable, setting the
* "hanging-indent=N" option; or,
* <li> the default is not to indent the second and subsequent lines of
* wrapped error messages.
* </ul>
* The above list is in order of highest precedence to lowest.
* A hanging indent of zero means "no indent".
*
* @returns
* NULL on error (i.e. malloc failed), or a pointer to a new
* dynamically allocated instance of the stderrr class.
*/
explain_output_t *explain_output_stderr_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: <br>
* option = 0 <br>
* facility = LOG_USER <br>
* level = LOG_ERR <br>
* See syslog(3) for more information.
*
* @returns
* NULL on error (i.e. malloc failed), or a pointer to a new
* dynamically allocated instance of the syslog class.
*/
explain_output_t *explain_output_syslog_new(void);
/**
* 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: <br>
* option = 0 <br>
* facility = LOG_USER <br>
* See syslog(3) for more information.
*
* @param level
* The syslog level to be used, see syslog(3) for a definition.
* @returns
* NULL on error (i.e. malloc failed), or a pointer to a new
* dynamically allocated instance of the syslog class.
*/
explain_output_t *explain_output_syslog_new1(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.
*
* @param option
* The syslog option to be used, see syslog(3) for a definition.
* @param facility
* The syslog facility to be used, see syslog(3) for a definition.
* @param level
* The syslog level to be used, see syslog(3) for a definition.
* @returns
* NULL on error (i.e. malloc failed), or a pointer to a new
* dynamically allocated instance of the syslog class.
*/
explain_output_t *explain_output_syslog_new3(int option, int facility,
int level);
/**
* 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).
*
* @param filename
* The file to be oopened and written to.
* @param append
* true (non-zero) if messages are to be appended to the file,
* false (zero) if the file is to be preplaced with new contents.
* @returns
* NULL on error (i.e. malloc failed), or a pointer to a new
* dynamically allocated instance of the syslog class.
*/
explain_output_t *explain_output_file_new(const char *filename, int append);
/**
* 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 <b>two</b> other output classes.
*
* @param first
* The first output class to write to.
* @param second
* The second output class to write to.
* @returns
* NULL on error (i.e. malloc failed), or a pointer to a new
* dynamically allocated instance of the syslog class.
*
* @note
* 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_t *explain_output_tee_new(explain_output_t *first,
explain_output_t *second);
/**
* The explain_output_message function is used to print text. It is
* printed via the registered output class, see #explain_output_register
* for how.
*
* @param text
* The text of the message to be printed.
* It has not been wrapped.
*/
void explain_output_message(const char *text);
/**
* The explain_output_error function is used to print a formatted error
* message.
*
* If the program name option has been selected, the program name will
* be prepended to the error message before it is printed.
* To select the option
* <ul>
* <li> calling the #explain_program_name_assemble function at the start of
* your program's main() function; or,
* <li> using the EXPLAIN_OPTIONS environment variable, giving the
* "program-name" or "no-program-name" option; or,
* <li> the default is to print the program name at the start of error
* and warning messages.
* </ul>
* These methods are presented here in order of highest to lowest precedence.
*
* The printing is done via the #explain_output_message function, which
* will do wrapping and indenting if the appropriate output class and
* options have been selected.
*
* @param fmt
* The format text of the message to be printed.
* See printf(3) for more information.
*/
void explain_output_error(const char *fmt, ...)
LIBEXPLAIN_FORMAT_PRINTF(1, 2);
/**
* 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 function, #explain_output_exit function.
*
* @param fmt
* The format text of the message to be printed.
* See printf(3) for more information.
*/
void explain_output_error_and_die(const char *fmt, ...)
LIBEXPLAIN_FORMAT_PRINTF(1, 2)
LIBEXPLAIN_NORETURN;
/**
* The explain_output_warning function is used to print a formatted
* error message, including the word "warning".
*
* If the program name option has been selected, the program name will be
* prepended to the error message before it is printed. To select the option
* <ul>
* <li> call the #explain_program_name_assemble function at the start of your
* program's main() function; or,
* <li> use the EXPLAIN_OPTIONS environment variable, giving the
* "program-name" or "no-program-name" option; or,
* <li> the default is to always print the program name at the start of error
* and warning messages.
* </ul>
* These methods are presented here in order of highest to lowest precedence.
*
* The printing is done via the #explain_output_message function, which
* will do wrapping and indenting if the appropriate output class and
* options have been selected.
*
* @param fmt
* The format text of the message to be printed.
* See printf(3) for more information.
*/
void explain_output_warning(const char *fmt, ...)
LIBEXPLAIN_FORMAT_PRINTF(1, 2);
/**
* The explain_output_method_message function is used to print text.
* Different output "classes" handle this differently.
*
* @param op
* Pointer to the explain_output_t instance to be "printed" on.
* @param text
* The text of the message to be printed.
* It has not been wrapped.
*/
void explain_output_method_message(explain_output_t *op, const char *text);
/**
* The explain_output_exit function is used to terminate
* execution. It is executed via the registered output class,
* #explain_output_register for how.
*
* @param status
* The exist status requested.
*/
void explain_output_exit(int status) LIBEXPLAIN_NORETURN;
/**
* The explain_output_exit_failure function is used to terminate
* execution, with exit status EXIT_FAILURE. It is executed via the
* registered output class, #explain_output_register for how.
*/
void explain_output_exit_failure(void) LIBEXPLAIN_NORETURN;
/**
* The explain_output_method_exit function is used to terminate
* execution. Different "classes" handle this differently.
*
* @param op
* Pointer to the explain_output_t instance to be operated on.
* @param status
* The exist status requested.
*/
void explain_output_method_exit(explain_output_t *op, int status)
LIBEXPLAIN_NORETURN;
/**
* 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.
*
* @param op
* Pointer to the explain_output_t instance to be operated on.
* The NULL pointer will reset to the default style (stderr).
*
* @note
* 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.
*/
void explain_output_register(explain_output_t *op);
/**
* The explain_output_method_destructor function is used to destroy an
* output instance, when its lifetime is over, think of it as a class
* specific free() function. It is called by #explain_output_register
* when a new output instance is given.
*
* It is safe for op to be NULL.
* It is safe for op->vtable->destructor to be NULL.
*
* @param op
* Pointer to the explain_output_t instance to be operated on.
*/
void explain_output_method_destructor(explain_output_t *op);
/**
* The explain_option_assemble_program_name_set option is used to
* override any EXPLAIN_OPTIONS or default setting as to whether or
* not the #explain_output_error, #explain_output_error_and_die and
* #explain_output_warning functions should include the program name
* at the start the messages.
*
* @param yesno
* true (non-zero) to include the program name, zero (false)
* to omit the program name.
*/
void explain_program_name_assemble(int yesno);
/**
* 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 spoace, similar to
* RFC822 headers.
*
* This can be set using the "hanging-indent=N" string in the
* EXPLAIN_OPTIONS environment variable.
*
* Using this function will override any environment variable setting.
*
* @param 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 to much of each
* line, and it is a clear indent.
*/
void explain_option_hanging_indent_set(int columns);
#ifdef __cplusplus
}
#endif
#endif /* LIBEXPLAIN_OUTPUT_H */
/* vim: set ts=8 sw=4 et : */
|