diff options
Diffstat (limited to 'vendor/golang.org/x/sys/windows/syscall_windows.go')
-rw-r--r-- | vendor/golang.org/x/sys/windows/syscall_windows.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/vendor/golang.org/x/sys/windows/syscall_windows.go b/vendor/golang.org/x/sys/windows/syscall_windows.go index b3e5503..12c0544 100644 --- a/vendor/golang.org/x/sys/windows/syscall_windows.go +++ b/vendor/golang.org/x/sys/windows/syscall_windows.go | |||
@@ -13,6 +13,8 @@ import ( | |||
13 | "time" | 13 | "time" |
14 | "unicode/utf16" | 14 | "unicode/utf16" |
15 | "unsafe" | 15 | "unsafe" |
16 | |||
17 | "golang.org/x/sys/internal/unsafeheader" | ||
16 | ) | 18 | ) |
17 | 19 | ||
18 | type Handle uintptr | 20 | type Handle uintptr |
@@ -117,6 +119,32 @@ func UTF16PtrFromString(s string) (*uint16, error) { | |||
117 | return &a[0], nil | 119 | return &a[0], nil |
118 | } | 120 | } |
119 | 121 | ||
122 | // UTF16PtrToString takes a pointer to a UTF-16 sequence and returns the corresponding UTF-8 encoded string. | ||
123 | // If the pointer is nil, this returns the empty string. This assumes that the UTF-16 sequence is terminated | ||
124 | // at a zero word; if the zero word is not present, the program may crash. | ||
125 | func UTF16PtrToString(p *uint16) string { | ||
126 | if p == nil { | ||
127 | return "" | ||
128 | } | ||
129 | if *p == 0 { | ||
130 | return "" | ||
131 | } | ||
132 | |||
133 | // Find NUL terminator. | ||
134 | n := 0 | ||
135 | for ptr := unsafe.Pointer(p); *(*uint16)(ptr) != 0; n++ { | ||
136 | ptr = unsafe.Pointer(uintptr(ptr) + unsafe.Sizeof(*p)) | ||
137 | } | ||
138 | |||
139 | var s []uint16 | ||
140 | h := (*unsafeheader.Slice)(unsafe.Pointer(&s)) | ||
141 | h.Data = unsafe.Pointer(p) | ||
142 | h.Len = n | ||
143 | h.Cap = n | ||
144 | |||
145 | return string(utf16.Decode(s)) | ||
146 | } | ||
147 | |||
120 | func Getpagesize() int { return 4096 } | 148 | func Getpagesize() int { return 4096 } |
121 | 149 | ||
122 | // NewCallback converts a Go function to a function pointer conforming to the stdcall calling convention. | 150 | // NewCallback converts a Go function to a function pointer conforming to the stdcall calling convention. |
@@ -1383,7 +1411,7 @@ func (t Token) KnownFolderPath(folderID *KNOWNFOLDERID, flags uint32) (string, e | |||
1383 | return "", err | 1411 | return "", err |
1384 | } | 1412 | } |
1385 | defer CoTaskMemFree(unsafe.Pointer(p)) | 1413 | defer CoTaskMemFree(unsafe.Pointer(p)) |
1386 | return UTF16ToString((*[(1 << 30) - 1]uint16)(unsafe.Pointer(p))[:]), nil | 1414 | return UTF16PtrToString(p), nil |
1387 | } | 1415 | } |
1388 | 1416 | ||
1389 | // RtlGetVersion returns the version of the underlying operating system, ignoring | 1417 | // RtlGetVersion returns the version of the underlying operating system, ignoring |