mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-05 20:33:41 +00:00
Remove git_errno
It was not being used by any methods (only by malloc and calloc), and since it needs to be TLS, it cannot be exported on DLLs on Windows. Burn it with fire. The API always returns error codes! Signed-off-by: Vicent Marti <tanoku@gmail.com>
This commit is contained in:
parent
11f6646f03
commit
9f54fe482d
@ -49,7 +49,6 @@ typedef SSIZE_T ssize_t;
|
|||||||
#include "git2/common.h"
|
#include "git2/common.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "thread-utils.h"
|
#include "thread-utils.h"
|
||||||
#include "errors.h"
|
|
||||||
#include "bswap.h"
|
#include "bswap.h"
|
||||||
|
|
||||||
#define GIT_PATH_MAX 4096
|
#define GIT_PATH_MAX 4096
|
||||||
|
28
src/errors.c
28
src/errors.c
@ -1,34 +1,6 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "thread-utils.h" /* for GIT_TLS */
|
#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 {
|
static struct {
|
||||||
int num;
|
int num;
|
||||||
const char *str;
|
const char *str;
|
||||||
|
24
src/errors.h
24
src/errors.h
@ -1,24 +0,0 @@
|
|||||||
#ifndef INCLUDE_errors_h__
|
|
||||||
#define INCLUDE_errors_h__
|
|
||||||
|
|
||||||
#include "git2/errors.h"
|
|
||||||
|
|
||||||
/* convenience functions */
|
|
||||||
GIT_INLINE(int) git_int_error(int code)
|
|
||||||
{
|
|
||||||
git_errno = code;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
GIT_INLINE(int) git_os_error(void)
|
|
||||||
{
|
|
||||||
return git_int_error(GIT_EOSERR);
|
|
||||||
}
|
|
||||||
|
|
||||||
GIT_INLINE(void) *git_ptr_error(int code)
|
|
||||||
{
|
|
||||||
git_errno = code;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -4,13 +4,13 @@
|
|||||||
int gitfo_open(const char *path, int flags)
|
int gitfo_open(const char *path, int flags)
|
||||||
{
|
{
|
||||||
int fd = open(path, flags | O_BINARY);
|
int fd = open(path, flags | O_BINARY);
|
||||||
return fd >= 0 ? fd : git_os_error();
|
return fd >= 0 ? fd : GIT_EOSERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gitfo_creat(const char *path, int mode)
|
int gitfo_creat(const char *path, int mode)
|
||||||
{
|
{
|
||||||
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
|
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
|
||||||
return fd >= 0 ? fd : git_os_error();
|
return fd >= 0 ? fd : GIT_EOSERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gitfo_read(git_file fd, void *buf, size_t cnt)
|
int gitfo_read(git_file fd, void *buf, size_t cnt)
|
||||||
@ -21,11 +21,11 @@ int gitfo_read(git_file fd, void *buf, size_t cnt)
|
|||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
if (errno == EINTR || errno == EAGAIN)
|
if (errno == EINTR || errno == EAGAIN)
|
||||||
continue;
|
continue;
|
||||||
return git_os_error();
|
return GIT_EOSERR;
|
||||||
}
|
}
|
||||||
if (!r) {
|
if (!r) {
|
||||||
errno = EPIPE;
|
errno = EPIPE;
|
||||||
return git_os_error();
|
return GIT_EOSERR;
|
||||||
}
|
}
|
||||||
cnt -= r;
|
cnt -= r;
|
||||||
b += r;
|
b += r;
|
||||||
@ -41,11 +41,11 @@ int gitfo_write(git_file fd, void *buf, size_t cnt)
|
|||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
if (errno == EINTR || errno == EAGAIN)
|
if (errno == EINTR || errno == EAGAIN)
|
||||||
continue;
|
continue;
|
||||||
return git_os_error();
|
return GIT_EOSERR;
|
||||||
}
|
}
|
||||||
if (!r) {
|
if (!r) {
|
||||||
errno = EPIPE;
|
errno = EPIPE;
|
||||||
return git_os_error();
|
return GIT_EOSERR;
|
||||||
}
|
}
|
||||||
cnt -= r;
|
cnt -= r;
|
||||||
b += r;
|
b += r;
|
||||||
@ -92,7 +92,7 @@ off_t gitfo_size(git_file fd)
|
|||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
if (gitfo_fstat(fd, &sb))
|
if (gitfo_fstat(fd, &sb))
|
||||||
return git_os_error();
|
return GIT_EOSERR;
|
||||||
return sb.st_size;
|
return sb.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,13 +151,13 @@ int gitfo_move_file(char *from, char *to)
|
|||||||
if (!rename(from, to))
|
if (!rename(from, to))
|
||||||
return GIT_SUCCESS;
|
return GIT_SUCCESS;
|
||||||
|
|
||||||
return git_os_error();
|
return GIT_EOSERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gitfo_map_ro(git_map *out, git_file fd, off_t begin, size_t len)
|
int gitfo_map_ro(git_map *out, git_file fd, off_t begin, size_t len)
|
||||||
{
|
{
|
||||||
if (git__mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin) < GIT_SUCCESS)
|
if (git__mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin) < GIT_SUCCESS)
|
||||||
return git_os_error();
|
return GIT_EOSERR;
|
||||||
return GIT_SUCCESS;
|
return GIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ int gitfo_dirent(
|
|||||||
|
|
||||||
dir = opendir(path);
|
dir = opendir(path);
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return git_os_error();
|
return GIT_EOSERR;
|
||||||
|
|
||||||
while ((de = readdir(dir)) != NULL) {
|
while ((de = readdir(dir)) != NULL) {
|
||||||
size_t de_len;
|
size_t de_len;
|
||||||
|
@ -33,16 +33,6 @@
|
|||||||
*/
|
*/
|
||||||
GIT_BEGIN_DECL
|
GIT_BEGIN_DECL
|
||||||
|
|
||||||
/** The git errno. */
|
|
||||||
#if defined(GIT_TLS)
|
|
||||||
GIT_EXTERN_TLS(int) git_errno;
|
|
||||||
|
|
||||||
#elif defined(GIT_HAS_PTHREAD)
|
|
||||||
# define git_errno (*git__errno_storage())
|
|
||||||
GIT_EXTERN(int *) git__errno_storage(void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* strerror() for the Git library
|
* strerror() for the Git library
|
||||||
* @param num The error code to explain
|
* @param num The error code to explain
|
||||||
|
@ -40,7 +40,7 @@ int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, off_t offse
|
|||||||
|
|
||||||
out->data = mmap(NULL, len, mprot, mflag, fd, offset);
|
out->data = mmap(NULL, len, mprot, mflag, fd, offset);
|
||||||
if (!out->data || out->data == MAP_FAILED)
|
if (!out->data || out->data == MAP_FAILED)
|
||||||
return git_os_error();
|
return GIT_EOSERR;
|
||||||
out->len = len;
|
out->len = len;
|
||||||
|
|
||||||
return GIT_SUCCESS;
|
return GIT_SUCCESS;
|
||||||
|
24
src/util.c
24
src/util.c
@ -3,30 +3,6 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
void *git__malloc(size_t n)
|
|
||||||
{
|
|
||||||
void *r = malloc(n);
|
|
||||||
if (!r)
|
|
||||||
return git_ptr_error(GIT_ENOMEM);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *git__calloc(size_t a, size_t b)
|
|
||||||
{
|
|
||||||
void *r = calloc(a, b);
|
|
||||||
if (!r)
|
|
||||||
return git_ptr_error(GIT_ENOMEM);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *git__strdup(const char *s)
|
|
||||||
{
|
|
||||||
char *r = strdup(s);
|
|
||||||
if (!r)
|
|
||||||
return git_ptr_error(GIT_ENOMEM);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int git__fmt(char *buf, size_t buf_sz, const char *fmt, ...)
|
int git__fmt(char *buf, size_t buf_sz, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
|
32
src/util.h
32
src/util.h
@ -3,28 +3,16 @@
|
|||||||
|
|
||||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||||
|
|
||||||
GIT_EXTERN(void *) git__malloc(size_t);
|
/*
|
||||||
GIT_EXTERN(void *) git__calloc(size_t, size_t);
|
* Don't wrap malloc/calloc.
|
||||||
GIT_EXTERN(char *) git__strdup(const char *);
|
* Use the default versions in glibc, and make
|
||||||
|
* sure that any methods that allocate memory
|
||||||
#ifndef GIT__NO_HIDE_MALLOC
|
* return a GIT_ENOMEM error when allocation
|
||||||
# define GIT__FORBID_MALLOC do_not_use_malloc_directly
|
* fails.
|
||||||
|
*/
|
||||||
# ifdef malloc
|
#define git__malloc malloc
|
||||||
# undef malloc
|
#define git__calloc calloc
|
||||||
# endif
|
#define git__strdup strdup
|
||||||
# define malloc(a) GIT__FORBID_MALLOC
|
|
||||||
|
|
||||||
# ifdef calloc
|
|
||||||
# undef calloc
|
|
||||||
# endif
|
|
||||||
# define calloc(a,b) GIT__FORBID_MALLOC
|
|
||||||
|
|
||||||
# ifdef strdup
|
|
||||||
# undef strdup
|
|
||||||
# endif
|
|
||||||
# define strdup(a) GIT__FORBID_MALLOC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
GIT_EXTERN(int) git__fmt(char *, size_t, const char *, ...)
|
GIT_EXTERN(int) git__fmt(char *, size_t, const char *, ...)
|
||||||
GIT_FORMAT_PRINTF(3, 4);
|
GIT_FORMAT_PRINTF(3, 4);
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
#include "test_lib.h"
|
|
||||||
#include "errors.h"
|
|
||||||
|
|
||||||
BEGIN_TEST(errno_zero_on_init)
|
|
||||||
must_be_true(git_errno == 0);
|
|
||||||
END_TEST
|
|
||||||
|
|
||||||
BEGIN_TEST(set_ENOTOID)
|
|
||||||
must_be_true(GIT_ENOTOID != 0);
|
|
||||||
git_errno = GIT_ENOTOID;
|
|
||||||
must_be_true(git_errno == GIT_ENOTOID);
|
|
||||||
END_TEST
|
|
Loading…
Reference in New Issue
Block a user