2017-10-26 12:33:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifdef __clang__
|
|
|
|
// Clang has a bug on zero-initialization of C structs.
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
|
|
|
#endif
|
2019-03-03 21:55:18 +00:00
|
|
|
#include <stdarg.h>
|
2017-10-26 12:33:02 +00:00
|
|
|
#include "dive.h"
|
|
|
|
#include "membuffer.h"
|
|
|
|
|
|
|
|
#define VA_BUF(b, fmt) do { va_list args; va_start(args, fmt); put_vformat(b, fmt, args); va_end(args); } while (0)
|
|
|
|
|
2018-01-26 09:40:04 +00:00
|
|
|
static void (*error_cb)(char *) = NULL;
|
2017-10-26 12:33:02 +00:00
|
|
|
|
|
|
|
int report_error(const char *fmt, ...)
|
|
|
|
{
|
2018-01-26 09:40:04 +00:00
|
|
|
struct membuffer buf = { 0 };
|
2017-10-26 12:33:02 +00:00
|
|
|
|
2018-01-26 09:40:04 +00:00
|
|
|
/* if there is no error callback registered, don't produce errors */
|
|
|
|
if (!error_cb)
|
|
|
|
return -1;
|
2017-10-26 12:33:02 +00:00
|
|
|
|
2018-01-26 09:40:04 +00:00
|
|
|
VA_BUF(&buf, fmt);
|
|
|
|
mb_cstring(&buf);
|
|
|
|
error_cb(detach_buffer(&buf));
|
2017-10-26 12:37:29 +00:00
|
|
|
|
2017-10-26 12:33:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-01-26 09:40:04 +00:00
|
|
|
void set_error_cb(void(*cb)(char *)) {
|
2017-10-26 12:37:29 +00:00
|
|
|
error_cb = cb;
|
|
|
|
}
|