eaarl-io
1.0.1+71abbd4
EAARL Input/Output Library (Public API)
|
Error codes and handling. More...
#include <stdio.h>
#include <string.h>
Go to the source code of this file.
Functions | |
char const * | eaarlio_error_name (eaarlio_error err) |
Retrieve the symbolic name for an error. More... | |
char const * | eaarlio_error_message (eaarlio_error err) |
Retrieve an error message for an error. More... | |
int | eaarlio_error_check (eaarlio_error err, char *format,...) |
Check for errors and display error if needed. More... | |
Error codes and handling.
This header defines the error codes that are used as return results throughout the library. It also provides two functions that can be used to provide human-readable information about error codes.
enum eaarlio_error |
int eaarlio_error_check | ( | eaarlio_error | err, |
char * | format, | ||
... | |||
) |
Check for errors and display error if needed.
This is a simple handler for checking eaarlio_error codes and displaying error messages.
When err
is EAARLIO_SUCCESS, this function does nothing except return 0.
When err
is anything other than EAARLIO_SUCCESS, it prints an error message to stderr and returns 1. If format
is provided, then fprintf will be used to print the supplied message (passing any additional parameters through to it). Then eaarlio_error_name and eaarlio_error_message are used to display the error code and a short description to stderr.
format
can be null
, in which case just the error code and description are output to stderr.
[in] | err | Error code from an eaarlio library function |
[in] | format | Format string for message to print on error |
[in] | ... | Additional arguments to use when printing error |
0 | if err is EAARLIO_SUCCESS |
1 | if err is not EAARLIO_SUCCESS |
err
is not EAARLIO_SUCCESS, then an error message is printed to stderr.As an example, consider this sample code:
Because err
is not EAARLIO_SUCCESS, this would print the following message to stderr and assign 1 to failed:
char const* eaarlio_error_message | ( | eaarlio_error | err | ) |
Retrieve an error message for an error.
For example, eaarlio_error_message(EAARLIO_SUCCESS)
will return "Success!"
.
[in] | err | An error code |
char const* eaarlio_error_name | ( | eaarlio_error | err | ) |
Retrieve the symbolic name for an error.
For example, eaarlio_error_name(EAARLIO_SUCCESS)
will return "EAARLIO_SUCCESS"
.
[in] | err | An error code |