summaryrefslogtreecommitdiff
path: root/vendor/github.com/kardianos/osext/osext_windows.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2021-04-14 16:54:42 +0200
committerkali kaneko (leap communications) <kali@leap.se>2021-04-14 16:54:42 +0200
commit67a0eb7111d3f89e4a0cb21e43aefe6d87d37e04 (patch)
treec9b18e0da6e06ac165a485ee957b7850adb12e86 /vendor/github.com/kardianos/osext/osext_windows.go
parent2e8f2a2e8e83fd89f956cdde886d5d9d808132da (diff)
[pkg] go mod vendor to build debian/ubuntu packages
Diffstat (limited to 'vendor/github.com/kardianos/osext/osext_windows.go')
-rw-r--r--vendor/github.com/kardianos/osext/osext_windows.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/vendor/github.com/kardianos/osext/osext_windows.go b/vendor/github.com/kardianos/osext/osext_windows.go
new file mode 100644
index 0000000..074b3b3
--- /dev/null
+++ b/vendor/github.com/kardianos/osext/osext_windows.go
@@ -0,0 +1,36 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//+build !go1.8
+
+package osext
+
+import (
+ "syscall"
+ "unicode/utf16"
+ "unsafe"
+)
+
+var (
+ kernel = syscall.MustLoadDLL("kernel32.dll")
+ getModuleFileNameProc = kernel.MustFindProc("GetModuleFileNameW")
+)
+
+// GetModuleFileName() with hModule = NULL
+func executable() (exePath string, err error) {
+ return getModuleFileName()
+}
+
+func getModuleFileName() (string, error) {
+ var n uint32
+ b := make([]uint16, syscall.MAX_PATH)
+ size := uint32(len(b))
+
+ r0, _, e1 := getModuleFileNameProc.Call(0, uintptr(unsafe.Pointer(&b[0])), uintptr(size))
+ n = uint32(r0)
+ if n == 0 {
+ return "", e1
+ }
+ return string(utf16.Decode(b[0:n])), nil
+}