From ad43aa10b27f8ce0f88f8167515b1be5685157e3 Mon Sep 17 00:00:00 2001 From: Valient Gough Date: Fri, 13 May 2016 13:33:23 -0700 Subject: [PATCH] use utimensat if available --- CMakeLists.txt | 3 ++- encfs/encfs.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ecffbaa..aa37223 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,9 +83,10 @@ check_cxx_source_compiles ("#include " XATTR_ADD_OPT) set (CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) -# Check if we have lchmod. +# Check if we have some standard functions. include (CheckFuncs) check_function_exists_glibc (lchmod HAVE_LCHMOD) +check_function_exists_glibc (utimensat HAVE_UTIMENSAT) set (CMAKE_THREAD_PREFER_PTHREAD) find_package (Threads REQUIRED) diff --git a/encfs/encfs.cpp b/encfs/encfs.cpp index c97a545..31d3e7d 100644 --- a/encfs/encfs.cpp +++ b/encfs/encfs.cpp @@ -497,6 +497,9 @@ int encfs_utime(const char *path, struct utimbuf *buf) { int _do_utimens(EncFS_Context *, const string &cyName, const struct timespec ts[2]) { +#ifdef HAVE_UTIMENSAT + int res = utimensat(AT_FDCWD, cyName.c_str(), ts, AT_SYMLINK_NOFOLLOW); +#else struct timeval tv[2]; tv[0].tv_sec = ts[0].tv_sec; tv[0].tv_usec = ts[0].tv_nsec / 1000; @@ -504,6 +507,7 @@ int _do_utimens(EncFS_Context *, const string &cyName, tv[1].tv_usec = ts[1].tv_nsec / 1000; int res = lutimes(cyName.c_str(), tv); +#endif return (res == -1) ? -errno : ESUCCESS; }