Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreutarass2011-08-08 18:06:26 +0000
committereutarass2011-08-08 18:06:26 +0000
commitb8d4c9cf5ad1a7a5b5e1cc4d823fc3913f2ef599 (patch)
tree2ac06c011c398b4a99e7573875d4c02e188d3122 /framework
parentea8f850f59028a4ef0df5bda3d958dc0f4f0c973 (diff)
downloadorg.eclipse.tcf.agent-b8d4c9cf5ad1a7a5b5e1cc4d823fc3913f2ef599.tar.gz
org.eclipse.tcf.agent-b8d4c9cf5ad1a7a5b5e1cc4d823fc3913f2ef599.tar.xz
org.eclipse.tcf.agent-b8d4c9cf5ad1a7a5b5e1cc4d823fc3913f2ef599.zip
TCF Agent: added new function to raise an exception that accepts format spec and varargs:
str_fmt_exception(int error, const char * fmt, ...)
Diffstat (limited to 'framework')
-rw-r--r--framework/exceptions.c21
-rw-r--r--framework/exceptions.h2
2 files changed, 23 insertions, 0 deletions
diff --git a/framework/exceptions.c b/framework/exceptions.c
index 774522c0..2ed2991b 100644
--- a/framework/exceptions.c
+++ b/framework/exceptions.c
@@ -33,9 +33,11 @@
#include <config.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <framework/exceptions.h>
+#include <framework/myalloc.h>
#include <framework/events.h>
#include <framework/trace.h>
@@ -77,3 +79,22 @@ void exception(int error) {
void str_exception(int error, const char * msg) {
exception(set_errno(error, msg));
}
+
+void str_fmt_exception(int error, const char * fmt, ...) {
+ va_list vaList;
+ char * buf = NULL;
+ size_t len = 100;
+ int n;
+
+ while (1) {
+ buf = (char *)loc_realloc(buf, len);
+ va_start(vaList, fmt);
+ n = vsnprintf(buf, len, fmt, vaList);
+ va_end(vaList);
+ if (n < (int)len) break;
+ len = n + 1;
+ }
+ error = set_errno(error, buf);
+ loc_free(buf);
+ exception(error);
+}
diff --git a/framework/exceptions.h b/framework/exceptions.h
index 556022ce..4a4b53dd 100644
--- a/framework/exceptions.h
+++ b/framework/exceptions.h
@@ -51,7 +51,9 @@ extern int set_trap_a(Trap * trap);
extern int set_trap_b(Trap * trap);
extern void clear_trap(Trap * trap);
+
extern void exception(int error);
extern void str_exception(int error, const char * msg);
+extern void str_fmt_exception(int error, const char * fmt, ...);
#endif /* D_exceptions */

Back to the top