From 855a6cb6767a7759f00f52acf501fabb38bc1243 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Thu, 2 Mar 2023 00:24:21 +0200 Subject: [PATCH] Use utimensat instead of utimes From the manual page: Note: modern applications may prefer to use the interfaces described in utimensat(2). Change-Id: Ib20d8b9b50626233852ca351452ce90841a39603 Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp index f36334db02f..aa40353c991 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp @@ -16,6 +16,8 @@ #include #if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS) #include + +#include // utimensat #include #elif defined(Q_OS_WIN) # include @@ -516,7 +518,7 @@ void tst_QLockFile::corruptedLockFile() void tst_QLockFile::corruptedLockFileInTheFuture() { #if !defined(Q_OS_UNIX) - QSKIP("This tests needs utimes"); + QSKIP("This test needs utimensat"); #else // This test is the same as the previous one, but the corruption was so there is a corrupted // .rmlock whose timestamp is in the future @@ -528,11 +530,12 @@ void tst_QLockFile::corruptedLockFileInTheFuture() QVERIFY(file.open(QFile::WriteOnly)); } - struct timeval times[2]; - gettimeofday(times, 0); - times[1].tv_sec = (times[0].tv_sec += 600); - times[1].tv_usec = times[0].tv_usec; - utimes(fileName.toLocal8Bit(), times); + struct timespec times[2]; + clock_gettime(CLOCK_REALTIME, times); + times[0].tv_sec += 600; + times[1].tv_sec = times[0].tv_sec; + times[1].tv_nsec = times[0].tv_nsec; + utimensat(0 /* ignored */, fileName.toLocal8Bit(), times, 0); QTest::ignoreMessage(QtInfoMsg, "QLockFile: Lock file '" + fileName.toUtf8() + "' has a modification time in the future"); corruptedLockFile();