summaryrefslogtreecommitdiff
path: root/src/errors.c
diff options
context:
space:
mode:
authorAndreas Ericsson <ae@op5.se>2008-11-18 22:20:15 +0100
committerShawn O. Pearce <spearce@spearce.org>2008-11-22 12:08:00 -0800
commitae23486285f4e16896afd53b20dd11180d26381a (patch)
tree4a65039859952e2ffe776d2e1afbe0c7ea02d14c /src/errors.c
parent3a2aabdce127a367aa27a4c27025199230e26c15 (diff)
downloadlibgit2-ae23486285f4e16896afd53b20dd11180d26381a.tar.gz
Add an embryo of a TLS-aware error handling system
This adds the per-thread global variable git_errno to the system, which callers can examine to get information about an error. Two helper functions are added to reduce LoC-count for the library code itself. Also, some exceptions are made for running sparse on GIT_TLS definitions, since it doesn't grok thread-local variables at all. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src/errors.c')
-rw-r--r--src/errors.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/errors.c b/src/errors.c
new file mode 100644
index 000000000..b3e014dd4
--- /dev/null
+++ b/src/errors.c
@@ -0,0 +1,23 @@
+#include "common.h"
+#include "thread-utils.h" /* for GIT_TLS */
+
+/* compile-time constant initialization required */
+GIT_TLS int git_errno = 0;
+
+static struct {
+ int num;
+ const char *str;
+} error_codes[] = {
+ { GIT_ENOTOID, "Not a git oid" },
+ { GIT_ENOTFOUND, "Object does not exist in the scope searched" },
+};
+
+const char *git_strerror(int num)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(error_codes); i++)
+ if (num == error_codes[i].num)
+ return error_codes[i].str;
+
+ return "Unknown error";
+}