mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 19:23:24 +00:00
Set error callback helper
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
6ec7d2d877
commit
eccd4b993a
2 changed files with 10 additions and 0 deletions
|
@ -698,6 +698,7 @@ extern "C" {
|
|||
extern int report_error(const char *fmt, ...);
|
||||
extern void report_message(const char *msg);
|
||||
extern const char *get_error_string(void);
|
||||
extern void set_error_cb(void(*cb)(void));
|
||||
|
||||
extern struct dive *find_dive_including(timestamp_t when);
|
||||
extern bool dive_within_time_range(struct dive *dive, timestamp_t when, timestamp_t offset);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define VA_BUF(b, fmt) do { va_list args; va_start(args, fmt); put_vformat(b, fmt, args); va_end(args); } while (0)
|
||||
|
||||
static struct membuffer error_string_buffer = { 0 };
|
||||
static void (*error_cb)(void) = NULL;
|
||||
/*
|
||||
* Note that the act of "getting" the error string
|
||||
* buffer doesn't de-allocate the buffer, but it does
|
||||
|
@ -37,6 +38,10 @@ int report_error(const char *fmt, ...)
|
|||
VA_BUF(buf, fmt);
|
||||
mb_cstring(buf);
|
||||
|
||||
/* if an error callback is registered, call it */
|
||||
if (error_cb)
|
||||
error_cb();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -44,3 +49,7 @@ void report_message(const char *msg)
|
|||
{
|
||||
(void)report_error("%s", msg);
|
||||
}
|
||||
|
||||
void set_error_cb(void(*cb)(void)) {
|
||||
error_cb = cb;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue