mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
5da09a21bb
Move the declarations of the "report_error()" and "set_error_cb()" functions and the "verbose" variable to errorhelper.h. Thus, error-reporting translation units don't have to import the big dive.h header file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
34 lines
738 B
C
34 lines
738 B
C
// 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
|
|
#include <stdarg.h>
|
|
#include "errorhelper.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)
|
|
|
|
int verbose;
|
|
|
|
static void (*error_cb)(char *) = NULL;
|
|
|
|
int report_error(const char *fmt, ...)
|
|
{
|
|
struct membuffer buf = { 0 };
|
|
|
|
/* if there is no error callback registered, don't produce errors */
|
|
if (!error_cb)
|
|
return -1;
|
|
|
|
VA_BUF(&buf, fmt);
|
|
mb_cstring(&buf);
|
|
error_cb(detach_buffer(&buf));
|
|
|
|
return -1;
|
|
}
|
|
|
|
void set_error_cb(void(*cb)(char *))
|
|
{
|
|
error_cb = cb;
|
|
}
|