2017-10-26 14:33:02 +02: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 22:55:18 +01:00
|
|
|
#include <stdarg.h>
|
2019-08-05 19:41:15 +02:00
|
|
|
#include "errorhelper.h"
|
2017-10-26 14:33:02 +02:00
|
|
|
#include "membuffer.h"
|
2022-08-30 09:48:46 -07:00
|
|
|
|
|
|
|
#if !defined(Q_OS_ANDROID) && !defined(__ANDROID__)
|
|
|
|
#define LOG_MSG(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#include <android/log.h>
|
|
|
|
#define LOG_MSG(fmt, ...) __android_log_print(ANDROID_LOG_INFO, "Subsurface", fmt, ##__VA_ARGS__);
|
|
|
|
#endif
|
2017-10-26 14:33:02 +02:00
|
|
|
|
|
|
|
#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 19:41:15 +02:00
|
|
|
int verbose;
|
|
|
|
|
2022-08-30 09:48:46 -07:00
|
|
|
void report_info(const char *fmt, ...)
|
|
|
|
{
|
2024-03-24 19:21:00 +01:00
|
|
|
struct membufferpp buf;
|
2022-08-30 09:48:46 -07:00
|
|
|
|
|
|
|
VA_BUF(&buf, fmt);
|
|
|
|
strip_mb(&buf);
|
|
|
|
LOG_MSG("INFO: %s\n", mb_cstring(&buf));
|
|
|
|
}
|
|
|
|
|
2018-01-26 10:40:04 +01:00
|
|
|
static void (*error_cb)(char *) = NULL;
|
2017-10-26 14:33:02 +02:00
|
|
|
|
|
|
|
int report_error(const char *fmt, ...)
|
|
|
|
{
|
2024-03-24 19:21:00 +01:00
|
|
|
struct membufferpp buf;
|
2017-10-26 14:33:02 +02:00
|
|
|
|
2022-08-30 09:48:46 -07:00
|
|
|
VA_BUF(&buf, fmt);
|
|
|
|
strip_mb(&buf);
|
|
|
|
LOG_MSG("ERROR: %s\n", mb_cstring(&buf));
|
|
|
|
|
2018-01-26 10:40:04 +01:00
|
|
|
/* if there is no error callback registered, don't produce errors */
|
|
|
|
if (!error_cb)
|
|
|
|
return -1;
|
2019-10-27 14:24:10 -04:00
|
|
|
error_cb(detach_cstring(&buf));
|
2017-10-26 14:33:02 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-02-23 18:31:02 +01:00
|
|
|
void set_error_cb(void(*cb)(char *))
|
|
|
|
{
|
2017-10-26 14:37:29 +02:00
|
|
|
error_cb = cb;
|
|
|
|
}
|