8#ifndef INCLUDED_BDLS_FILESYSTEMUTIL_WINDOWSIMPUTIL
9#define INCLUDED_BDLS_FILESYSTEMUTIL_WINDOWSIMPUTIL
58#include <bdlt_datetime.h>
136template <
class WINDOWS_INTERFACE>
147 typedef typename WINDOWS_INTERFACE::INT64
Offset;
154 typedef typename WINDOWS_INTERFACE::BOOL BOOL;
158 typedef typename WINDOWS_INTERFACE::DWORD DWORD;
162 typedef typename WINDOWS_INTERFACE::FILETIME FILETIME;
166 typedef typename WINDOWS_INTERFACE::HANDLE HANDLE;
170 typedef typename WINDOWS_INTERFACE::INT64 INT64;
174 typedef typename WINDOWS_INTERFACE::LPDWORD LPDWORD;
178 typedef typename WINDOWS_INTERFACE::LPFILETIME LPFILETIME;
182 typedef typename WINDOWS_INTERFACE::LPSYSTEMTIME LPSYSTEMTIME;
186 typedef typename WINDOWS_INTERFACE::SYSTEMTIME SYSTEMTIME;
190 typedef typename WINDOWS_INTERFACE::ULARGE_INTEGER ULARGE_INTEGER;
194 typedef typename WINDOWS_INTERFACE::ULONG64 ULONG64;
198 typedef typename WINDOWS_INTERFACE::ULONGLONG ULONGLONG;
202 typedef typename WINDOWS_INTERFACE::WORD WORD;
211 static BOOL FileTimeToSystemTime(
const FILETIME *lpFileTime,
212 LPSYSTEMTIME lpSystemTime);
218 static DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
225 static BOOL GetFileTime(HANDLE hFile,
226 LPFILETIME lpCreationTime,
227 LPFILETIME lpLastAccessTime,
228 LPFILETIME lpLastWriteTime);
232 static DWORD GetLastError();
239 static BOOL SystemTimeToFileTime(
const SYSTEMTIME *lpSystemTime,
240 LPFILETIME lpFileTime);
256 const LPFILETIME lpFileTime);
279template <
class WINDOWS_INTERFACE>
280typename WINDOWS_INTERFACE::BOOL
282 const FILETIME *lpFileTime,
283 LPSYSTEMTIME lpSystemTime)
285 return WINDOWS_INTERFACE::FileTimeToSystemTime(lpFileTime, lpSystemTime);
288template <
class WINDOWS_INTERFACE>
289typename WINDOWS_INTERFACE::DWORD
290FilesystemUtil_WindowsImpUtil<WINDOWS_INTERFACE>::GetFileSize(
292 LPDWORD lpFileSizeHigh)
294 return WINDOWS_INTERFACE::GetFileSize(hFile, lpFileSizeHigh);
297template <
class WINDOWS_INTERFACE>
298typename WINDOWS_INTERFACE::BOOL
299FilesystemUtil_WindowsImpUtil<WINDOWS_INTERFACE>::GetFileTime(
301 LPFILETIME lpCreationTime,
302 LPFILETIME lpLastAccessTime,
303 LPFILETIME lpLastWriteTime)
305 return WINDOWS_INTERFACE::GetFileTime(
306 hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime);
309template <
class WINDOWS_INTERFACE>
310typename WINDOWS_INTERFACE::DWORD
311FilesystemUtil_WindowsImpUtil<WINDOWS_INTERFACE>::GetLastError()
313 return WINDOWS_INTERFACE::GetLastError();
316template <
class WINDOWS_INTERFACE>
317typename WINDOWS_INTERFACE::BOOL
318FilesystemUtil_WindowsImpUtil<WINDOWS_INTERFACE>::SystemTimeToFileTime(
319 const SYSTEMTIME *lpSystemTime,
320 LPFILETIME lpFileTime)
322 return WINDOWS_INTERFACE::SystemTimeToFileTime(lpSystemTime, lpFileTime);
326template <
class WINDOWS_INTERFACE>
330 const LPFILETIME lpFileTime)
342 static ULONGLONG adjustedFiletimeEpochToUnixEpochInMicros;
346 const SYSTEMTIME unixEpochSystemTimeUtc =
358 FILETIME unixEpochFileTimeUtc;
359 const BOOL systemTimeToFileTimeStatus = SystemTimeToFileTime(
360 &unixEpochSystemTimeUtc,
361 &unixEpochFileTimeUtc);
362 if (!systemTimeToFileTimeStatus) {
368 ULARGE_INTEGER unixEpochFileTimeInTicks;
369 unixEpochFileTimeInTicks.u.HighPart =
370 unixEpochFileTimeUtc.dwHighDateTime;
371 unixEpochFileTimeInTicks.u.LowPart =
372 unixEpochFileTimeUtc.dwLowDateTime;
374 adjustedFiletimeEpochToUnixEpochInMicros =
375 unixEpochFileTimeInTicks.QuadPart /
376 k_WINDOWS_TICKS_PER_MICROSECOND;
380 ULARGE_INTEGER lastWriteTimeInTicks;
381 lastWriteTimeInTicks.u.HighPart = lpFileTime->dwHighDateTime;
382 lastWriteTimeInTicks.u.LowPart = lpFileTime->dwLowDateTime;
384 ULONGLONG lastWriteTimeInMicroseconds = lastWriteTimeInTicks.QuadPart /
385 k_WINDOWS_TICKS_PER_MICROSECOND;
387 if (lastWriteTimeInMicroseconds <
388 adjustedFiletimeEpochToUnixEpochInMicros) {
396 adjustedFiletimeEpochToUnixEpochInMicros);
406template <
class WINDOWS_INTERFACE>
412 BSLS_ASSERT(0 == bsl::numeric_limits<DWORD>::min());
413 BSLS_ASSERT(0xFFFFFFFFul == bsl::numeric_limits<DWORD>::max());
416 BSLS_ASSERT(0 == bsl::numeric_limits<ULONG64>::min());
417 BSLS_ASSERT(0xFFFFFFFFFFFFFFFFull == bsl::numeric_limits<ULONG64>::max());
431 DWORD sizeHigh32Bits;
432 const DWORD sizeLow32Bits = GetFileSize(descriptor, &sizeHigh32Bits);
439 static const DWORD k_INVALID_FILE_SIZE = 0xFFFFFFFFul;
440 if (k_INVALID_FILE_SIZE == sizeLow32Bits) {
441 const DWORD lastError = GetLastError();
443 static const DWORD k_NO_ERROR = 0;
444 if (k_NO_ERROR != lastError) {
449 const ULONG64 uSizeHigh32Bits =
static_cast<ULONG64
>(sizeHigh32Bits);
450 const ULONG64 uSizeLow32Bits =
static_cast<ULONG64
>(sizeLow32Bits);
451 const ULONG64 uSize64Bits = (uSizeHigh32Bits << 32) | uSizeLow32Bits;
453 return static_cast<Offset>(uSize64Bits);
456template <
class WINDOWS_INTERFACE>
461 static const LPFILETIME s_IGNORED_CREATION_TIME = 0;
462 static const LPFILETIME s_IGNORED_LAST_ACCESS_TIME = 0;
464 FILETIME lastWriteTime;
465 const BOOL getFileTimeSuccessFlag = GetFileTime(descriptor,
466 s_IGNORED_CREATION_TIME,
467 s_IGNORED_LAST_ACCESS_TIME,
469 if (!getFileTimeSuccessFlag) {
473 return convertFileTimeToDatetime(time, &lastWriteTime);
Definition bdlt_datetime.h:331
int addMicrosecondsIfValid(bsls::Types::Int64 microseconds)
Definition bdlt_datetime.h:2103
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLMT_ONCE_DO
Definition bslmt_once.h:425
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdls_fdstreambuf.h:412
Definition bdls_filesystemutil_windowsimputil.h:137
static int getLastModificationTime(bdlt::Datetime *time, FileDescriptor descriptor)
Definition bdls_filesystemutil_windowsimputil.h:457
static const bsls::Types::Int64 k_WINDOWS_TICKS_PER_MICROSECOND
Definition bdls_filesystemutil_windowsimputil.h:246
static const bsls::Types::Int64 k_NANOSECONDS_PER_WINDOWS_TICK
Definition bdls_filesystemutil_windowsimputil.h:244
WINDOWS_INTERFACE::HANDLE FileDescriptor
Definition bdls_filesystemutil_windowsimputil.h:143
WINDOWS_INTERFACE::INT64 Offset
Definition bdls_filesystemutil_windowsimputil.h:147
static Offset getFileSize(FileDescriptor descriptor)
Definition bdls_filesystemutil_windowsimputil.h:408
static int convertFileTimeToDatetime(bdlt::Datetime *time, const LPFILETIME lpFileTime)
Definition bdls_filesystemutil_windowsimputil.h:328
static const Datetime & epoch()
Definition bdlt_epochutil.h:375
static const bsls::Types::Int64 k_NANOSECONDS_PER_MICROSECOND
Definition bdlt_timeunitratio.h:205
Definition bslmf_isintegral.h:130
long long Int64
Definition bsls_types.h:132