diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-03-14 10:35:09 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-03-14 10:49:56 -0700 |
commit | ec33a95ad04099d428275de2c6b36e7098cc943e (patch) | |
tree | 7790a74518823ea8c636e9658ad9f96eccb0294c /save-git.c | |
parent | b5d0cfd557aa94a423e19663339439301ab1a5ae (diff) | |
download | subsurface-ec33a95ad04099d428275de2c6b36e7098cc943e.tar.gz |
show the error string in the GUI rather than stderr
This makes the error string just be an internal "membuffer", which the
GUI can fetch and show when errors occur. The error string keeps
accumulating until somebody retrieves it with "get_error_string()".
This should make any write errors actually show up to the user.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'save-git.c')
-rw-r--r-- | save-git.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/save-git.c b/save-git.c index ab00ba951..745f26b01 100644 --- a/save-git.c +++ b/save-git.c @@ -340,16 +340,35 @@ static void create_dive_buffer(struct dive *dive, struct membuffer *b) save_dive_temperature(b, dive); } -int report_error(const char *fmt, ...) +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) { - struct membuffer b = { 0 }; - VA_BUF(&b, fmt); + const char *str; - /* We should do some UI element thing describing the failure */ - put_bytes(&b, "\n", 1); - flush_buffer(&b, stderr); - free_buffer(&b); + 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; } |