aboutsummaryrefslogtreecommitdiffstats
path: root/set_error.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-04-12 21:12:12 +0200
committerMattias Andrée <maandree@kth.se>2019-04-12 21:13:19 +0200
commit1484b1264552ad05d75a4ca4f40972ac94e729e9 (patch)
treeb9f6d6212866699db66e8bd64310d445498db2f3 /set_error.c
downloadliberror-1484b1264552ad05d75a4ca4f40972ac94e729e9.tar.gz
liberror-1484b1264552ad05d75a4ca4f40972ac94e729e9.tar.bz2
liberror-1484b1264552ad05d75a4ca4f40972ac94e729e9.tar.xz
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--set_error.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/set_error.c b/set_error.c
new file mode 100644
index 0000000..5ee54ce
--- /dev/null
+++ b/set_error.c
@@ -0,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+#include "internal.h"
+
+
+void
+liberror_set_error(const char description[256], const char source[64], const char code_group[64], long long int code)
+{
+ struct liberror_error *cause;
+ struct liberror_error *error;
+ int have_cause;
+
+ cause = liberror_get_error();
+ have_cause = !!cause;
+ cause = liberror_copy_error(cause);
+
+ error = &liberror_error_;
+ liberror_have_error_ = 1;
+
+ memset(error, 0, sizeof(*error));
+
+ if (*description) {
+ stpcpy(error->description, description);
+ } else if (!strcmp(code_group, "errno")) {
+ if (code >= (long long int)INT_MIN && code <= (long long int)INT_MAX)
+ strerror_r((int)code, error->description, sizeof(error->description));
+ }
+ stpcpy(error->source, source);
+ stpcpy(error->code_group, code_group);
+ error->code = code;
+ liberror_save_backtrace_(error);
+ error->cause = cause;
+ error->failed_to_allocate_cause = have_cause && !cause;
+}