aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/Microsoft/hcsshim/internal/interop/interop.go
blob: 2f6ec029ecf9aa7de2d16d68f6d13d2984c14789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package interop

import (
	"syscall"
	"unsafe"
)

//go:generate go run ../../mksyscall_windows.go -output zsyscall_windows.go interop.go

//sys coTaskMemFree(buffer unsafe.Pointer) = api_ms_win_core_com_l1_1_0.CoTaskMemFree

func ConvertAndFreeCoTaskMemString(buffer *uint16) string {
	str := syscall.UTF16ToString((*[1 << 29]uint16)(unsafe.Pointer(buffer))[:])
	coTaskMemFree(unsafe.Pointer(buffer))
	return str
}

func ConvertAndFreeCoTaskMemBytes(buffer *uint16) []byte {
	return []byte(ConvertAndFreeCoTaskMemString(buffer))
}

func Win32FromHresult(hr uintptr) syscall.Errno {
	if hr&0x1fff0000 == 0x00070000 {
		return syscall.Errno(hr & 0xffff)
	}
	return syscall.Errno(hr)
}