2018-05-07 Edward Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libgo / go / os / executable_windows.go
blobfc5cf8600533d125ca991198aeacbdb3cd3b2f37
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package os
7 import (
8 "internal/syscall/windows"
9 "syscall"
12 func getModuleFileName(handle syscall.Handle) (string, error) {
13 n := uint32(1024)
14 var buf []uint16
15 for {
16 buf = make([]uint16, n)
17 r, err := windows.GetModuleFileName(handle, &buf[0], n)
18 if err != nil {
19 return "", err
21 if r < n {
22 break
24 // r == n means n not big enough
25 n += 1024
27 return syscall.UTF16ToString(buf), nil
30 func executable() (string, error) {
31 return getModuleFileName(0)