Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba1a555

Browse files
committed
Merge pull request libgit2#3446 from ethomson/portability
portability: use `CHECK_FUNCTION_EXISTS` for checking whether functions exist...
2 parents e8ccdd6 + e683d15 commit ba1a555

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ CMAKE_POLICY(SET CMP0015 NEW)
1919
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
2020

2121
INCLUDE(CheckLibraryExists)
22+
INCLUDE(CheckFunctionExists)
2223
INCLUDE(AddCFlagIfSupported)
2324
INCLUDE(FindPkgConfig)
2425

@@ -469,6 +470,21 @@ ELSE ()
469470
ENDIF ()
470471
ENDIF()
471472

473+
CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS)
474+
IF (HAVE_FUTIMENS)
475+
ADD_DEFINITIONS(-DHAVE_FUTIMENS)
476+
ENDIF ()
477+
478+
CHECK_FUNCTION_EXISTS(qsort_r HAVE_QSORT_R)
479+
IF (HAVE_QSORT_R)
480+
ADD_DEFINITIONS(-DHAVE_QSORT_R)
481+
ENDIF ()
482+
483+
CHECK_FUNCTION_EXISTS(qsort_s HAVE_QSORT_S)
484+
IF (HAVE_QSORT_S)
485+
ADD_DEFINITIONS(-DHAVE_QSORT_S)
486+
ENDIF ()
487+
472488
IF( NOT CMAKE_CONFIGURATION_TYPES )
473489
# Build Debug by default
474490
IF (NOT CMAKE_BUILD_TYPE)

src/unix/posix.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ typedef int GIT_SOCKET;
2222
#define p_stat(p,b) stat(p, b)
2323

2424
#define p_utimes(f, t) utimes(f, t)
25-
#define p_futimes(f, t) futimes(f, t)
2625

2726
#define p_readlink(a, b, c) readlink(a, b, c)
2827
#define p_symlink(o,n) symlink(o, n)
@@ -53,4 +52,18 @@ extern char *p_realpath(const char *, char *);
5352
#define p_localtime_r(c, r) localtime_r(c, r)
5453
#define p_gmtime_r(c, r) gmtime_r(c, r)
5554

55+
#ifdef HAVE_FUTIMENS
56+
GIT_INLINE(int) p_futimes(int f, const struct timeval t[2])
57+
{
58+
struct timespec s[2];
59+
s[0].tv_sec = t[0].tv_sec;
60+
s[0].tv_nsec = t[0].tv_usec * 1000;
61+
s[1].tv_sec = t[1].tv_sec;
62+
s[1].tv_nsec = t[1].tv_usec * 1000;
63+
return futimens(f, s);
64+
}
65+
#else
66+
# define p_futimes futimes
67+
#endif
68+
5669
#endif

src/util.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ size_t git__unescape(char *str)
611611
return (pos - str);
612612
}
613613

614-
#if defined(GIT_WIN32) || defined(BSD)
614+
#if defined(HAVE_QSORT_S) || (defined(HAVE_QSORT_R) && defined(BSD))
615615
typedef struct {
616616
git__sort_r_cmp cmp;
617617
void *payload;
@@ -628,21 +628,16 @@ static int GIT_STDLIB_CALL git__qsort_r_glue_cmp(
628628
void git__qsort_r(
629629
void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload)
630630
{
631-
#if defined(__MINGW32__) || defined(AMIGA) || \
632-
defined(__OpenBSD__) || defined(__NetBSD__) || \
633-
defined(__gnu_hurd__) || defined(__ANDROID_API__) || \
634-
defined(__sun) || defined(__CYGWIN__) || \
635-
(__GLIBC__ == 2 && __GLIBC_MINOR__ < 8) || \
636-
(defined(_MSC_VER) && _MSC_VER < 1500)
637-
git__insertsort_r(els, nel, elsize, NULL, cmp, payload);
638-
#elif defined(GIT_WIN32)
639-
git__qsort_r_glue glue = { cmp, payload };
640-
qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue);
641-
#elif defined(BSD)
631+
#if defined(HAVE_QSORT_R) && defined(BSD)
642632
git__qsort_r_glue glue = { cmp, payload };
643633
qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp);
644-
#else
634+
#elif defined(HAVE_QSORT_R) && defined(__GLIBC__)
645635
qsort_r(els, nel, elsize, cmp, payload);
636+
#elif defined(HAVE_QSORT_S)
637+
git__qsort_r_glue glue = { cmp, payload };
638+
qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue);
639+
#else
640+
git__insertsort_r(els, nel, elsize, NULL, cmp, payload);
646641
#endif
647642
}
648643

0 commit comments

Comments
 (0)