From 05ad06600b712a29bc99a65ae89f38d4d8f30371 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 13 Apr 2019 22:00:04 +0200 Subject: Add liberror_start and liberror_end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- liberror.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'liberror.h') diff --git a/liberror.h b/liberror.h index 3cad426..6062889 100644 --- a/liberror.h +++ b/liberror.h @@ -218,6 +218,31 @@ struct liberror_error { union liberror_details details; }; +/** + * Saved error state for a thread + */ +struct liberror_state { + /** + * The backtrace for the next error + */ + struct liberror_backtrace *backtrace; + + /** + * The thread's error + */ + struct liberror_error error; + + /** + * Whether the thread hade an error + */ + int have_error; + + /** + * The thread's value of `errno` + */ + int errnum; +}; + /** * Get the current error for the thread @@ -346,5 +371,29 @@ void liberror_set_error_errno(const char[256], const char[64], int); */ void liberror_print_error(struct liberror_error *, FILE *, int, const char *); +/** + * Save the thread's liberror error, pending backtrace, + * and `errno`, and then reset the error information + * for the thread + * + * Asynchronously called functions such as signal handlers + * should call this function the first thing they do + * + * @param state Output parameter for the error state + */ +void liberror_start(struct liberror_state *); + +/** + * Restore the thread's liberror error, pending backtrace, + * and `errno` + * + * Asynchronously called functions such as signal handlers + * should call this function the last thing they do before + * returning + * + * @param state The saved error state to restore + */ +void liberror_end(const struct liberror_state *); + #endif -- cgit v1.2.3-70-g09d2