subsurface/core/errorhelper.c
Berthold Stoeger 9ed5cf16a4 Coding style: remove Java-style function definition
Remove a few cases of
	void fun() {
		...
	}

While touching these functions, fix a few other whitespace
coding style violations.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00

32 lines
717 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 "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)
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;
}