summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-05-08 15:47:04 +0200
committerMax Kellermann <max@musicpd.org>2019-05-08 16:02:13 +0200
commit5641c4baa6b304a6e9dba21c5a972be363117aeb (patch)
treebeb05ab7d69e45d284b7f150e0778f8c38d8103b
parent96f889276f95a7c9b9882f53423556e1bf17e6a2 (diff)
system/Clock, fs/FileInfo: move FILETIME specific code to time/FileTime.hxx
-rw-r--r--src/fs/FileInfo.hxx26
-rw-r--r--src/system/Clock.cxx16
-rw-r--r--src/time/FileTime.hxx71
3 files changed, 75 insertions, 38 deletions
diff --git a/src/fs/FileInfo.hxx b/src/fs/FileInfo.hxx
index acd915248..b8a2c54a6 100644
--- a/src/fs/FileInfo.hxx
+++ b/src/fs/FileInfo.hxx
@@ -24,7 +24,7 @@
#include "system/Error.hxx"
#ifdef _WIN32
-#include <fileapi.h>
+#include "time/FileTime.hxx"
#else
#include <sys/stat.h>
#endif
@@ -33,30 +33,6 @@
#include <stdint.h>
-#ifdef _WIN32
-
-static constexpr uint64_t
-ConstructUint64(DWORD lo, DWORD hi)
-{
- return uint64_t(lo) | (uint64_t(hi) << 32);
-}
-
-static constexpr time_t
-FileTimeToTimeT(FILETIME ft)
-{
- return (ConstructUint64(ft.dwLowDateTime, ft.dwHighDateTime)
- - 116444736000000000) / 10000000;
-}
-
-static std::chrono::system_clock::time_point
-FileTimeToChrono(FILETIME ft)
-{
- // TODO: eliminate the time_t roundtrip, preserve sub-second resolution
- return std::chrono::system_clock::from_time_t(FileTimeToTimeT(ft));
-}
-
-#endif
-
class FileInfo {
friend bool GetFileInfo(Path path, FileInfo &info,
bool follow_symlinks);
diff --git a/src/system/Clock.cxx b/src/system/Clock.cxx
index a4dc9ef89..2fe5d73cf 100644
--- a/src/system/Clock.cxx
+++ b/src/system/Clock.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2018 The Music Player Daemon Project
+ * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,19 +20,9 @@
#include "Clock.hxx"
#ifdef _WIN32
-#include <windows.h>
+#include "time/FileTime.hxx"
-gcc_const
-static std::chrono::seconds
-DeltaFileTimeS(FILETIME a, FILETIME b)
-{
- ULARGE_INTEGER a2, b2;
- b2.LowPart = b.dwLowDateTime;
- b2.HighPart = b.dwHighDateTime;
- a2.LowPart = a.dwLowDateTime;
- a2.HighPart = a.dwHighDateTime;
- return std::chrono::seconds((a2.QuadPart - b2.QuadPart) / 10000000);
-}
+#include <windows.h>
std::chrono::seconds
GetProcessUptimeS()
diff --git a/src/time/FileTime.hxx b/src/time/FileTime.hxx
new file mode 100644
index 000000000..da18b13f7
--- /dev/null
+++ b/src/time/FileTime.hxx
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2013-2019 Max Kellermann <max.kellermann@gmail.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FILE_TIME_HXX
+#define FILE_TIME_HXX
+
+#include <fileapi.h>
+
+#include <chrono>
+
+#include <stdint.h>
+
+static constexpr uint64_t
+ConstructUint64(DWORD lo, DWORD hi)
+{
+ return uint64_t(lo) | (uint64_t(hi) << 32);
+}
+
+static constexpr time_t
+FileTimeToTimeT(FILETIME ft)
+{
+ return (ConstructUint64(ft.dwLowDateTime, ft.dwHighDateTime)
+ - 116444736000000000) / 10000000;
+}
+
+static inline std::chrono::system_clock::time_point
+FileTimeToChrono(FILETIME ft)
+{
+ // TODO: eliminate the time_t roundtrip, preserve sub-second resolution
+ return std::chrono::system_clock::from_time_t(FileTimeToTimeT(ft));
+}
+
+gcc_const
+static inline std::chrono::seconds
+DeltaFileTimeS(FILETIME a, FILETIME b)
+{
+ ULARGE_INTEGER a2, b2;
+ b2.LowPart = b.dwLowDateTime;
+ b2.HighPart = b.dwHighDateTime;
+ a2.LowPart = a.dwLowDateTime;
+ a2.HighPart = a.dwHighDateTime;
+ return std::chrono::seconds((a2.QuadPart - b2.QuadPart) / 10000000);
+}
+
+#endif