[mirror] Go packages for low-level interaction with the operating system https://golang.org/x/sys
Find a file
gremat eaaaaee1dc windows/registry: correct KeyInfo.ModTime calculation
Filetime.Nanoseconds() has a major drawback: the returned int64 is too small to
represent Filetime's zero value (January 1, 1601, [1]) in terms of nanoseconds
since Epoch (00:00:00 UTC, January 1, 1970); MinInt64 [2] only dates back to
year 1677.

This has real-life implications, e.g., some Windows sub systems (Perflib, to
    name one) create registry keys with the last write time property set to
zero (see note below). In this case, ModTime() reports an underflow-affected
value of 2185-07-22T00:34:33.709551+01:00.

This commit drops usage of Nanoseconds() in favor of a conversion that converts
first to seconds and nanoseconds before gauging thus is capable to cover the
full range of Filetime values.

A note on last write time values: `lastWriteTime` is not exposed in the UI
(say, `regedit`) or in PowerShell (`Get-ItemProperty`), you need to query
`RegQueryInfoKeyA` [3] explicitly in some way [4] or another [5]. The source of
the latter is offline by now but can be found elsewhere [6] and provides a
quick way to show the value.

[1] https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime
[2] https://pkg.go.dev/math#pkg-constants
[3] https://learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryinfokeya?redirectedfrom=MSDN
[4] https://learn.microsoft.com/en-us/windows/win32/sysinfo/retrieving-the-last-write-time
[5] https://learn-powershell.net/2014/12/18/retrieving-a-registry-key-lastwritetime-using-powershell/
[6] https://github.com/wxrdnx/GetRegistryKeyLastWriteTimeAndClassName

Fixes golang/go#74335.

Change-Id: I83dc1d6b5e0c581bfb53d58ee08a21ed9c166b0f
GitHub-Last-Rev: 0073d1d313
GitHub-Pull-Request: golang/sys#251
Reviewed-on: https://go-review.googlesource.com/c/sys/+/682816
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2026-03-02 17:51:03 -08:00
cpu cpu: darwin/arm64 feature detection 2026-03-02 13:52:18 -08:00
execabs all: update go directive to 1.18 2023-10-11 21:54:30 +00:00
plan9 plan9: change Note to alias syscall.Note 2026-02-11 17:50:06 -08:00
unix unix/linux: Prefixmsg and PrefixCacheinfo structs 2026-02-18 12:31:42 -08:00
windows windows/registry: correct KeyInfo.ModTime calculation 2026-03-02 17:51:03 -08:00
.gitattributes sys: copying .gitattributes to all subrepositories 2014-12-23 09:43:20 +00:00
.gitignore gitignore: remove obsolete reference to .hgignore in comment 2020-03-20 18:12:52 +00:00
codereview.cfg sys: add codereview.cfg 2015-03-18 17:04:21 +00:00
CONTRIBUTING.md CONTRIBUTING.md: remove note about not accepting Pull Requests 2018-03-14 18:01:51 +00:00
go.mod all: upgrade go directive to at least 1.25.0 [generated] 2026-02-11 11:14:51 -08:00
LICENSE LICENSE: update per Google Legal 2024-07-16 16:11:15 +00:00
PATENTS go.empty: add PATENTS file to the subrepo. 2012-04-16 11:24:04 +10:00
README.md README: don't recommend go get 2024-11-02 04:18:59 +00:00

sys

Go Reference

This repository holds supplemental Go packages for low-level interactions with the operating system.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/sys.

The main issue tracker for the sys repository is located at https://go.dev/issues. Prefix your issue with "x/sys:" in the subject line, so it is easy to find.