use utimensat if available

This commit is contained in:
Valient Gough 2016-05-13 13:33:23 -07:00
parent e19f4a8c69
commit ad43aa10b2
No known key found for this signature in database
GPG Key ID: B515DCEB95967051
2 changed files with 6 additions and 1 deletions

View File

@ -83,9 +83,10 @@ check_cxx_source_compiles ("#include <sys/types.h>
" 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)

View File

@ -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;
}