summaryrefslogtreecommitdiff
path: root/src/errors.c
diff options
context:
space:
mode:
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
index b3e014dd4..75636f477 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -1,9 +1,32 @@
#include "common.h"
#include "thread-utils.h" /* for GIT_TLS */
+#if defined(GIT_TLS)
/* compile-time constant initialization required */
GIT_TLS int git_errno = 0;
+#elif defined(GIT_HAS_PTHREAD)
+
+static pthread_key_t errno_key;
+
+static void init_errno(void) __attribute__((constructor));
+static void init_errno(void)
+{
+ pthread_key_create(&errno_key, free);
+}
+
+int *git__errno_storage(void)
+{
+ int *e = pthread_getspecific(errno_key);
+ if (!e) {
+ e = calloc(1, sizeof(*e));
+ pthread_setspecific(errno_key, e);
+ }
+ return e;
+}
+
+#endif
+
static struct {
int num;
const char *str;