aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-27 10:52:17 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-27 10:52:17 -0800
commitdd98188ce06c09c666414e45ab54a4fd260b0d59 (patch)
treedcffc4c933601128df5e1b5c2475ce2ae9be699c /lib
parenta7c9d11b289b2140430f2666968bddb02a6f1a1f (diff)
downloadzig-dd98188ce06c09c666414e45ab54a4fd260b0d59.tar.gz
zig-dd98188ce06c09c666414e45ab54a4fd260b0d59.zip
std.Io.Threaded: mostly implement fileSetTimestamps for Windows
it's still missing the case of setting to now (which was also not implemented before)
Diffstat (limited to 'lib')
-rw-r--r--lib/std/Io/Threaded.zig33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig
index 419552c187..730a1a3b28 100644
--- a/lib/std/Io/Threaded.zig
+++ b/lib/std/Io/Threaded.zig
@@ -6046,11 +6046,34 @@ fn fileSetTimestamps(
if (is_windows) {
try current_thread.checkCancel();
- const atime_ft = windows.nanoSecondsToFileTime(options.access_time);
- const mtime_ft = windows.nanoSecondsToFileTime(options.modify_time);
+ var access_time_buffer: windows.FILETIME = undefined;
+ var modify_time_buffer: windows.FILETIME = undefined;
+ var system_time_buffer: windows.LARGE_INTEGER = undefined;
+
+ if (options.access_timestamp == .now or options.modify_timestamp == .now) {
+ system_time_buffer = windows.ntdll.RtlGetSystemTimePrecise();
+ }
+
+ const access_ptr = switch (options.access_timestamp) {
+ .unchanged => null,
+ .now => @panic("TODO do SystemTimeToFileTime logic here"),
+ .new => |ts| p: {
+ access_time_buffer = windows.nanoSecondsToFileTime(ts);
+ break :p &access_time_buffer;
+ },
+ };
+
+ const modify_ptr = switch (options.modify_timestamp) {
+ .unchanged => null,
+ .now => @panic("TODO do SystemTimeToFileTime logic here"),
+ .new => |ts| p: {
+ modify_time_buffer = windows.nanoSecondsToFileTime(ts);
+ break :p &modify_time_buffer;
+ },
+ };
// https://github.com/ziglang/zig/issues/1840
- const rc = windows.kernel32.SetFileTime(file.handle, null, &atime_ft, &mtime_ft);
+ const rc = windows.kernel32.SetFileTime(file.handle, null, access_ptr, modify_ptr);
if (rc == 0) {
switch (windows.GetLastError()) {
else => |err| return windows.unexpectedError(err),
@@ -6060,8 +6083,8 @@ fn fileSetTimestamps(
}
if (native_os == .wasi and !builtin.link_libc) {
- const atim = timestampToPosix(options.access_time.nanoseconds).toTimestamp();
- const mtim = timestampToPosix(options.modify_time.nanoseconds).toTimestamp();
+ const atim = timestampToPosix(options.access_timestamp.nanoseconds).toTimestamp();
+ const mtim = timestampToPosix(options.modify_timestamp.nanoseconds).toTimestamp();
try current_thread.beginSyscall();
while (true) switch (std.os.wasi.fd_filestat_set_times(file.handle, atim, mtim, .{
.ATIM = true,