|
|
@@ -3,13 +3,39 @@
|
|
|
package registry
|
|
|
|
|
|
import (
|
|
|
- "golang.org/x/sys/windows"
|
|
|
"syscall"
|
|
|
"unsafe"
|
|
|
+
|
|
|
+ "golang.org/x/sys/windows"
|
|
|
)
|
|
|
|
|
|
var _ unsafe.Pointer
|
|
|
|
|
|
+// Do the interface allocations only once for common
|
|
|
+// Errno values.
|
|
|
+const (
|
|
|
+ errnoERROR_IO_PENDING = 997
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
|
|
|
+)
|
|
|
+
|
|
|
+// errnoErr returns common boxed Errno values, to prevent
|
|
|
+// allocations at runtime.
|
|
|
+func errnoErr(e syscall.Errno) error {
|
|
|
+ switch e {
|
|
|
+ case 0:
|
|
|
+ return nil
|
|
|
+ case errnoERROR_IO_PENDING:
|
|
|
+ return errERROR_IO_PENDING
|
|
|
+ }
|
|
|
+ // TODO: add more here, after collecting data on the common
|
|
|
+ // error values see on Windows. (perhaps when running
|
|
|
+ // all.bat?)
|
|
|
+ return e
|
|
|
+}
|
|
|
+
|
|
|
var (
|
|
|
modadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
|
|
|
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
|
|
@@ -76,7 +102,7 @@ func expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32,
|
|
|
n = uint32(r0)
|
|
|
if n == 0 {
|
|
|
if e1 != 0 {
|
|
|
- err = error(e1)
|
|
|
+ err = errnoErr(e1)
|
|
|
} else {
|
|
|
err = syscall.EINVAL
|
|
|
}
|