mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Move error reporting into its own source file
This doesn't really seem to belong in save_git.c. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
2c67b387ea
commit
6ec7d2d877
3 changed files with 47 additions and 36 deletions
|
@ -40,6 +40,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
|
|||
divesite.cpp
|
||||
divelist.c
|
||||
equipment.c
|
||||
errorhelper.c
|
||||
file.c
|
||||
gas-model.c
|
||||
git-access.c
|
||||
|
|
46
core/errorhelper.c
Normal file
46
core/errorhelper.c
Normal file
|
@ -0,0 +1,46 @@
|
|||
// 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 "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 struct membuffer error_string_buffer = { 0 };
|
||||
/*
|
||||
* Note that the act of "getting" the error string
|
||||
* buffer doesn't de-allocate the buffer, but it does
|
||||
* set the buffer length to zero, so that any future
|
||||
* error reports will overwrite the string rather than
|
||||
* append to it.
|
||||
*/
|
||||
const char *get_error_string(void)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
if (!error_string_buffer.len)
|
||||
return "";
|
||||
str = mb_cstring(&error_string_buffer);
|
||||
error_string_buffer.len = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
int report_error(const char *fmt, ...)
|
||||
{
|
||||
struct membuffer *buf = &error_string_buffer;
|
||||
|
||||
/* Previous unprinted errors? Add a newline in between */
|
||||
if (buf->len)
|
||||
put_bytes(buf, "\n", 1);
|
||||
VA_BUF(buf, fmt);
|
||||
mb_cstring(buf);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void report_message(const char *msg)
|
||||
{
|
||||
(void)report_error("%s", msg);
|
||||
}
|
|
@ -440,42 +440,6 @@ static void create_dive_buffer(struct dive *dive, struct membuffer *b)
|
|||
save_dive_temperature(b, dive);
|
||||
}
|
||||
|
||||
static struct membuffer error_string_buffer = { 0 };
|
||||
|
||||
/*
|
||||
* Note that the act of "getting" the error string
|
||||
* buffer doesn't de-allocate the buffer, but it does
|
||||
* set the buffer length to zero, so that any future
|
||||
* error reports will overwrite the string rather than
|
||||
* append to it.
|
||||
*/
|
||||
const char *get_error_string(void)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
if (!error_string_buffer.len)
|
||||
return "";
|
||||
str = mb_cstring(&error_string_buffer);
|
||||
error_string_buffer.len = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
int report_error(const char *fmt, ...)
|
||||
{
|
||||
struct membuffer *buf = &error_string_buffer;
|
||||
|
||||
/* Previous unprinted errors? Add a newline in between */
|
||||
if (buf->len)
|
||||
put_bytes(buf, "\n", 1);
|
||||
VA_BUF(buf, fmt);
|
||||
mb_cstring(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void report_message(const char *msg)
|
||||
{
|
||||
(void)report_error("%s", msg);
|
||||
}
|
||||
|
||||
/*
|
||||
* libgit2 has a "git_treebuilder" concept, but it's broken, and can not
|
||||
|
|
Loading…
Add table
Reference in a new issue