summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2015-09-29 13:36:37 -0400
committerCarlos Martín Nieto <cmn@dwim.me>2015-11-04 17:07:12 -0800
commitcd768280dbcc52dd349462c5f17ccfe89f461326 (patch)
tree3f67bfa1105456f8f4c356572b2147d4851dd43e
parent08a2a939c2a6073bed5292ab23f48eabf1244166 (diff)
downloadlibgit2-cd768280dbcc52dd349462c5f17ccfe89f461326.tar.gz
p_futimes: support using futimens when available
-rw-r--r--CMakeLists.txt6
-rw-r--r--src/unix/posix.h15
2 files changed, 20 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8d47358de..c4d70fc42 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)
@@ -447,6 +448,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