File 1148-erts-Silently-convert-FILETIME-of-1-to-0-on-Windows.patch of Package erlang

From 740fad636a889e2e08c1418082f547fa8c3fea56 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20H=C3=B6gberg?= <john@erlang.org>
Date: Thu, 1 Dec 2022 13:59:25 +0100
Subject: [PATCH 1/2] erts: Silently convert FILETIME of -1 to 0 on Windows

Some functions that return a FILETIME signal its absence by
returning the highest possible value instead of the documented 0,
which causes a time conversion to fail later on.

This commit silently converts such times to 0, presenting them as
absent.
---
 erts/emulator/nifs/win32/win_prim_file.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/erts/emulator/nifs/win32/win_prim_file.c b/erts/emulator/nifs/win32/win_prim_file.c
index e443914bda..bdbf7a19d2 100644
--- a/erts/emulator/nifs/win32/win_prim_file.c
+++ b/erts/emulator/nifs/win32/win_prim_file.c
@@ -65,11 +65,16 @@
 #define TICKS_PER_SECOND (10000000ULL)
 #define EPOCH_DIFFERENCE (11644473600LL)
 
+/* Note: some functions return a file time of -1 when the time is unavailable,
+ * rather than the documented 0, so we'll silently convert it to 0. */ \
 #define FILETIME_TO_EPOCH(epoch, ft) \
     do { \
         ULARGE_INTEGER ull; \
         ull.LowPart  = (ft).dwLowDateTime; \
         ull.HighPart = (ft).dwHighDateTime; \
+        if (ull.QuadPart == ~0ULL) { \
+            ull.QuadPart = 0; \
+        } \
         (epoch) = ((ull.QuadPart / TICKS_PER_SECOND) - EPOCH_DIFFERENCE); \
     } while(0)
 
-- 
2.35.3

openSUSE Build Service is sponsored by