1
0
mirror of https://github.com/golang/go synced 2024-11-21 21:04:41 -07:00

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
This commit is contained in:
Alex Brainman 2011-02-11 10:15:51 +11:00
parent 876e9d1b89
commit cf75c86cdf
11 changed files with 192 additions and 234 deletions

View File

@ -28,15 +28,15 @@ func (r *rngReader) Read(b []byte) (n int, err os.Error) {
if r.prov == 0 { if r.prov == 0 {
const provType = syscall.PROV_RSA_FULL const provType = syscall.PROV_RSA_FULL
const flags = syscall.CRYPT_VERIFYCONTEXT | syscall.CRYPT_SILENT const flags = syscall.CRYPT_VERIFYCONTEXT | syscall.CRYPT_SILENT
ok, errno := syscall.CryptAcquireContext(&r.prov, nil, nil, provType, flags) errno := syscall.CryptAcquireContext(&r.prov, nil, nil, provType, flags)
if !ok { if errno != 0 {
r.mu.Unlock() r.mu.Unlock()
return 0, os.NewSyscallError("CryptAcquireContext", errno) return 0, os.NewSyscallError("CryptAcquireContext", errno)
} }
} }
r.mu.Unlock() r.mu.Unlock()
ok, errno := syscall.CryptGenRandom(r.prov, uint32(len(b)), &b[0]) errno := syscall.CryptGenRandom(r.prov, uint32(len(b)), &b[0])
if !ok { if errno != 0 {
return 0, os.NewSyscallError("CryptGenRandom", errno) return 0, os.NewSyscallError("CryptGenRandom", errno)
} }
return len(b), nil return len(b), nil

View File

@ -51,7 +51,8 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
case WM_COMMAND: case WM_COMMAND:
switch uint32(lparam) { switch uint32(lparam) {
case bh: 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) abortErrNo("PostMessage", e)
} }
default: default:
@ -125,7 +126,7 @@ func rungui() int {
ShowWindow(wh, SW_SHOWDEFAULT) ShowWindow(wh, SW_SHOWDEFAULT)
// UpdateWindow // UpdateWindow
if _, e := UpdateWindow(wh); e != 0 { if e := UpdateWindow(wh); e != 0 {
abortErrNo("UpdateWindow", e) abortErrNo("UpdateWindow", e)
} }

View File

@ -130,18 +130,18 @@ var (
//sys RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) = user32.RegisterClassExW //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 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 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 PostQuitMessage(exitcode int32) = user32.PostQuitMessage
//sys ShowWindow(hwnd uint32, cmdshow int32) (ok bool) = user32.ShowWindow //sys ShowWindow(hwnd uint32, cmdshow int32) (wasvisible bool) = user32.ShowWindow
//sys UpdateWindow(hwnd uint32) (ok bool, errno int) = user32.UpdateWindow //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 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 DispatchMessage(msg *Msg) (ret int32) = user32.DispatchMessageW
//sys LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) = user32.LoadIconW //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 LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int) = user32.LoadCursorW
//sys SetCursor(cursor uint32) (precursor uint32, errno int) = user32.SetCursor //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 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 { func MakeIntResource(id uint16) *uint16 {
return (*uint16)(unsafe.Pointer(uintptr(id))) return (*uint16)(unsafe.Pointer(uintptr(id)))

View File

@ -79,10 +79,9 @@ func DefWindowProc(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult
return return
} }
func DestroyWindow(hwnd uint32) (ok bool, errno int) { func DestroyWindow(hwnd uint32) (errno int) {
r0, _, e1 := syscall.Syscall(procDestroyWindow, 1, uintptr(hwnd), 0, 0) r1, _, e1 := syscall.Syscall(procDestroyWindow, 1, uintptr(hwnd), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -99,16 +98,15 @@ func PostQuitMessage(exitcode int32) {
return 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) r0, _, _ := syscall.Syscall(procShowWindow, 2, uintptr(hwnd), uintptr(cmdshow), 0)
ok = bool(r0 != 0) wasvisible = bool(r0 != 0)
return return
} }
func UpdateWindow(hwnd uint32) (ok bool, errno int) { func UpdateWindow(hwnd uint32) (errno int) {
r0, _, e1 := syscall.Syscall(procUpdateWindow, 1, uintptr(hwnd), 0, 0) r1, _, e1 := syscall.Syscall(procUpdateWindow, 1, uintptr(hwnd), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -135,9 +133,9 @@ func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32)
return return
} }
func TranslateMessage(msg *Msg) (ok bool) { func TranslateMessage(msg *Msg) (done bool) {
r0, _, _ := syscall.Syscall(procTranslateMessage, 1, uintptr(unsafe.Pointer(msg)), 0, 0) r0, _, _ := syscall.Syscall(procTranslateMessage, 1, uintptr(unsafe.Pointer(msg)), 0, 0)
ok = bool(r0 != 0) done = bool(r0 != 0)
return return
} }
@ -198,10 +196,9 @@ func SendMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult i
return return
} }
func PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (ok bool, errno int) { func PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (errno int) {
r0, _, e1 := syscall.Syscall6(procPostMessageW, 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0) r1, _, e1 := syscall.Syscall6(procPostMessageW, 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {

View File

@ -85,7 +85,7 @@ type ioPacket struct {
func (s *pollServer) getCompletedIO() (ov *syscall.Overlapped, result *ioResult, err os.Error) { func (s *pollServer) getCompletedIO() (ov *syscall.Overlapped, result *ioResult, err os.Error) {
var r ioResult var r ioResult
var o *syscall.Overlapped 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 { switch {
case e == 0: case e == 0:
// Dequeued successfully completed io packet. // Dequeued successfully completed io packet.
@ -270,7 +270,7 @@ func timeoutIO() {
case writeto: case writeto:
e = syscall.WSASendto(uint32(o.fd.sysfd), o.pckt.w, 1, o.done, 0, *o.sa, &o.pckt.o, nil) e = syscall.WSASendto(uint32(o.fd.sysfd), o.pckt.w, 1, o.done, 0, *o.sa, &o.pckt.o, nil)
case cancel: case cancel:
_, e = syscall.CancelIo(uint32(o.fd.sysfd)) e = syscall.CancelIo(uint32(o.fd.sysfd))
} }
o.c <- e o.c <- e
} }

View File

@ -50,8 +50,8 @@ func Setenv(key, value string) Error {
if len(value) > 0 { if len(value) > 0 {
v = syscall.StringToUTF16Ptr(value) v = syscall.StringToUTF16Ptr(value)
} }
ok, e := syscall.SetEnvironmentVariable(syscall.StringToUTF16Ptr(key), v) e := syscall.SetEnvironmentVariable(syscall.StringToUTF16Ptr(key), v)
if !ok { if e != 0 {
return NewSyscallError("SetEnvironmentVariable", e) return NewSyscallError("SetEnvironmentVariable", e)
} }
return nil return nil

View File

@ -20,7 +20,8 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
return nil, ErrorString("os: unexpected result from WaitForSingleObject") return nil, ErrorString("os: unexpected result from WaitForSingleObject")
} }
var ec uint32 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 nil, NewSyscallError("GetExitCodeProcess", e)
} }
return &Waitmsg{p.Pid, syscall.WaitStatus{s, ec}, new(syscall.Rusage)}, nil 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 { if p.handle == -1 {
return EINVAL return EINVAL
} }
if ok, e := syscall.CloseHandle(int32(p.handle)); !ok { e := syscall.CloseHandle(int32(p.handle))
if e != 0 {
return NewSyscallError("CloseHandle", e) return NewSyscallError("CloseHandle", e)
} }
p.handle = -1 p.handle = -1

View File

@ -83,9 +83,9 @@ func (file *File) Close() Error {
} }
var e int var e int
if file.isdir() { if file.isdir() {
_, e = syscall.FindClose(int32(file.fd)) e = syscall.FindClose(int32(file.fd))
} else { } else {
_, e = syscall.CloseHandle(int32(file.fd)) e = syscall.CloseHandle(int32(file.fd))
} }
var err Error var err Error
if e != 0 { if e != 0 {
@ -100,7 +100,8 @@ func (file *File) Close() Error {
func (file *File) statFile(name string) (fi *FileInfo, err Error) { func (file *File) statFile(name string) (fi *FileInfo, err Error) {
var stat syscall.ByHandleFileInformation 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 nil, &PathError{"stat", file.name, Errno(e)}
} }
return fileInfoFromByHandleInfo(new(FileInfo), file.name, &stat), nil 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 { if di.usefirststat {
di.usefirststat = false di.usefirststat = false
} else { } else {
_, e := syscall.FindNextFile(int32(file.fd), &di.stat.Windata) e := syscall.FindNextFile(int32(file.fd), &di.stat.Windata)
if e != 0 { if e != 0 {
if e == syscall.ERROR_NO_MORE_FILES { if e == syscall.ERROR_NO_MORE_FILES {
break break

View File

@ -148,19 +148,22 @@ func StartProcess(argv0 string, argv []string, envv []string, dir string, fd []i
var currentProc, _ = GetCurrentProcess() var currentProc, _ = GetCurrentProcess()
if len(fd) > 0 && fd[0] > 0 { 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 return 0, 0, err
} }
defer CloseHandle(int32(startupInfo.StdInput)) defer CloseHandle(int32(startupInfo.StdInput))
} }
if len(fd) > 1 && fd[1] > 0 { 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 return 0, 0, err
} }
defer CloseHandle(int32(startupInfo.StdOutput)) defer CloseHandle(int32(startupInfo.StdOutput))
} }
if len(fd) > 2 && fd[2] > 0 { 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 return 0, 0, err
} }
defer CloseHandle(int32(startupInfo.StdErr)) 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 // argv0 must not be longer then 256 chars
// but the entire cmd line can have up to 32k chars (msdn) // but the entire cmd line can have up to 32k chars (msdn)
ok, err := CreateProcess( err = CreateProcess(
nil, nil,
StringToUTF16Ptr(escapeAddQuotes(argv0)+" "+stringJoin(argv[1:], " ", escapeAddQuotes)), StringToUTF16Ptr(escapeAddQuotes(argv0)+" "+stringJoin(argv[1:], " ", escapeAddQuotes)),
nil, //ptr to struct lpProcessAttributes nil, //ptr to struct lpProcessAttributes
@ -182,7 +185,7 @@ func StartProcess(argv0 string, argv []string, envv []string, dir string, fd []i
startupInfo, startupInfo,
processInfo) processInfo)
if ok { if err != 0 {
pid = int(processInfo.ProcessId) pid = int(processInfo.ProcessId)
handle = int(processInfo.Process) handle = int(processInfo.Process)
CloseHandle(processInfo.Thread) CloseHandle(processInfo.Thread)

View File

@ -106,59 +106,59 @@ func NewCallback(fn interface{}) uintptr
//sys GetLastError() (lasterrno int) //sys GetLastError() (lasterrno int)
//sys LoadLibrary(libname string) (handle uint32, errno int) = LoadLibraryW //sys LoadLibrary(libname string) (handle uint32, errno int) = LoadLibraryW
//sys FreeLibrary(handle uint32) (ok bool, errno int) //sys FreeLibrary(handle uint32) (errno int)
//sys GetProcAddress(module uint32, procname string) (proc uint32, errno int) //sys GetProcAddress(module uint32, procname string) (proc uint32, errno int)
//sys GetVersion() (ver uint32, errno int) //sys GetVersion() (ver uint32, errno int)
//sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, errno int) = FormatMessageW //sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, errno int) = FormatMessageW
//sys ExitProcess(exitcode uint32) //sys ExitProcess(exitcode uint32)
//sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle int32, errno int) [failretval==-1] = CreateFileW //sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle int32, errno int) [failretval==-1] = CreateFileW
//sys ReadFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (ok bool, errno int) //sys ReadFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (errno int)
//sys WriteFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (ok bool, errno int) //sys WriteFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (errno int)
//sys SetFilePointer(handle int32, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, errno int) [failretval==0xffffffff] //sys SetFilePointer(handle int32, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, errno int) [failretval==0xffffffff]
//sys CloseHandle(handle int32) (ok bool, errno int) //sys CloseHandle(handle int32) (errno int)
//sys GetStdHandle(stdhandle int32) (handle int32, errno int) [failretval==-1] //sys GetStdHandle(stdhandle int32) (handle int32, errno int) [failretval==-1]
//sys FindFirstFile(name *uint16, data *Win32finddata) (handle int32, errno int) [failretval==-1] = FindFirstFileW //sys FindFirstFile(name *uint16, data *Win32finddata) (handle int32, errno int) [failretval==-1] = FindFirstFileW
//sys FindNextFile(handle int32, data *Win32finddata) (ok bool, errno int) = FindNextFileW //sys FindNextFile(handle int32, data *Win32finddata) (errno int) = FindNextFileW
//sys FindClose(handle int32) (ok bool, errno int) //sys FindClose(handle int32) (errno int)
//sys GetFileInformationByHandle(handle int32, data *ByHandleFileInformation) (ok bool, errno int) //sys GetFileInformationByHandle(handle int32, data *ByHandleFileInformation) (errno int)
//sys GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, errno int) = GetCurrentDirectoryW //sys GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, errno int) = GetCurrentDirectoryW
//sys SetCurrentDirectory(path *uint16) (ok bool, errno int) = SetCurrentDirectoryW //sys SetCurrentDirectory(path *uint16) (errno int) = SetCurrentDirectoryW
//sys CreateDirectory(path *uint16, sa *SecurityAttributes) (ok bool, errno int) = CreateDirectoryW //sys CreateDirectory(path *uint16, sa *SecurityAttributes) (errno int) = CreateDirectoryW
//sys RemoveDirectory(path *uint16) (ok bool, errno int) = RemoveDirectoryW //sys RemoveDirectory(path *uint16) (errno int) = RemoveDirectoryW
//sys DeleteFile(path *uint16) (ok bool, errno int) = DeleteFileW //sys DeleteFile(path *uint16) (errno int) = DeleteFileW
//sys MoveFile(from *uint16, to *uint16) (ok bool, errno int) = MoveFileW //sys MoveFile(from *uint16, to *uint16) (errno int) = MoveFileW
//sys GetComputerName(buf *uint16, n *uint32) (ok bool, errno int) = GetComputerNameW //sys GetComputerName(buf *uint16, n *uint32) (errno int) = GetComputerNameW
//sys SetEndOfFile(handle int32) (ok bool, errno int) //sys SetEndOfFile(handle int32) (errno int)
//sys GetSystemTimeAsFileTime(time *Filetime) //sys GetSystemTimeAsFileTime(time *Filetime)
//sys sleep(msec uint32) = Sleep //sys sleep(msec uint32) = Sleep
//sys GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, errno int) [failretval==0xffffffff] //sys GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, errno int) [failretval==0xffffffff]
//sys CreateIoCompletionPort(filehandle int32, cphandle int32, key uint32, threadcnt uint32) (handle int32, errno int) //sys CreateIoCompletionPort(filehandle int32, cphandle int32, key uint32, threadcnt uint32) (handle int32, errno int)
//sys GetQueuedCompletionStatus(cphandle int32, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (ok bool, errno int) //sys GetQueuedCompletionStatus(cphandle int32, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (errno int)
//sys CancelIo(s uint32) (ok bool, errno int) //sys CancelIo(s uint32) (errno int)
//sys CreateProcess(appName *int16, commandLine *uint16, procSecurity *int16, threadSecurity *int16, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (ok bool, errno int) = CreateProcessW //sys CreateProcess(appName *int16, commandLine *uint16, procSecurity *int16, threadSecurity *int16, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (errno int) = CreateProcessW
//sys OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle uint32, errno int) //sys OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle uint32, errno int)
//sys GetExitCodeProcess(handle uint32, exitcode *uint32) (ok bool, errno int) //sys GetExitCodeProcess(handle uint32, exitcode *uint32) (errno int)
//sys GetStartupInfo(startupInfo *StartupInfo) (ok bool, errno int) = GetStartupInfoW //sys GetStartupInfo(startupInfo *StartupInfo) (errno int) = GetStartupInfoW
//sys GetCurrentProcess() (pseudoHandle int32, errno int) //sys GetCurrentProcess() (pseudoHandle int32, errno int)
//sys DuplicateHandle(hSourceProcessHandle int32, hSourceHandle int32, hTargetProcessHandle int32, lpTargetHandle *int32, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (ok bool, errno int) //sys DuplicateHandle(hSourceProcessHandle int32, hSourceHandle int32, hTargetProcessHandle int32, lpTargetHandle *int32, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (errno int)
//sys WaitForSingleObject(handle int32, waitMilliseconds uint32) (event uint32, errno int) [failretval==0xffffffff] //sys WaitForSingleObject(handle int32, waitMilliseconds uint32) (event uint32, errno int) [failretval==0xffffffff]
//sys GetTempPath(buflen uint32, buf *uint16) (n uint32, errno int) = GetTempPathW //sys GetTempPath(buflen uint32, buf *uint16) (n uint32, errno int) = GetTempPathW
//sys CreatePipe(readhandle *uint32, writehandle *uint32, sa *SecurityAttributes, size uint32) (ok bool, errno int) //sys CreatePipe(readhandle *uint32, writehandle *uint32, sa *SecurityAttributes, size uint32) (errno int)
//sys GetFileType(filehandle uint32) (n uint32, errno int) //sys GetFileType(filehandle uint32) (n uint32, errno int)
//sys CryptAcquireContext(provhandle *uint32, container *uint16, provider *uint16, provtype uint32, flags uint32) (ok bool, errno int) = advapi32.CryptAcquireContextW //sys CryptAcquireContext(provhandle *uint32, container *uint16, provider *uint16, provtype uint32, flags uint32) (errno int) = advapi32.CryptAcquireContextW
//sys CryptReleaseContext(provhandle uint32, flags uint32) (ok bool, errno int) = advapi32.CryptReleaseContext //sys CryptReleaseContext(provhandle uint32, flags uint32) (errno int) = advapi32.CryptReleaseContext
//sys CryptGenRandom(provhandle uint32, buflen uint32, buf *byte) (ok bool, errno int) = advapi32.CryptGenRandom //sys CryptGenRandom(provhandle uint32, buflen uint32, buf *byte) (errno int) = advapi32.CryptGenRandom
//sys GetEnvironmentStrings() (envs *uint16, errno int) [failretval==nil] = kernel32.GetEnvironmentStringsW //sys GetEnvironmentStrings() (envs *uint16, errno int) [failretval==nil] = kernel32.GetEnvironmentStringsW
//sys FreeEnvironmentStrings(envs *uint16) (ok bool, errno int) = kernel32.FreeEnvironmentStringsW //sys FreeEnvironmentStrings(envs *uint16) (errno int) = kernel32.FreeEnvironmentStringsW
//sys GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, errno int) = kernel32.GetEnvironmentVariableW //sys GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, errno int) = kernel32.GetEnvironmentVariableW
//sys SetEnvironmentVariable(name *uint16, value *uint16) (ok bool, errno int) = kernel32.SetEnvironmentVariableW //sys SetEnvironmentVariable(name *uint16, value *uint16) (errno int) = kernel32.SetEnvironmentVariableW
//sys SetFileTime(handle int32, ctime *Filetime, atime *Filetime, wtime *Filetime) (ok bool, errno int) //sys SetFileTime(handle int32, ctime *Filetime, atime *Filetime, wtime *Filetime) (errno int)
//sys GetFileAttributes(name *uint16) (attrs uint32, errno int) [failretval==INVALID_FILE_ATTRIBUTES] = kernel32.GetFileAttributesW //sys GetFileAttributes(name *uint16) (attrs uint32, errno int) [failretval==INVALID_FILE_ATTRIBUTES] = kernel32.GetFileAttributesW
//sys GetCommandLine() (cmd *uint16) = kernel32.GetCommandLineW //sys GetCommandLine() (cmd *uint16) = kernel32.GetCommandLineW
//sys CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, errno int) [failretval==nil] = shell32.CommandLineToArgvW //sys CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, errno int) [failretval==nil] = shell32.CommandLineToArgvW
//sys LocalFree(hmem uint32) (handle uint32, errno int) [failretval!=0] //sys LocalFree(hmem uint32) (handle uint32, errno int) [failretval!=0]
//sys SetHandleInformation(handle int32, mask uint32, flags uint32) (ok bool, errno int) //sys SetHandleInformation(handle int32, mask uint32, flags uint32) (errno int)
//sys FlushFileBuffers(handle int32) (ok bool, errno int) //sys FlushFileBuffers(handle int32) (errno int)
// syscall interface implementation for other packages // syscall interface implementation for other packages
@ -234,7 +234,8 @@ func Open(path string, mode int, perm uint32) (fd int, errno int) {
func Read(fd int, p []byte) (n int, errno int) { func Read(fd int, p []byte) (n int, errno int) {
var done uint32 var done uint32
if ok, e := ReadFile(int32(fd), p, &done, nil); !ok { e := ReadFile(int32(fd), p, &done, nil)
if e != 0 {
if e == ERROR_BROKEN_PIPE { if e == ERROR_BROKEN_PIPE {
// NOTE(brainman): work around ERROR_BROKEN_PIPE is returned on reading EOF from stdin // NOTE(brainman): work around ERROR_BROKEN_PIPE is returned on reading EOF from stdin
return 0, 0 return 0, 0
@ -258,7 +259,8 @@ func Pread(fd int, p []byte, offset int64) (n int, errno int) {
o.OffsetHigh = uint32(offset >> 32) o.OffsetHigh = uint32(offset >> 32)
o.Offset = uint32(offset) o.Offset = uint32(offset)
var done uint32 var done uint32
if ok, e := ReadFile(int32(fd), p, &done, &o); !ok { e = ReadFile(int32(fd), p, &done, &o)
if e != 0 {
return 0, e return 0, e
} }
return int(done), 0 return int(done), 0
@ -266,7 +268,8 @@ func Pread(fd int, p []byte, offset int64) (n int, errno int) {
func Write(fd int, p []byte) (n int, errno int) { func Write(fd int, p []byte) (n int, errno int) {
var done uint32 var done uint32
if ok, e := WriteFile(int32(fd), p, &done, nil); !ok { e := WriteFile(int32(fd), p, &done, nil)
if e != 0 {
return 0, e return 0, e
} }
return int(done), 0 return int(done), 0
@ -282,7 +285,8 @@ func Pwrite(fd int, p []byte, offset int64) (n int, errno int) {
o.OffsetHigh = uint32(offset >> 32) o.OffsetHigh = uint32(offset >> 32)
o.Offset = uint32(offset) o.Offset = uint32(offset)
var done uint32 var done uint32
if ok, e := WriteFile(int32(fd), p, &done, &o); !ok { e = WriteFile(int32(fd), p, &done, &o)
if e != 0 {
return 0, e return 0, e
} }
return int(done), 0 return int(done), 0
@ -313,10 +317,7 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, errno int) {
} }
func Close(fd int) (errno int) { func Close(fd int) (errno int) {
if ok, e := CloseHandle(int32(fd)); !ok { return CloseHandle(int32(fd))
return e
}
return 0
} }
var ( var (
@ -375,46 +376,32 @@ func Getwd() (wd string, errno int) {
} }
func Chdir(path string) (errno int) { func Chdir(path string) (errno int) {
if ok, e := SetCurrentDirectory(&StringToUTF16(path)[0]); !ok { return SetCurrentDirectory(&StringToUTF16(path)[0])
return e
}
return 0
} }
func Mkdir(path string, mode uint32) (errno int) { func Mkdir(path string, mode uint32) (errno int) {
if ok, e := CreateDirectory(&StringToUTF16(path)[0], nil); !ok { return CreateDirectory(&StringToUTF16(path)[0], nil)
return e
}
return 0
} }
func Rmdir(path string) (errno int) { func Rmdir(path string) (errno int) {
if ok, e := RemoveDirectory(&StringToUTF16(path)[0]); !ok { return RemoveDirectory(&StringToUTF16(path)[0])
return e
}
return 0
} }
func Unlink(path string) (errno int) { func Unlink(path string) (errno int) {
if ok, e := DeleteFile(&StringToUTF16(path)[0]); !ok { return DeleteFile(&StringToUTF16(path)[0])
return e
}
return 0
} }
func Rename(oldpath, newpath string) (errno int) { func Rename(oldpath, newpath string) (errno int) {
from := &StringToUTF16(oldpath)[0] from := &StringToUTF16(oldpath)[0]
to := &StringToUTF16(newpath)[0] to := &StringToUTF16(newpath)[0]
if ok, e := MoveFile(from, to); !ok { return MoveFile(from, to)
return e
}
return 0
} }
func ComputerName() (name string, errno int) { func ComputerName() (name string, errno int) {
var n uint32 = MAX_COMPUTERNAME_LENGTH + 1 var n uint32 = MAX_COMPUTERNAME_LENGTH + 1
b := make([]uint16, n) b := make([]uint16, n)
if ok, e := GetComputerName(&b[0], &n); !ok { e := GetComputerName(&b[0], &n)
if e != 0 {
return "", e return "", e
} }
return string(utf16.Decode(b[0:n])), 0 return string(utf16.Decode(b[0:n])), 0
@ -426,10 +413,12 @@ func Ftruncate(fd int, length int64) (errno int) {
return e return e
} }
defer Seek(fd, curoffset, 0) defer Seek(fd, curoffset, 0)
if _, e := Seek(fd, length, 0); e != 0 { _, e = Seek(fd, length, 0)
if e != 0 {
return e return e
} }
if _, e := SetEndOfFile(int32(fd)); e != 0 { e = SetEndOfFile(int32(fd))
if e != 0 {
return e return e
} }
return 0 return 0
@ -452,8 +441,9 @@ func Pipe(p []int) (errno int) {
return EINVAL return EINVAL
} }
var r, w uint32 var r, w uint32
if ok, errno := CreatePipe(&r, &w, makeInheritSa(), 0); !ok { e := CreatePipe(&r, &w, makeInheritSa(), 0)
return errno if e != 0 {
return e
} }
p[0] = int(r) p[0] = int(r)
p[1] = int(w) p[1] = int(w)
@ -473,17 +463,11 @@ func Utimes(path string, tv []Timeval) (errno int) {
defer Close(int(h)) defer Close(int(h))
a := NsecToFiletime(tv[0].Nanoseconds()) a := NsecToFiletime(tv[0].Nanoseconds())
w := NsecToFiletime(tv[1].Nanoseconds()) w := NsecToFiletime(tv[1].Nanoseconds())
if ok, e := SetFileTime(h, nil, &a, &w); !ok { return SetFileTime(h, nil, &a, &w)
return e
}
return 0
} }
func Fsync(fd int) (errno int) { func Fsync(fd int) (errno int) {
if ok, e := FlushFileBuffers(int32(fd)); !ok { return FlushFileBuffers(int32(fd))
return e
}
return 0
} }
// net api calls // net api calls
@ -499,7 +483,7 @@ func Fsync(fd int) (errno int) {
//sys listen(s int32, backlog int32) (errno int) [failretval==-1] = wsock32.listen //sys listen(s int32, backlog int32) (errno int) [failretval==-1] = wsock32.listen
//sys shutdown(s int32, how int32) (errno int) [failretval==-1] = wsock32.shutdown //sys shutdown(s int32, how int32) (errno int) [failretval==-1] = wsock32.shutdown
//sys Closesocket(s int32) (errno int) [failretval==-1] = wsock32.closesocket //sys Closesocket(s int32) (errno int) [failretval==-1] = wsock32.closesocket
//sys AcceptEx(ls uint32, as uint32, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (ok bool, errno int) = wsock32.AcceptEx //sys AcceptEx(ls uint32, as uint32, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (errno int) = wsock32.AcceptEx
//sys GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) = wsock32.GetAcceptExSockaddrs //sys GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) = wsock32.GetAcceptExSockaddrs
//sys WSARecv(s uint32, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (errno int) [failretval==-1] = ws2_32.WSARecv //sys WSARecv(s uint32, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (errno int) [failretval==-1] = ws2_32.WSARecv
//sys WSASend(s uint32, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (errno int) [failretval==-1] = ws2_32.WSASend //sys WSASend(s uint32, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (errno int) [failretval==-1] = ws2_32.WSASend
@ -657,7 +641,7 @@ func AcceptIOCP(iocpfd, fd int, o *Overlapped) (attrs *byte, errno int) {
attrs = (*byte)(unsafe.Pointer(&rsa[0])) attrs = (*byte)(unsafe.Pointer(&rsa[0]))
alen := uint32(unsafe.Sizeof(rsa[0])) alen := uint32(unsafe.Sizeof(rsa[0]))
var done uint32 var done uint32
_, errno = AcceptEx(uint32(iocpfd), uint32(fd), attrs, 0, alen, alen, &done, o) errno = AcceptEx(uint32(iocpfd), uint32(fd), attrs, 0, alen, alen, &done, o)
return return
} }

View File

@ -113,10 +113,9 @@ func LoadLibrary(libname string) (handle uint32, errno int) {
return return
} }
func FreeLibrary(handle uint32) (ok bool, errno int) { func FreeLibrary(handle uint32) (errno int) {
r0, _, e1 := Syscall(procFreeLibrary, 1, uintptr(handle), 0, 0) r1, _, e1 := Syscall(procFreeLibrary, 1, uintptr(handle), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -197,14 +196,13 @@ func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes
return return
} }
func ReadFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (ok bool, errno int) { func ReadFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (errno int) {
var _p0 *byte var _p0 *byte
if len(buf) > 0 { if len(buf) > 0 {
_p0 = &buf[0] _p0 = &buf[0]
} }
r0, _, e1 := Syscall6(procReadFile, 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0) r1, _, e1 := Syscall6(procReadFile, 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -216,14 +214,13 @@ func ReadFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (o
return return
} }
func WriteFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (ok bool, errno int) { func WriteFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (errno int) {
var _p0 *byte var _p0 *byte
if len(buf) > 0 { if len(buf) > 0 {
_p0 = &buf[0] _p0 = &buf[0]
} }
r0, _, e1 := Syscall6(procWriteFile, 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0) r1, _, e1 := Syscall6(procWriteFile, 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -250,10 +247,9 @@ func SetFilePointer(handle int32, lowoffset int32, highoffsetptr *int32, whence
return return
} }
func CloseHandle(handle int32) (ok bool, errno int) { func CloseHandle(handle int32) (errno int) {
r0, _, e1 := Syscall(procCloseHandle, 1, uintptr(handle), 0, 0) r1, _, e1 := Syscall(procCloseHandle, 1, uintptr(handle), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -295,10 +291,9 @@ func FindFirstFile(name *uint16, data *Win32finddata) (handle int32, errno int)
return return
} }
func FindNextFile(handle int32, data *Win32finddata) (ok bool, errno int) { func FindNextFile(handle int32, data *Win32finddata) (errno int) {
r0, _, e1 := Syscall(procFindNextFileW, 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0) r1, _, e1 := Syscall(procFindNextFileW, 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -310,10 +305,9 @@ func FindNextFile(handle int32, data *Win32finddata) (ok bool, errno int) {
return return
} }
func FindClose(handle int32) (ok bool, errno int) { func FindClose(handle int32) (errno int) {
r0, _, e1 := Syscall(procFindClose, 1, uintptr(handle), 0, 0) r1, _, e1 := Syscall(procFindClose, 1, uintptr(handle), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -325,10 +319,9 @@ func FindClose(handle int32) (ok bool, errno int) {
return return
} }
func GetFileInformationByHandle(handle int32, data *ByHandleFileInformation) (ok bool, errno int) { func GetFileInformationByHandle(handle int32, data *ByHandleFileInformation) (errno int) {
r0, _, e1 := Syscall(procGetFileInformationByHandle, 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0) r1, _, e1 := Syscall(procGetFileInformationByHandle, 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -355,10 +348,9 @@ func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, errno int) {
return return
} }
func SetCurrentDirectory(path *uint16) (ok bool, errno int) { func SetCurrentDirectory(path *uint16) (errno int) {
r0, _, e1 := Syscall(procSetCurrentDirectoryW, 1, uintptr(unsafe.Pointer(path)), 0, 0) r1, _, e1 := Syscall(procSetCurrentDirectoryW, 1, uintptr(unsafe.Pointer(path)), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -370,10 +362,9 @@ func SetCurrentDirectory(path *uint16) (ok bool, errno int) {
return return
} }
func CreateDirectory(path *uint16, sa *SecurityAttributes) (ok bool, errno int) { func CreateDirectory(path *uint16, sa *SecurityAttributes) (errno int) {
r0, _, e1 := Syscall(procCreateDirectoryW, 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0) r1, _, e1 := Syscall(procCreateDirectoryW, 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -385,10 +376,9 @@ func CreateDirectory(path *uint16, sa *SecurityAttributes) (ok bool, errno int)
return return
} }
func RemoveDirectory(path *uint16) (ok bool, errno int) { func RemoveDirectory(path *uint16) (errno int) {
r0, _, e1 := Syscall(procRemoveDirectoryW, 1, uintptr(unsafe.Pointer(path)), 0, 0) r1, _, e1 := Syscall(procRemoveDirectoryW, 1, uintptr(unsafe.Pointer(path)), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -400,10 +390,9 @@ func RemoveDirectory(path *uint16) (ok bool, errno int) {
return return
} }
func DeleteFile(path *uint16) (ok bool, errno int) { func DeleteFile(path *uint16) (errno int) {
r0, _, e1 := Syscall(procDeleteFileW, 1, uintptr(unsafe.Pointer(path)), 0, 0) r1, _, e1 := Syscall(procDeleteFileW, 1, uintptr(unsafe.Pointer(path)), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -415,10 +404,9 @@ func DeleteFile(path *uint16) (ok bool, errno int) {
return return
} }
func MoveFile(from *uint16, to *uint16) (ok bool, errno int) { func MoveFile(from *uint16, to *uint16) (errno int) {
r0, _, e1 := Syscall(procMoveFileW, 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0) r1, _, e1 := Syscall(procMoveFileW, 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -430,10 +418,9 @@ func MoveFile(from *uint16, to *uint16) (ok bool, errno int) {
return return
} }
func GetComputerName(buf *uint16, n *uint32) (ok bool, errno int) { func GetComputerName(buf *uint16, n *uint32) (errno int) {
r0, _, e1 := Syscall(procGetComputerNameW, 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0) r1, _, e1 := Syscall(procGetComputerNameW, 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -445,10 +432,9 @@ func GetComputerName(buf *uint16, n *uint32) (ok bool, errno int) {
return return
} }
func SetEndOfFile(handle int32) (ok bool, errno int) { func SetEndOfFile(handle int32) (errno int) {
r0, _, e1 := Syscall(procSetEndOfFile, 1, uintptr(handle), 0, 0) r1, _, e1 := Syscall(procSetEndOfFile, 1, uintptr(handle), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -500,10 +486,9 @@ func CreateIoCompletionPort(filehandle int32, cphandle int32, key uint32, thread
return return
} }
func GetQueuedCompletionStatus(cphandle int32, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (ok bool, errno int) { func GetQueuedCompletionStatus(cphandle int32, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (errno int) {
r0, _, e1 := Syscall6(procGetQueuedCompletionStatus, 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0) r1, _, e1 := Syscall6(procGetQueuedCompletionStatus, 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -515,10 +500,9 @@ func GetQueuedCompletionStatus(cphandle int32, qty *uint32, key *uint32, overlap
return return
} }
func CancelIo(s uint32) (ok bool, errno int) { func CancelIo(s uint32) (errno int) {
r0, _, e1 := Syscall(procCancelIo, 1, uintptr(s), 0, 0) r1, _, e1 := Syscall(procCancelIo, 1, uintptr(s), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -530,16 +514,15 @@ func CancelIo(s uint32) (ok bool, errno int) {
return return
} }
func CreateProcess(appName *int16, commandLine *uint16, procSecurity *int16, threadSecurity *int16, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (ok bool, errno int) { func CreateProcess(appName *int16, commandLine *uint16, procSecurity *int16, threadSecurity *int16, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (errno int) {
var _p0 uint32 var _p0 uint32
if inheritHandles { if inheritHandles {
_p0 = 1 _p0 = 1
} else { } else {
_p0 = 0 _p0 = 0
} }
r0, _, e1 := Syscall12(procCreateProcessW, 10, uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0, 0) r1, _, e1 := Syscall12(procCreateProcessW, 10, uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -572,10 +555,9 @@ func OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle uint32, errn
return return
} }
func GetExitCodeProcess(handle uint32, exitcode *uint32) (ok bool, errno int) { func GetExitCodeProcess(handle uint32, exitcode *uint32) (errno int) {
r0, _, e1 := Syscall(procGetExitCodeProcess, 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0) r1, _, e1 := Syscall(procGetExitCodeProcess, 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -587,10 +569,9 @@ func GetExitCodeProcess(handle uint32, exitcode *uint32) (ok bool, errno int) {
return return
} }
func GetStartupInfo(startupInfo *StartupInfo) (ok bool, errno int) { func GetStartupInfo(startupInfo *StartupInfo) (errno int) {
r0, _, e1 := Syscall(procGetStartupInfoW, 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0) r1, _, e1 := Syscall(procGetStartupInfoW, 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -617,16 +598,15 @@ func GetCurrentProcess() (pseudoHandle int32, errno int) {
return return
} }
func DuplicateHandle(hSourceProcessHandle int32, hSourceHandle int32, hTargetProcessHandle int32, lpTargetHandle *int32, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (ok bool, errno int) { func DuplicateHandle(hSourceProcessHandle int32, hSourceHandle int32, hTargetProcessHandle int32, lpTargetHandle *int32, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (errno int) {
var _p0 uint32 var _p0 uint32
if bInheritHandle { if bInheritHandle {
_p0 = 1 _p0 = 1
} else { } else {
_p0 = 0 _p0 = 0
} }
r0, _, e1 := Syscall9(procDuplicateHandle, 7, uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions), 0, 0) r1, _, e1 := Syscall9(procDuplicateHandle, 7, uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -668,10 +648,9 @@ func GetTempPath(buflen uint32, buf *uint16) (n uint32, errno int) {
return return
} }
func CreatePipe(readhandle *uint32, writehandle *uint32, sa *SecurityAttributes, size uint32) (ok bool, errno int) { func CreatePipe(readhandle *uint32, writehandle *uint32, sa *SecurityAttributes, size uint32) (errno int) {
r0, _, e1 := Syscall6(procCreatePipe, 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0) r1, _, e1 := Syscall6(procCreatePipe, 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -698,10 +677,9 @@ func GetFileType(filehandle uint32) (n uint32, errno int) {
return return
} }
func CryptAcquireContext(provhandle *uint32, container *uint16, provider *uint16, provtype uint32, flags uint32) (ok bool, errno int) { func CryptAcquireContext(provhandle *uint32, container *uint16, provider *uint16, provtype uint32, flags uint32) (errno int) {
r0, _, e1 := Syscall6(procCryptAcquireContextW, 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0) r1, _, e1 := Syscall6(procCryptAcquireContextW, 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -713,10 +691,9 @@ func CryptAcquireContext(provhandle *uint32, container *uint16, provider *uint16
return return
} }
func CryptReleaseContext(provhandle uint32, flags uint32) (ok bool, errno int) { func CryptReleaseContext(provhandle uint32, flags uint32) (errno int) {
r0, _, e1 := Syscall(procCryptReleaseContext, 2, uintptr(provhandle), uintptr(flags), 0) r1, _, e1 := Syscall(procCryptReleaseContext, 2, uintptr(provhandle), uintptr(flags), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -728,10 +705,9 @@ func CryptReleaseContext(provhandle uint32, flags uint32) (ok bool, errno int) {
return return
} }
func CryptGenRandom(provhandle uint32, buflen uint32, buf *byte) (ok bool, errno int) { func CryptGenRandom(provhandle uint32, buflen uint32, buf *byte) (errno int) {
r0, _, e1 := Syscall(procCryptGenRandom, 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf))) r1, _, e1 := Syscall(procCryptGenRandom, 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf)))
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -758,10 +734,9 @@ func GetEnvironmentStrings() (envs *uint16, errno int) {
return return
} }
func FreeEnvironmentStrings(envs *uint16) (ok bool, errno int) { func FreeEnvironmentStrings(envs *uint16) (errno int) {
r0, _, e1 := Syscall(procFreeEnvironmentStringsW, 1, uintptr(unsafe.Pointer(envs)), 0, 0) r1, _, e1 := Syscall(procFreeEnvironmentStringsW, 1, uintptr(unsafe.Pointer(envs)), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -788,10 +763,9 @@ func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32
return return
} }
func SetEnvironmentVariable(name *uint16, value *uint16) (ok bool, errno int) { func SetEnvironmentVariable(name *uint16, value *uint16) (errno int) {
r0, _, e1 := Syscall(procSetEnvironmentVariableW, 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0) r1, _, e1 := Syscall(procSetEnvironmentVariableW, 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -803,10 +777,9 @@ func SetEnvironmentVariable(name *uint16, value *uint16) (ok bool, errno int) {
return return
} }
func SetFileTime(handle int32, ctime *Filetime, atime *Filetime, wtime *Filetime) (ok bool, errno int) { func SetFileTime(handle int32, ctime *Filetime, atime *Filetime, wtime *Filetime) (errno int) {
r0, _, e1 := Syscall6(procSetFileTime, 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0) r1, _, e1 := Syscall6(procSetFileTime, 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -869,10 +842,9 @@ func LocalFree(hmem uint32) (handle uint32, errno int) {
return return
} }
func SetHandleInformation(handle int32, mask uint32, flags uint32) (ok bool, errno int) { func SetHandleInformation(handle int32, mask uint32, flags uint32) (errno int) {
r0, _, e1 := Syscall(procSetHandleInformation, 3, uintptr(handle), uintptr(mask), uintptr(flags)) r1, _, e1 := Syscall(procSetHandleInformation, 3, uintptr(handle), uintptr(mask), uintptr(flags))
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -884,10 +856,9 @@ func SetHandleInformation(handle int32, mask uint32, flags uint32) (ok bool, err
return return
} }
func FlushFileBuffers(handle int32) (ok bool, errno int) { func FlushFileBuffers(handle int32) (errno int) {
r0, _, e1 := Syscall(procFlushFileBuffers, 1, uintptr(handle), 0, 0) r1, _, e1 := Syscall(procFlushFileBuffers, 1, uintptr(handle), 0, 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {
@ -1046,10 +1017,9 @@ func Closesocket(s int32) (errno int) {
return return
} }
func AcceptEx(ls uint32, as uint32, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (ok bool, errno int) { func AcceptEx(ls uint32, as uint32, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (errno int) {
r0, _, e1 := Syscall9(procAcceptEx, 8, uintptr(ls), uintptr(as), uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(overlapped)), 0) r1, _, e1 := Syscall9(procAcceptEx, 8, uintptr(ls), uintptr(as), uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(overlapped)), 0)
ok = bool(r0 != 0) if int(r1) == 0 {
if !ok {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
} else { } else {