diff options
Diffstat (limited to 'src/VBox/Runtime/r3/posix/fileio2-posix.cpp')
-rw-r--r-- | src/VBox/Runtime/r3/posix/fileio2-posix.cpp | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/VBox/Runtime/r3/posix/fileio2-posix.cpp b/src/VBox/Runtime/r3/posix/fileio2-posix.cpp index 47c13697..33e10e35 100644 --- a/src/VBox/Runtime/r3/posix/fileio2-posix.cpp +++ b/src/VBox/Runtime/r3/posix/fileio2-posix.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2011 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -46,16 +46,15 @@ #if defined(RT_OS_OS2) && (!defined(__INNOTEK_LIBC__) || __INNOTEK_LIBC__ < 0x006) # include <io.h> #endif -#ifdef RT_OS_L4 -/* This is currently ifdef'ed out in the relevant L4 header file */ -/* Same as `utimes', but takes an open file descriptor instead of a name. */ -extern int futimes(int __fd, __const struct timeval __tvp[2]) __THROW; -#endif #ifdef RT_OS_SOLARIS # define futimes(filedes, timeval) futimesat(filedes, NULL, timeval) #endif +#ifdef RT_OS_HAIKU +# define USE_FUTIMENS +#endif + #include <iprt/file.h> #include <iprt/path.h> #include <iprt/assert.h> @@ -143,6 +142,30 @@ RTR3DECL(int) RTFileSetTimes(RTFILE hFile, PCRTTIMESPEC pAccessTime, PCRTTIMESPE if (!pAccessTime && !pModificationTime) return VINF_SUCCESS; +#ifdef USE_FUTIMENS + struct timespec aTimespecs[2]; + if (pAccessTime && pModificationTime) + { + memcpy(&aTimespecs[0], pAccessTime, sizeof(struct timespec)); + memcpy(&aTimespecs[1], pModificationTime, sizeof(struct timespec)); + } + else + { + RTFSOBJINFO ObjInfo; + int rc = RTFileQueryInfo(hFile, &ObjInfo, RTFSOBJATTRADD_UNIX); + if (RT_FAILURE(rc)) + return rc; + memcpy(&aTimespecs[0], pAccessTime ? pAccessTime : &ObjInfo.AccessTime, sizeof(struct timespec)); + memcpy(&aTimespecs[1], pModificationTime ? pModificationTime : &ObjInfo.ModificationTime, sizeof(struct timespec)); + } + + if (futimens(RTFileToNative(hFile), aTimespecs)) + { + int rc = RTErrConvertFromErrno(errno); + Log(("RTFileSetTimes(%RTfile,%p,%p,,): returns %Rrc\n", hFile, pAccessTime, pModificationTime, rc)); + return rc; + } +#else /* * Convert the input to timeval, getting the missing one if necessary, * and call the API which does the change. @@ -171,6 +194,7 @@ RTR3DECL(int) RTFileSetTimes(RTFILE hFile, PCRTTIMESPEC pAccessTime, PCRTTIMESPE Log(("RTFileSetTimes(%RTfile,%p,%p,,): returns %Rrc\n", hFile, pAccessTime, pModificationTime, rc)); return rc; } +#endif return VINF_SUCCESS; } |