mirror of
https://github.com/golang/sys.git
synced 2026-02-08 11:46:04 +03:00
windows: correct types and error values of internal GUID handling
This corrects the Windows int type to be the more correct int32 Go analog, as well as not using GetLastError() for the error value of the GUID string parsing function. Change-Id: I9716f991ef649f7d299295e3f4e75d3986ec3a74 Reviewed-on: https://go-review.googlesource.com/c/sys/+/181397 Run-TryBot: Jason Donenfeld <Jason@zx2c4.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
committed by
Jason Donenfeld
parent
5b15430b70
commit
6df407bc07
@@ -288,8 +288,8 @@ func NewCallbackCDecl(fn interface{}) uintptr {
|
||||
//sys SetVolumeLabel(rootPathName *uint16, volumeName *uint16) (err error) = SetVolumeLabelW
|
||||
//sys SetVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16) (err error) = SetVolumeMountPointW
|
||||
//sys MessageBox(hwnd Handle, text *uint16, caption *uint16, boxtype uint32) (ret int32, err error) [failretval==0] = user32.MessageBoxW
|
||||
//sys clsidFromString(lpsz *uint16, pclsid *GUID) (err error) [failretval!=0] = ole32.CLSIDFromString
|
||||
//sys stringFromGUID2(rguid *GUID, lpsz *uint16, cchMax int) (chars int) = ole32.StringFromGUID2
|
||||
//sys clsidFromString(lpsz *uint16, pclsid *GUID) (ret error) = ole32.CLSIDFromString
|
||||
//sys stringFromGUID2(rguid *GUID, lpsz *uint16, cchMax int32) (chars int32) = ole32.StringFromGUID2
|
||||
//sys coCreateGuid(pguid *GUID) (ret error) = ole32.CoCreateGuid
|
||||
|
||||
// syscall interface implementation for other packages
|
||||
@@ -1276,7 +1276,7 @@ func GenerateGUID() (GUID, error) {
|
||||
// in the form of "{XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}".
|
||||
func (guid GUID) String() string {
|
||||
var str [100]uint16
|
||||
chars := stringFromGUID2(&guid, &str[0], len(str))
|
||||
chars := stringFromGUID2(&guid, &str[0], int32(len(str)))
|
||||
if chars <= 1 {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -191,4 +191,8 @@ func TestGUID(t *testing.T) {
|
||||
if guid2 != guid {
|
||||
t.Fatalf("Did not parse string back to original GUID = %q; want %q", guid2, guid)
|
||||
}
|
||||
_, err = windows.GUIDFromString("not-a-real-guid")
|
||||
if err != syscall.Errno(windows.CO_E_CLASSSTRING) {
|
||||
t.Fatalf("Bad GUID string error = %v; want CO_E_CLASSSTRING", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2436,21 +2436,17 @@ func MessageBox(hwnd Handle, text *uint16, caption *uint16, boxtype uint32) (ret
|
||||
return
|
||||
}
|
||||
|
||||
func clsidFromString(lpsz *uint16, pclsid *GUID) (err error) {
|
||||
r1, _, e1 := syscall.Syscall(procCLSIDFromString.Addr(), 2, uintptr(unsafe.Pointer(lpsz)), uintptr(unsafe.Pointer(pclsid)), 0)
|
||||
if r1 != 0 {
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
} else {
|
||||
err = syscall.EINVAL
|
||||
}
|
||||
func clsidFromString(lpsz *uint16, pclsid *GUID) (ret error) {
|
||||
r0, _, _ := syscall.Syscall(procCLSIDFromString.Addr(), 2, uintptr(unsafe.Pointer(lpsz)), uintptr(unsafe.Pointer(pclsid)), 0)
|
||||
if r0 != 0 {
|
||||
ret = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func stringFromGUID2(rguid *GUID, lpsz *uint16, cchMax int) (chars int) {
|
||||
func stringFromGUID2(rguid *GUID, lpsz *uint16, cchMax int32) (chars int32) {
|
||||
r0, _, _ := syscall.Syscall(procStringFromGUID2.Addr(), 3, uintptr(unsafe.Pointer(rguid)), uintptr(unsafe.Pointer(lpsz)), uintptr(cchMax))
|
||||
chars = int(r0)
|
||||
chars = int32(r0)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user