diff options
author | Vicent Marti <vicent@github.com> | 2014-08-07 18:00:57 +0200 |
---|---|---|
committer | Vicent Marti <vicent@github.com> | 2014-08-07 18:00:57 +0200 |
commit | 8f759ac0b373eea9dcec680524a68a527d637937 (patch) | |
tree | 99ca32351711018c855ac06e3859c5be9ed86ea5 | |
parent | e0af2517bf9055441cfa34c45087c0ee9defe7e9 (diff) | |
parent | 07d03d31456899a39f97425a3d09903d7a54ed3f (diff) | |
download | libgit2-8f759ac0b373eea9dcec680524a68a527d637937.tar.gz |
Merge pull request #2471 from jacquesg/compatibility-cleanup
Compatibility/Portability cleanup
-rw-r--r-- | src/clone.c | 3 | ||||
-rw-r--r-- | src/global.c | 2 | ||||
-rw-r--r-- | src/path.h | 1 | ||||
-rw-r--r-- | src/posix.h | 74 | ||||
-rw-r--r-- | src/transports/winhttp.c | 8 | ||||
-rw-r--r-- | src/unix/posix.h | 32 | ||||
-rw-r--r-- | src/unix/realpath.c | 15 | ||||
-rw-r--r-- | src/win32/mingw-compat.h | 17 | ||||
-rw-r--r-- | src/win32/msvc-compat.h | 35 | ||||
-rw-r--r-- | src/win32/posix.h | 51 | ||||
-rw-r--r-- | src/win32/posix_w32.c | 31 | ||||
-rw-r--r-- | tests/clar_libgit2.h | 3 | ||||
-rw-r--r-- | tests/refs/pack.c | 4 | ||||
-rw-r--r-- | tests/stress/diff.c | 10 | ||||
-rw-r--r-- | tests/threads/refdb.c | 8 |
15 files changed, 158 insertions, 136 deletions
diff --git a/src/clone.c b/src/clone.c index 523b1fe76..7835be1b1 100644 --- a/src/clone.c +++ b/src/clone.c @@ -488,6 +488,9 @@ static const char *repository_base(git_repository *repo) static bool can_link(const char *src, const char *dst, int link) { #ifdef GIT_WIN32 + GIT_UNUSED(src); + GIT_UNUSED(dst); + GIT_UNUSED(link); return false; #else diff --git a/src/global.c b/src/global.c index c72bfe890..f89c73256 100644 --- a/src/global.c +++ b/src/global.c @@ -19,7 +19,9 @@ git_mutex git__mwindow_mutex; #ifdef GIT_SSL # include <openssl/ssl.h> SSL_CTX *git__ssl_ctx; +# ifdef GIT_THREADS static git_mutex *openssl_locks; +# endif #endif static git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB]; diff --git a/src/path.h b/src/path.h index b100af97e..2e86241e1 100644 --- a/src/path.h +++ b/src/path.h @@ -8,6 +8,7 @@ #define INCLUDE_path_h__ #include "common.h" +#include "posix.h" #include "buffer.h" #include "vector.h" diff --git a/src/posix.h b/src/posix.h index 965cd98d5..9ef348739 100644 --- a/src/posix.h +++ b/src/posix.h @@ -12,23 +12,61 @@ #include <time.h> #include "fnmatch.h" +/* stat: file mode type testing macros */ #ifndef S_IFGITLINK #define S_IFGITLINK 0160000 #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK) #endif +#ifndef S_IFLNK +#define S_IFLNK 0120000 +#undef _S_IFLNK +#define _S_IFLNK S_IFLNK +#endif + +#ifndef S_IXUSR +#define S_IXUSR 00100 +#endif + +#ifndef S_ISLNK +#define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) +#endif + +#ifndef S_ISDIR +#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) +#endif + +#ifndef S_ISREG +#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) +#endif + +#ifndef S_ISFIFO +#define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) +#endif + /* if S_ISGID is not defined, then don't try to set it */ #ifndef S_ISGID #define S_ISGID 0 #endif -#if !defined(O_BINARY) +#ifndef O_BINARY #define O_BINARY 0 #endif -#if !defined(O_CLOEXEC) +#ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif +/* access() mode parameter #defines */ +#ifndef F_OK +#define F_OK 0 /* existence check */ +#endif +#ifndef W_OK +#define W_OK 2 /* write mode check */ +#endif +#ifndef R_OK +#define R_OK 4 /* read mode check */ +#endif + /* Determine whether an errno value indicates that a read or write failed * because the descriptor is blocked. */ @@ -38,6 +76,12 @@ #define GIT_ISBLOCKED(e) ((e) == EAGAIN) #endif +/* define some standard errnos that the runtime may be missing. for example, + * mingw lacks EAFNOSUPPORT. */ +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT (INT_MAX-1) +#endif + typedef int git_file; /** @@ -56,8 +100,6 @@ typedef int git_file; extern int p_read(git_file fd, void *buf, size_t cnt); extern int p_write(git_file fd, const void *buf, size_t cnt); -#define p_fstat(f,b) fstat(f, b) -#define p_lseek(f,n,w) lseek(f, n, w) #define p_close(fd) close(fd) #define p_umask(m) umask(m) @@ -66,30 +108,6 @@ extern int p_creat(const char *path, mode_t mode); extern int p_getcwd(char *buffer_out, size_t size); extern int p_rename(const char *from, const char *to); -#ifndef GIT_WIN32 - -#define p_stat(p,b) stat(p, b) -#define p_chdir(p) chdir(p) -#define p_rmdir(p) rmdir(p) -#define p_chmod(p,m) chmod(p, m) -#define p_access(p,m) access(p,m) -#define p_ftruncate(fd, sz) ftruncate(fd, sz) -#define p_recv(s,b,l,f) recv(s,b,l,f) -#define p_send(s,b,l,f) send(s,b,l,f) -typedef int GIT_SOCKET; -#define INVALID_SOCKET -1 - -#define p_localtime_r localtime_r -#define p_gmtime_r gmtime_r - -#else - -typedef SOCKET GIT_SOCKET; -extern struct tm * p_localtime_r (const time_t *timer, struct tm *result); -extern struct tm * p_gmtime_r (const time_t *timer, struct tm *result); - -#endif - /** * Platform-dependent methods */ diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index bd9509cd4..32641cd64 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -36,6 +36,10 @@ #define CACHED_POST_BODY_BUF_SIZE 4096 #define UUID_LENGTH_CCH 32 +#ifndef WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH +#define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0 +#endif + static const char *prefix_http = "http://"; static const char *prefix_https = "https://"; static const char *upload_pack_service = "upload-pack"; @@ -745,9 +749,9 @@ replay: /* Verify that we got the correct content-type back */ if (post_verb == s->verb) - snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-result", s->service); + p_snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-result", s->service); else - snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-advertisement", s->service); + p_snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-advertisement", s->service); if (git__utf8_to_16(expected_content_type, MAX_CONTENT_TYPE_LEN, expected_content_type_8) < 0) { giterr_set(GITERR_OS, "Failed to convert expected content-type to wide characters"); diff --git a/src/unix/posix.h b/src/unix/posix.h index 1e41bcf18..e4f3ac67a 100644 --- a/src/unix/posix.h +++ b/src/unix/posix.h @@ -4,33 +4,47 @@ * This file is part of libgit2, distributed under the GNU GPL v2 with * a Linking Exception. For full terms see the included COPYING file. */ -#ifndef INCLUDE_posix__w32_h__ -#define INCLUDE_posix__w32_h__ +#ifndef INCLUDE_posix__unix_h__ +#define INCLUDE_posix__unix_h__ #include <stdio.h> #include <sys/param.h> +typedef int GIT_SOCKET; +#define INVALID_SOCKET -1 + +#define p_lseek(f,n,w) lseek(f, n, w) +#define p_fstat(f,b) fstat(f, b) #define p_lstat(p,b) lstat(p,b) +#define p_stat(p,b) stat(p, b) + #define p_readlink(a, b, c) readlink(a, b, c) #define p_symlink(o,n) symlink(o, n) #define p_link(o,n) link(o, n) #define p_unlink(p) unlink(p) #define p_mkdir(p,m) mkdir(p, m) #define p_fsync(fd) fsync(fd) +extern char *p_realpath(const char *, char *); -/* The OpenBSD realpath function behaves differently */ -#if !defined(__OpenBSD__) -# define p_realpath(p, po) realpath(p, po) -#else -char *p_realpath(const char *, char *); -#endif +#define p_recv(s,b,l,f) recv(s,b,l,f) +#define p_send(s,b,l,f) send(s,b,l,f) +#define p_inet_pton(a, b, c) inet_pton(a, b, c) +#define p_strcasecmp(s1, s2) strcasecmp(s1, s2) +#define p_strncasecmp(s1, s2, c) strncasecmp(s1, s2, c) #define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a) #define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__) #define p_mkstemp(p) mkstemp(p) -#define p_inet_pton(a, b, c) inet_pton(a, b, c) +#define p_chdir(p) chdir(p) +#define p_chmod(p,m) chmod(p, m) +#define p_rmdir(p) rmdir(p) +#define p_access(p,m) access(p,m) +#define p_ftruncate(fd, sz) ftruncate(fd, sz) /* see win32/posix.h for explanation about why this exists */ #define p_lstat_posixly(p,b) lstat(p,b) +#define p_localtime_r(c, r) localtime_r(c, r) +#define p_gmtime_r(c, r) gmtime_r(c, r) + #endif diff --git a/src/unix/realpath.c b/src/unix/realpath.c index 15601bd22..2e49150c2 100644 --- a/src/unix/realpath.c +++ b/src/unix/realpath.c @@ -6,7 +6,7 @@ */ #include <git2/common.h> -#ifdef __OpenBSD__ +#ifndef GIT_WIN32 #include <limits.h> #include <stdlib.h> @@ -16,15 +16,16 @@ char *p_realpath(const char *pathname, char *resolved) { char *ret; - if ((ret = realpath(pathname, resolved)) == NULL) return NULL; - /* Figure out if the file exists */ - if (!access(ret, F_OK)) - return ret; - - return NULL; +#ifdef __OpenBSD__ + /* The OpenBSD realpath function behaves differently, + * figure out if the file exists */ + if (access(ret, F_OK) < 0) + ret = NULL; +#endif + return ret; } #endif diff --git a/src/win32/mingw-compat.h b/src/win32/mingw-compat.h index 059e39cbc..83ee28765 100644 --- a/src/win32/mingw-compat.h +++ b/src/win32/mingw-compat.h @@ -9,18 +9,11 @@ #if defined(__MINGW32__) -/* use a 64-bit file offset type */ -# undef lseek -# define lseek _lseeki64 -# undef stat -# define stat _stati64 -# undef fstat -# define fstat _fstati64 - -/* stat: file mode type testing macros */ -# define _S_IFLNK 0120000 -# define S_IFLNK _S_IFLNK -# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) +#if _WIN32_WINNT >= 0x0601 +#define stat __stat64 +#else +#define stat _stati64 +#endif #endif diff --git a/src/win32/msvc-compat.h b/src/win32/msvc-compat.h index fa4e2912c..4789d63df 100644 --- a/src/win32/msvc-compat.h +++ b/src/win32/msvc-compat.h @@ -9,41 +9,12 @@ #if defined(_MSC_VER) -/* access() mode parameter #defines */ -# define F_OK 0 /* existence check */ -# define W_OK 2 /* write mode check */ -# define R_OK 4 /* read mode check */ +/* 64-bit stat information, regardless of USE_32BIT_TIME_T define */ +#define stat __stat64 -# define lseek _lseeki64 -# define stat __stat64 -# define fstat _fstat64 - -/* stat: file mode type testing macros */ -# define _S_IFLNK 0120000 -# define S_IFLNK _S_IFLNK -# define S_IXUSR 00100 - -# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) -# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) -# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) -# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) - -# define mode_t unsigned short - -/* case-insensitive string comparison */ -# define strcasecmp _stricmp -# define strncasecmp _strnicmp - -/* MSVC doesn't define ssize_t at all */ +typedef unsigned short mode_t; typedef SSIZE_T ssize_t; -/* define snprintf using variadic macro support if available */ -#if _MSC_VER >= 1500 -# define snprintf(BUF, SZ, FMT, ...) _snprintf_s(BUF, SZ, _TRUNCATE, FMT, __VA_ARGS__) -#else -# define snprintf _snprintf -#endif - #endif #define GIT_STDLIB_CALL __cdecl diff --git a/src/win32/posix.h b/src/win32/posix.h index 22ea6a531..e055a77d0 100644 --- a/src/win32/posix.h +++ b/src/win32/posix.h @@ -12,49 +12,35 @@ #include "utf-conv.h" #include "dir.h" -/* define some standard errnos that the runtime may be missing. for example, - * mingw lacks EAFNOSUPPORT. */ +typedef SOCKET GIT_SOCKET; -#ifndef EAFNOSUPPORT -# define EAFNOSUPPORT (INT_MAX-1) -#endif - -#if defined(_MSC_VER) && _MSC_VER >= 1500 -# define p_ftruncate(fd, sz) _chsize_s(fd, sz) -#else /* MinGW */ -# define p_ftruncate(fd, sz) _chsize(fd, sz) -#endif - -GIT_INLINE(int) p_link(const char *old, const char *new) -{ - GIT_UNUSED(old); - GIT_UNUSED(new); - errno = ENOSYS; - return -1; -} - -extern int p_mkdir(const char *path, mode_t mode); -extern int p_unlink(const char *path); +#define p_lseek(f,n,w) _lseeki64(f, n, w) +#define p_fstat(f,b) _fstat64(f, b) extern int p_lstat(const char *file_name, struct stat *buf); +extern int p_stat(const char* path, struct stat* buf); + extern int p_readlink(const char *path, char *buf, size_t bufsiz); extern int p_symlink(const char *old, const char *new); +extern int p_link(const char *old, const char *new); +extern int p_unlink(const char *path); +extern int p_mkdir(const char *path, mode_t mode); +extern int p_fsync(int fd); extern char *p_realpath(const char *orig_path, char *buffer); + +extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags); +extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags); +extern int p_inet_pton(int af, const char* src, void* dst); + +#define strcasecmp(s1, s2) _stricmp(s1, s2) +#define strncasecmp(s1, s2, c) _strnicmp(s1, s2, c) extern int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr); extern int p_snprintf(char *buffer, size_t count, const char *format, ...) GIT_FORMAT_PRINTF(3, 4); extern int p_mkstemp(char *tmp_path); -extern int p_stat(const char* path, struct stat* buf); extern int p_chdir(const char* path); extern int p_chmod(const char* path, mode_t mode); extern int p_rmdir(const char* path); extern int p_access(const char* path, mode_t mode); -extern int p_fsync(int fd); -extern int p_open(const char *path, int flags, ...); -extern int p_creat(const char *path, mode_t mode); -extern int p_getcwd(char *buffer_out, size_t size); -extern int p_rename(const char *from, const char *to); -extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags); -extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags); -extern int p_inet_pton(int af, const char* src, void* dst); +extern int p_ftruncate(int fd, long size); /* p_lstat is almost but not quite POSIX correct. Specifically, the use of * ENOTDIR is wrong, in that it does not mean precisely that a non-directory @@ -64,4 +50,7 @@ extern int p_inet_pton(int af, const char* src, void* dst); */ extern int p_lstat_posixly(const char *filename, struct stat *buf); +extern struct tm * p_localtime_r (const time_t *timer, struct tm *result); +extern struct tm * p_gmtime_r (const time_t *timer, struct tm *result); + #endif diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index a74fcaad1..0023f95ff 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -51,6 +51,15 @@ static int utf8_to_16_with_errno(git_win32_path dest, const char *src) return len; } +int p_ftruncate(int fd, long size) +{ +#if defined(_MSC_VER) && _MSC_VER >= 1500 + return _chsize_s(fd, size); +#else + return _chsize(fd, size); +#endif +} + int p_mkdir(const char *path, mode_t mode) { git_win32_path buf; @@ -63,6 +72,14 @@ int p_mkdir(const char *path, mode_t mode) return _wmkdir(buf); } +int p_link(const char *old, const char *new) +{ + GIT_UNUSED(old); + GIT_UNUSED(new); + errno = ENOSYS; + return -1; +} + int p_unlink(const char *path) { git_win32_path buf; @@ -547,11 +564,19 @@ char *p_realpath(const char *orig_path, char *buffer) int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr) { -#if defined(_MSC_VER) && _MSC_VER >= 1500 +#if defined(_MSC_VER) int len; - if (count == 0 || - (len = _vsnprintf_s(buffer, count, _TRUNCATE, format, argptr)) < 0) + if (count == 0) + return _vscprintf(format, argptr); + + #if _MSC_VER >= 1500 + len = _vsnprintf_s(buffer, count, _TRUNCATE, format, argptr); + #else + len = _vsnprintf(buffer, count, format, argptr); + #endif + + if (len < 0) return _vscprintf(format, argptr); return len; diff --git a/tests/clar_libgit2.h b/tests/clar_libgit2.h index 0744877cb..f51554293 100644 --- a/tests/clar_libgit2.h +++ b/tests/clar_libgit2.h @@ -3,6 +3,7 @@ #include "clar.h" #include <git2.h> +#include <posix.h> #include "common.h" /** @@ -51,7 +52,7 @@ GIT_INLINE(void) clar__assert_in_range( { if (lo > val || hi < val) { char buf[128]; - snprintf(buf, sizeof(buf), "%d not in [%d,%d]", val, lo, hi); + p_snprintf(buf, sizeof(buf), "%d not in [%d,%d]", val, lo, hi); clar__fail(file, line, err, buf, should_abort); } } diff --git a/tests/refs/pack.c b/tests/refs/pack.c index 7f5c611a7..dbe377d7f 100644 --- a/tests/refs/pack.c +++ b/tests/refs/pack.c @@ -91,12 +91,12 @@ void test_refs_pack__symbolic(void) /* make a bunch of references */ for (i = 0; i < 100; ++i) { - snprintf(name, sizeof(name), "refs/heads/symbolic-%03d", i); + p_snprintf(name, sizeof(name), "refs/heads/symbolic-%03d", i); cl_git_pass(git_reference_symbolic_create( &ref, g_repo, name, "refs/heads/master", 0, NULL, NULL)); git_reference_free(ref); - snprintf(name, sizeof(name), "refs/heads/direct-%03d", i); + p_snprintf(name, sizeof(name), "refs/heads/direct-%03d", i); cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL)); git_reference_free(ref); } diff --git a/tests/stress/diff.c b/tests/stress/diff.c index 3d2092614..0dda44d30 100644 --- a/tests/stress/diff.c +++ b/tests/stress/diff.c @@ -97,14 +97,14 @@ void test_stress_diff__rename_big_files(void) cl_git_pass(git_repository_index(&index, g_repo)); for (i = 0; i < 100; i += 1) { - snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i); + p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i); for (j = i * 256; j > 0; --j) git_buf_printf(&b, "more content %d\n", i); cl_git_mkfile(tmp, b.ptr); } for (i = 0; i < 100; i += 1) { - snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i); + p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i); cl_git_pass(git_index_add_bypath(index, tmp + strlen("renames/"))); } @@ -128,15 +128,15 @@ void test_stress_diff__rename_many_files(void) git_buf_printf(&b, "%08d\n" ANOTHER_POEM "%08d\n" ANOTHER_POEM ANOTHER_POEM, 0, 0); for (i = 0; i < 2500; i += 1) { - snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i); - snprintf(b.ptr, 9, "%08d", i); + p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i); + p_snprintf(b.ptr, 9, "%08d", i); b.ptr[8] = '\n'; cl_git_mkfile(tmp, b.ptr); } git_buf_free(&b); for (i = 0; i < 2500; i += 1) { - snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i); + p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i); cl_git_pass(git_index_add_bypath(index, tmp + strlen("renames/"))); } diff --git a/tests/threads/refdb.c b/tests/threads/refdb.c index 94a21f259..078267aa8 100644 --- a/tests/threads/refdb.c +++ b/tests/threads/refdb.c @@ -58,7 +58,7 @@ void test_threads_refdb__iterator(void) /* make a bunch of references */ for (r = 0; r < 200; ++r) { - snprintf(name, sizeof(name), "refs/heads/direct-%03d", r); + p_snprintf(name, sizeof(name), "refs/heads/direct-%03d", r); cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL)); git_reference_free(ref); } @@ -102,7 +102,7 @@ static void *create_refs(void *arg) cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD")); for (i = 0; i < 10; ++i) { - snprintf(name, sizeof(name), "refs/heads/thread-%03d-%02d", *id, i); + p_snprintf(name, sizeof(name), "refs/heads/thread-%03d-%02d", *id, i); cl_git_pass(git_reference_create(&ref[i], g_repo, name, &head, 0, NULL, NULL)); if (i == 5) { @@ -127,7 +127,7 @@ static void *delete_refs(void *arg) char name[128]; for (i = 0; i < 10; ++i) { - snprintf( + p_snprintf( name, sizeof(name), "refs/heads/thread-%03d-%02d", (*id) & ~0x3, i); if (!git_reference_lookup(&ref, g_repo, name)) { @@ -167,7 +167,7 @@ void test_threads_refdb__edit_while_iterate(void) /* make a bunch of references */ for (r = 0; r < 50; ++r) { - snprintf(name, sizeof(name), "refs/heads/starter-%03d", r); + p_snprintf(name, sizeof(name), "refs/heads/starter-%03d", r); cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL)); git_reference_free(ref); } |