From 8649dfd8df4f0d840a64c1d6c5fc80b8e94a68d1 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 29 Sep 2015 13:36:37 -0400 Subject: [PATCH 1/2] p_futimes: support using futimens when available --- CMakeLists.txt | 6 ++++++ src/unix/posix.h | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c03c718c..a0ef89f76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ CMAKE_POLICY(SET CMP0015 NEW) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") INCLUDE(CheckLibraryExists) +INCLUDE(CheckFunctionExists) INCLUDE(AddCFlagIfSupported) INCLUDE(FindPkgConfig) @@ -431,6 +432,11 @@ ELSE () ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-const-variable) ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-function) + CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS) + IF (HAVE_FUTIMENS) + ADD_DEFINITIONS(-DHAVE_FUTIMENS) + ENDIF () + IF (APPLE) # Apple deprecated OpenSSL ADD_C_FLAG_IF_SUPPORTED(-Wno-deprecated-declarations) ENDIF() diff --git a/src/unix/posix.h b/src/unix/posix.h index 777350990..6633689bc 100644 --- a/src/unix/posix.h +++ b/src/unix/posix.h @@ -22,7 +22,6 @@ typedef int GIT_SOCKET; #define p_stat(p,b) stat(p, b) #define p_utimes(f, t) utimes(f, t) -#define p_futimes(f, t) futimes(f, t) #define p_readlink(a, b, c) readlink(a, b, c) #define p_symlink(o,n) symlink(o, n) @@ -53,4 +52,18 @@ extern char *p_realpath(const char *, char *); #define p_localtime_r(c, r) localtime_r(c, r) #define p_gmtime_r(c, r) gmtime_r(c, r) +#ifdef HAVE_FUTIMENS +GIT_INLINE(int) p_futimes(int f, const struct timeval t[2]) +{ + struct timespec s[2]; + s[0].tv_sec = t[0].tv_sec; + s[0].tv_nsec = t[0].tv_usec * 1000; + s[1].tv_sec = t[1].tv_sec; + s[1].tv_nsec = t[1].tv_usec * 1000; + return futimens(f, s); +} +#else +# define p_futimes futimes +#endif + #endif From e683d15247ef7231143b46580f07113ecae43773 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 30 Sep 2015 05:49:04 -0400 Subject: [PATCH 2/2] qsort_r/qsort_s: detect their support --- CMakeLists.txt | 20 +++++++++++++++----- src/util.c | 21 ++++++++------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0ef89f76..e6c06413b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -432,11 +432,6 @@ ELSE () ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-const-variable) ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-function) - CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS) - IF (HAVE_FUTIMENS) - ADD_DEFINITIONS(-DHAVE_FUTIMENS) - ENDIF () - IF (APPLE) # Apple deprecated OpenSSL ADD_C_FLAG_IF_SUPPORTED(-Wno-deprecated-declarations) ENDIF() @@ -447,6 +442,21 @@ ELSE () ENDIF () ENDIF() +CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS) +IF (HAVE_FUTIMENS) + ADD_DEFINITIONS(-DHAVE_FUTIMENS) +ENDIF () + +CHECK_FUNCTION_EXISTS(qsort_r HAVE_QSORT_R) +IF (HAVE_QSORT_R) + ADD_DEFINITIONS(-DHAVE_QSORT_R) +ENDIF () + +CHECK_FUNCTION_EXISTS(qsort_s HAVE_QSORT_S) +IF (HAVE_QSORT_S) + ADD_DEFINITIONS(-DHAVE_QSORT_S) +ENDIF () + IF( NOT CMAKE_CONFIGURATION_TYPES ) # Build Debug by default IF (NOT CMAKE_BUILD_TYPE) diff --git a/src/util.c b/src/util.c index b3929bca2..9e67f4347 100644 --- a/src/util.c +++ b/src/util.c @@ -611,7 +611,7 @@ size_t git__unescape(char *str) return (pos - str); } -#if defined(GIT_WIN32) || defined(BSD) +#if defined(HAVE_QSORT_S) || (defined(HAVE_QSORT_R) && defined(BSD)) typedef struct { git__sort_r_cmp cmp; void *payload; @@ -628,21 +628,16 @@ static int GIT_STDLIB_CALL git__qsort_r_glue_cmp( void git__qsort_r( void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload) { -#if defined(__MINGW32__) || defined(AMIGA) || \ - defined(__OpenBSD__) || defined(__NetBSD__) || \ - defined(__gnu_hurd__) || defined(__ANDROID_API__) || \ - defined(__sun) || defined(__CYGWIN__) || \ - (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8) || \ - (defined(_MSC_VER) && _MSC_VER < 1500) - git__insertsort_r(els, nel, elsize, NULL, cmp, payload); -#elif defined(GIT_WIN32) - git__qsort_r_glue glue = { cmp, payload }; - qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue); -#elif defined(BSD) +#if defined(HAVE_QSORT_R) && defined(BSD) git__qsort_r_glue glue = { cmp, payload }; qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp); -#else +#elif defined(HAVE_QSORT_R) && defined(__GLIBC__) qsort_r(els, nel, elsize, cmp, payload); +#elif defined(HAVE_QSORT_S) + git__qsort_r_glue glue = { cmp, payload }; + qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue); +#else + git__insertsort_r(els, nel, elsize, NULL, cmp, payload); #endif }