#include "attributes.h"
#include "filenames.h"
#include "terminal_colors.h"
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <err.h>
Go to the source code of this file.
|
#define | ERRNO_OK 0 /* No error */ |
#define | RV_EXCEPTION ( -2 ) /* Non-fatal, recoverable error e.g. OOB index */ |
#define | RV_ERROR ( -1 ) /* Fatal, un-recoverable error */ |
#define | RV_SUCCESS 0 /* Success */ |
#define | on_fail(func_call) |
#define | on_error(func_call) |
#define | return_on_fail(func_call) |
#define | return_on_error(func_call) |
#define | goto_on_fail(GOTO_LABEL, func_call) |
#define | goto_on_error(GOTO_LABEL, func_call) |
#define | COLOR_WARNING FOREGROUND_RED |
#define | f_stack_trace(RETVAL) |
#define | ffl_stack_trace(RETVAL) |
#define | warn_ret(RETVAL, ...) |
#define | warnx_ret(RETVAL, ...) |
#define | fwarn(...) |
#define | fwarnx(...) |
#define | fwarn_ret(RETVAL, ...) |
#define | fwarnx_ret(RETVAL, ...) |
#define | fflwarn(...) |
#define | fflwarnx(...) |
#define | fflwarn_ret(RETVAL, ...) |
#define | fflwarnx_ret(RETVAL, ...) |
◆ COLOR_WARNING
◆ ERRNO_OK
#define ERRNO_OK 0 /* No error */ |
◆ f_stack_trace
#define f_stack_trace |
( |
| RETVAL | ) |
|
Value: WarnUniversal(
false, NULL, NULL, -1, -1, ( ptrdiff_t ) RETVAL,
"\tin %s", __func__ )
LibraryDefined PrintfLike Cold ptrdiff_t WarnUniversal(bool PrintProgName, const char *__restrict FileName, const char *__restrict FunctionName, int LineNumber, int err_no, ptrdiff_t return_value, const char *__restrict format,...)
Definition errors.h:160
prints
Example:
int foo()
{
fwarnx(
"some error message" );
}
int main()
{
{
return 1;
}
}
#define fwarnx(...)
Definition errors.h:270
#define f_stack_trace(RETVAL)
Definition errors.h:241
#define RV_SUCCESS
Definition errors.h:34
#define RV_EXCEPTION
Definition errors.h:32
prints (to stderr):
‹program-name›: foo: some error message
in main
◆ ffl_stack_trace
#define ffl_stack_trace |
( |
| RETVAL | ) |
|
Value:
NULL, \
NULL, \
-1, \
-1, \
( ptrdiff_t ) RETVAL, \
"\tin %s: %s @ %d", \
__FILE_NAME__, \
__func__, \
__LINE__ )
Like f_stack_trace, just with __FILE_NAME__ and __LINE__
- See also
- f_stack_trace()
◆ fflwarn
Value:
true, __FILE_NAME__, __func__, __LINE__, errno, -1, __VA_ARGS__ )
◆ fflwarn_ret
#define fflwarn_ret |
( |
| RETVAL, |
|
|
| ... ) |
Value:
__FILE_NAME__, \
__func__, \
__LINE__, \
errno, \
( ptrdiff_t ) RETVAL, \
__VA_ARGS__ )
◆ fflwarnx
Value: ( void )
WarnUniversal(
true, __FILE_NAME__, __func__, __LINE__, -1, -1, __VA_ARGS__ )
◆ fflwarnx_ret
#define fflwarnx_ret |
( |
| RETVAL, |
|
|
| ... ) |
Value:
__FILE_NAME__, \
__func__, \
__LINE__, \
-1, \
( ptrdiff_t ) RETVAL, \
__VA_ARGS__ )
◆ fwarn
Value: ( void )
WarnUniversal(
true, NULL, __func__, -1, errno, -1, __VA_ARGS__ )
warn() with function name at the start
◆ fwarn_ret
#define fwarn_ret |
( |
| RETVAL, |
|
|
| ... ) |
Value: WarnUniversal(
true, NULL, __func__, -1, errno, ( ptrdiff_t ) RETVAL, __VA_ARGS__ )
◆ fwarnx
Value: ( void )
WarnUniversal(
true, NULL, __func__, -1, -1, -1, __VA_ARGS__ )
◆ fwarnx_ret
#define fwarnx_ret |
( |
| RETVAL, |
|
|
| ... ) |
Value: WarnUniversal(
true, NULL, __func__, -1, -1, ( ptrdiff_t ) RETVAL, __VA_ARGS__ )
◆ goto_on_error
#define goto_on_error |
( |
| GOTO_LABEL, |
|
|
| func_call ) |
Value: do \
{ \
on_error ( func_call ) \
goto GOTO_LABEL; \
} \
while ( 0 )
◆ goto_on_fail
#define goto_on_fail |
( |
| GOTO_LABEL, |
|
|
| func_call ) |
Value: do \
{ \
on_fail ( func_call ) \
goto GOTO_LABEL; \
} \
while ( 0 )
◆ on_error
#define on_error |
( |
| func_call | ) |
|
Value:
#define RV_ERROR
Definition errors.h:33
◆ on_fail
#define on_fail |
( |
| func_call | ) |
|
◆ return_on_error
#define return_on_error |
( |
| func_call | ) |
|
Value: do \
{ \
int func_call_retval = ( func_call ); \
on_error ( func_call_retval ) \
{ \
return func_call_retval; \
} \
} \
while ( 0 )
Returns the value (of type int) of the function call or variable if it equals RV_ERROR
- See also
- return_on_fail()
◆ return_on_fail
#define return_on_fail |
( |
| func_call | ) |
|
Value: do \
{ \
int func_call_retval = ( func_call ); \
on_fail ( func_call_retval ) \
{ \
return func_call_retval; \
} \
} \
while ( 0 )
Returns the value (of type int) of the function call or variable if it doesn't equal RV_SUCCESS
- See also
- return_on_error()
◆ RV_ERROR
#define RV_ERROR ( -1 ) /* Fatal, un-recoverable error */ |
◆ RV_EXCEPTION
#define RV_EXCEPTION ( -2 ) /* Non-fatal, recoverable error e.g. OOB index */ |
◆ RV_SUCCESS
#define RV_SUCCESS 0 /* Success */ |
◆ warn_ret
#define warn_ret |
( |
| RETVAL, |
|
|
| ... ) |
Value: WarnUniversal(
true, NULL, NULL, -1, errno, ( ptrdiff_t ) RETVAL, __VA_ARGS__ )
Warns like warn() and returns RETVAL
◆ warnx_ret
#define warnx_ret |
( |
| RETVAL, |
|
|
| ... ) |
Value: WarnUniversal(
true, NULL, NULL, -1, -1, ( ptrdiff_t ) RETVAL, __VA_ARGS__ )
◆ rv_to_string()
Turns an RV to a string.
- Parameters
-
- Returns
- string literal
◆ WarnUniversal()
ptrdiff_t WarnUniversal |
( |
bool | PrintProgName, |
|
|
const char *__restrict | FileName, |
|
|
const char *__restrict | FunctionName, |
|
|
int | LineNumber, |
|
|
int | err_no, |
|
|
ptrdiff_t | return_value, |
|
|
const char *__restrict | format, |
|
|
| ... ) |
Similar to warn() (especially warnc)
Prints
‹executable name›: ‹FileName›: ‹FunctionName› @ LineNumber: ‹formatted string›[: strerror(err_no)]
If ‹FileName› or ‹FunctionName› is NULL or if ‹LineNumber› or ‹err_no› equals -1, then they are not printed.
Example of an actual function-like macro defined in errors.h:
#define fwarn( ... ) ( void ) WarnUniversal( NULL, __func__, -1, errno, -1, __VA_ARGS__ )
- Parameters
-
PrintProgName | true if the function should print the executable name |
FileName | name of the current file (FILE_NAME) |
FunctionName | name of the function (func) |
LineNumber | number of the line to warn about (LINE) |
err_no | errno to warn about |
return_value | returned value |
format | format string |
... | printf-like arguments for ‹format› |
- Returns
- Bug
- "%p" for some reason sometimes throws compiler errors for non void * pointers