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>
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "errorhelper.h"
|
2017-10-26 12:33:02 +00:00
|
|
|
#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)
|
|
|
|
|
2019-08-05 17:41:15 +00:00
|
|
|
int verbose;
|
|
|
|
|
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);
|
2019-10-27 18:24:10 +00:00
|
|
|
error_cb(detach_cstring(&buf));
|
2017-10-26 12:37:29 +00:00
|
|
|
|
2017-10-26 12:33:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-02-23 17:31:02 +00:00
|
|
|
void set_error_cb(void(*cb)(char *))
|
|
|
|
{
|
2017-10-26 12:37:29 +00:00
|
|
|
error_cb = cb;
|
|
|
|
}
|