Hash :
0ef9d2aa
Author :
Date :
2010-01-03T22:56:54
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#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) {
#undef calloc
e = calloc(1, sizeof(*e));
#define calloc(a,b) GIT__FORBID_MALLOC
pthread_setspecific(errno_key, e);
}
return e;
}
#endif
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" },
{ GIT_ENOMEM, "Not enough space" },
};
const char *git_strerror(int num)
{
size_t i;
if (num == GIT_EOSERR)
return strerror(errno);
for (i = 0; i < ARRAY_SIZE(error_codes); i++)
if (num == error_codes[i].num)
return error_codes[i].str;
return "Unknown error";
}