Commit cf75c86c authored by Alex Brainman's avatar Alex Brainman

syscall: change windows apis with bool return value to return errno instead

This change is to make these apis similar to their unix counterparts.

R=rsc
CC=golang-dev
https://golang.org/cl/4185042
parent 876e9d1b
......@@ -28,15 +28,15 @@ func (r *rngReader) Read(b []byte) (n int, err os.Error) {
if r.prov == 0 {
const provType = syscall.PROV_RSA_FULL
const flags = syscall.CRYPT_VERIFYCONTEXT | syscall.CRYPT_SILENT
ok, errno := syscall.CryptAcquireContext(&r.prov, nil, nil, provType, flags)
if !ok {
errno := syscall.CryptAcquireContext(&r.prov, nil, nil, provType, flags)
if errno != 0 {
r.mu.Unlock()
return 0, os.NewSyscallError("CryptAcquireContext", errno)
}
}
r.mu.Unlock()
ok, errno := syscall.CryptGenRandom(r.prov, uint32(len(b)), &b[0])
if !ok {
errno := syscall.CryptGenRandom(r.prov, uint32(len(b)), &b[0])
if errno != 0 {
return 0, os.NewSyscallError("CryptGenRandom", errno)
}
return len(b), nil
......
......@@ -51,7 +51,8 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
case WM_COMMAND:
switch uint32(lparam) {
case bh:
if ok, e := PostMessage(hwnd, WM_CLOSE, 0, 0); !ok {
e := PostMessage(hwnd, WM_CLOSE, 0, 0)
if e != 0 {
abortErrNo("PostMessage", e)
}
default:
......@@ -125,7 +126,7 @@ func rungui() int {
ShowWindow(wh, SW_SHOWDEFAULT)
// UpdateWindow
if _, e := UpdateWindow(wh); e != 0 {
if e := UpdateWindow(wh); e != 0 {
abortErrNo("UpdateWindow", e)
}
......
......@@ -130,18 +130,18 @@ var (
//sys RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) = user32.RegisterClassExW
//sys CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent uint32, menu uint32, instance uint32, param uintptr) (hwnd uint32, errno int) = user32.CreateWindowExW
//sys DefWindowProc(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) = user32.DefWindowProcW
//sys DestroyWindow(hwnd uint32) (ok bool, errno int) = user32.DestroyWindow
//sys DestroyWindow(hwnd uint32) (errno int) = user32.DestroyWindow
//sys PostQuitMessage(exitcode int32) = user32.PostQuitMessage
//sys ShowWindow(hwnd uint32, cmdshow int32) (ok bool) = user32.ShowWindow
//sys UpdateWindow(hwnd uint32) (ok bool, errno int) = user32.UpdateWindow
//sys ShowWindow(hwnd uint32, cmdshow int32) (wasvisible bool) = user32.ShowWindow
//sys UpdateWindow(hwnd uint32) (errno int) = user32.UpdateWindow
//sys GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) [failretval==-1] = user32.GetMessageW
//sys TranslateMessage(msg *Msg) (ok bool) = user32.TranslateMessage
//sys TranslateMessage(msg *Msg) (done bool) = user32.TranslateMessage
//sys DispatchMessage(msg *Msg) (ret int32) = user32.DispatchMessageW
//sys LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) = user32.LoadIconW
//sys LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int) = user32.LoadCursorW
//sys SetCursor(cursor uint32) (precursor uint32, errno int) = user32.SetCursor
//sys SendMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) = user32.SendMessageW
//sys PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (ok bool, errno int) = user32.PostMessageW
//sys PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (errno int) = user32.PostMessageW
func MakeIntResource(id uint16) *uint16 {
return (*uint16)(unsafe.Pointer(uintptr(id)))
......
......@@ -79,10 +79,9 @@ func DefWindowProc(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult
return
}
func DestroyWindow(hwnd uint32) (ok bool, errno int) {
r0, _, e1 := syscall.Syscall(procDestroyWindow, 1, uintptr(hwnd), 0, 0)
ok = bool(r0 != 0)
if !ok {
func DestroyWindow(hwnd uint32) (errno int) {
r1, _, e1 := syscall.Syscall(procDestroyWindow, 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
errno = int(e1)
} else {
......@@ -99,16 +98,15 @@ func PostQuitMessage(exitcode int32) {
return
}
func ShowWindow(hwnd uint32, cmdshow int32) (ok bool) {
func ShowWindow(hwnd uint32, cmdshow int32) (wasvisible bool) {
r0, _, _ := syscall.Syscall(procShowWindow, 2, uintptr(hwnd), uintptr(cmdshow), 0)
ok = bool(r0 != 0)
wasvisible = bool(r0 != 0)
return
}
func UpdateWindow(hwnd uint32) (ok bool, errno int) {
r0, _, e1 := syscall.Syscall(procUpdateWindow, 1, uintptr(hwnd), 0, 0)
ok = bool(r0 != 0)
if !ok {
func UpdateWindow(hwnd uint32) (errno int) {
r1, _, e1 := syscall.Syscall(procUpdateWindow, 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
errno = int(e1)
} else {
......@@ -135,9 +133,9 @@ func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32)
return
}
func TranslateMessage(msg *Msg) (ok bool) {
func TranslateMessage(msg *Msg) (done bool) {
r0, _, _ := syscall.Syscall(procTranslateMessage, 1, uintptr(unsafe.Pointer(msg)), 0, 0)
ok = bool(r0 != 0)
done = bool(r0 != 0)
return
}
......@@ -198,10 +196,9 @@ func SendMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult i
return
}
func PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (ok bool, errno int) {
r0, _, e1 := syscall.Syscall6(procPostMessageW, 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
ok = bool(r0 != 0)
if !ok {
func PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (errno int) {
r1, _, e1 := syscall.Syscall6(procPostMessageW, 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
errno = int(e1)
} else {
......
......@@ -85,7 +85,7 @@ type ioPacket struct {
func (s *pollServer) getCompletedIO() (ov *syscall.Overlapped, result *ioResult, err os.Error) {
var r ioResult
var o *syscall.Overlapped
_, e := syscall.GetQueuedCompletionStatus(s.iocp, &r.qty, &r.key, &o, syscall.INFINITE)
e := syscall.GetQueuedCompletionStatus(s.iocp, &r.qty, &r.key, &o, syscall.INFINITE)
switch {
case e == 0:
// Dequeued successfully completed io packet.
......@@ -270,7 +270,7 @@ func timeoutIO() {
case writeto:
e = syscall.WSASendto(uint32(o.fd.sysfd), o.pckt.w, 1, o.done, 0, *o.sa, &o.pckt.o, nil)
case cancel:
_, e = syscall.CancelIo(uint32(o.fd.sysfd))
e = syscall.CancelIo(uint32(o.fd.sysfd))
}
o.c <- e
}
......
......@@ -50,8 +50,8 @@ func Setenv(key, value string) Error {
if len(value) > 0 {
v = syscall.StringToUTF16Ptr(value)
}
ok, e := syscall.SetEnvironmentVariable(syscall.StringToUTF16Ptr(key), v)
if !ok {
e := syscall.SetEnvironmentVariable(syscall.StringToUTF16Ptr(key), v)
if e != 0 {
return NewSyscallError("SetEnvironmentVariable", e)
}
return nil
......
......@@ -20,7 +20,8 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
return nil, ErrorString("os: unexpected result from WaitForSingleObject")
}
var ec uint32
if ok, e := syscall.GetExitCodeProcess(uint32(p.handle), &ec); !ok {
e = syscall.GetExitCodeProcess(uint32(p.handle), &ec)
if e != 0 {
return nil, NewSyscallError("GetExitCodeProcess", e)
}
return &Waitmsg{p.Pid, syscall.WaitStatus{s, ec}, new(syscall.Rusage)}, nil
......@@ -30,7 +31,8 @@ func (p *Process) Release() Error {
if p.handle == -1 {
return EINVAL
}
if ok, e := syscall.CloseHandle(int32(p.handle)); !ok {
e := syscall.CloseHandle(int32(p.handle))
if e != 0 {
return NewSyscallError("CloseHandle", e)
}
p.handle = -1
......
......@@ -83,9 +83,9 @@ func (file *File) Close() Error {
}
var e int
if file.isdir() {
_, e = syscall.FindClose(int32(file.fd))
e = syscall.FindClose(int32(file.fd))
} else {
_, e = syscall.CloseHandle(int32(file.fd))
e = syscall.CloseHandle(int32(file.fd))
}
var err Error
if e != 0 {
......@@ -100,7 +100,8 @@ func (file *File) Close() Error {
func (file *File) statFile(name string) (fi *FileInfo, err Error) {
var stat syscall.ByHandleFileInformation
if ok, e := syscall.GetFileInformationByHandle(int32(file.fd), &stat); !ok {
e := syscall.GetFileInformationByHandle(int32(file.fd), &stat)
if e != 0 {
return nil, &PathError{"stat", file.name, Errno(e)}
}
return fileInfoFromByHandleInfo(new(FileInfo), file.name, &stat), nil
......@@ -142,7 +143,7 @@ func (file *File) Readdir(count int) (fi []FileInfo, err Error) {
if di.usefirststat {
di.usefirststat = false
} else {
_, e := syscall.FindNextFile(int32(file.fd), &di.stat.Windata)
e := syscall.FindNextFile(int32(file.fd), &di.stat.Windata)
if e != 0 {
if e == syscall.ERROR_NO_MORE_FILES {
break
......
......@@ -148,19 +148,22 @@ func StartProcess(argv0 string, argv []string, envv []string, dir string, fd []i
var currentProc, _ = GetCurrentProcess()
if len(fd) > 0 && fd[0] > 0 {
if ok, err := DuplicateHandle(currentProc, int32(fd[0]), currentProc, &startupInfo.StdInput, 0, true, DUPLICATE_SAME_ACCESS); !ok {
err := DuplicateHandle(currentProc, int32(fd[0]), currentProc, &startupInfo.StdInput, 0, true, DUPLICATE_SAME_ACCESS)
if err != 0 {
return 0, 0, err
}
defer CloseHandle(int32(startupInfo.StdInput))
}
if len(fd) > 1 && fd[1] > 0 {
if ok, err := DuplicateHandle(currentProc, int32(fd[1]), currentProc, &startupInfo.StdOutput, 0, true, DUPLICATE_SAME_ACCESS); !ok {
err := DuplicateHandle(currentProc, int32(fd[1]), currentProc, &startupInfo.StdOutput, 0, true, DUPLICATE_SAME_ACCESS)
if err != 0 {
return 0, 0, err
}
defer CloseHandle(int32(startupInfo.StdOutput))
}
if len(fd) > 2 && fd[2] > 0 {
if ok, err := DuplicateHandle(currentProc, int32(fd[2]), currentProc, &startupInfo.StdErr, 0, true, DUPLICATE_SAME_ACCESS); !ok {
err := DuplicateHandle(currentProc, int32(fd[2]), currentProc, &startupInfo.StdErr, 0, true, DUPLICATE_SAME_ACCESS)
if err != 0 {
return 0, 0, err
}
defer CloseHandle(int32(startupInfo.StdErr))
......@@ -170,7 +173,7 @@ func StartProcess(argv0 string, argv []string, envv []string, dir string, fd []i
}
// argv0 must not be longer then 256 chars
// but the entire cmd line can have up to 32k chars (msdn)
ok, err := CreateProcess(
err = CreateProcess(
nil,
StringToUTF16Ptr(escapeAddQuotes(argv0)+" "+stringJoin(argv[1:], " ", escapeAddQuotes)),
nil, //ptr to struct lpProcessAttributes
......@@ -182,7 +185,7 @@ func StartProcess(argv0 string, argv []string, envv []string, dir string, fd []i
startupInfo,
processInfo)
if ok {
if err != 0 {
pid = int(processInfo.ProcessId)
handle = int(processInfo.Process)
CloseHandle(processInfo.Thread)
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment