2010-03-09 16:09:09 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Windows system calls.
|
|
|
|
|
|
|
|
package syscall
|
|
|
|
|
2010-03-17 00:10:07 -06:00
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
"utf16"
|
|
|
|
)
|
2010-03-09 16:09:09 -07:00
|
|
|
|
2010-04-30 00:45:14 -06:00
|
|
|
const OS = "windows"
|
2010-03-09 16:09:09 -07:00
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
type Handle uintptr
|
|
|
|
|
|
|
|
const InvalidHandle = ^Handle(0)
|
|
|
|
|
2010-03-09 16:09:09 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
small demo to detect version of windows you are running:
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2010-03-17 00:10:07 -06:00
|
|
|
func abort(funcname string, err int) {
|
2010-03-30 14:15:16 -06:00
|
|
|
panic(funcname + " failed: " + syscall.Errstr(err))
|
2010-03-17 00:10:07 -06:00
|
|
|
}
|
|
|
|
|
2010-03-09 16:09:09 -07:00
|
|
|
func print_version(v uint32) {
|
|
|
|
major := byte(v)
|
|
|
|
minor := uint8(v >> 8)
|
|
|
|
build := uint16(v >> 16)
|
|
|
|
print("windows version ", major, ".", minor, " (Build ", build, ")\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
h, err := syscall.LoadLibrary("kernel32.dll")
|
|
|
|
if err != 0 {
|
2010-03-17 00:10:07 -06:00
|
|
|
abort("LoadLibrary", err)
|
2010-03-09 16:09:09 -07:00
|
|
|
}
|
|
|
|
defer syscall.FreeLibrary(h)
|
|
|
|
proc, err := syscall.GetProcAddress(h, "GetVersion")
|
|
|
|
if err != 0 {
|
2010-03-17 00:10:07 -06:00
|
|
|
abort("GetProcAddress", err)
|
2010-03-09 16:09:09 -07:00
|
|
|
}
|
2011-02-01 09:49:24 -07:00
|
|
|
r, _, _ := syscall.Syscall(uintptr(proc), 0, 0, 0, 0)
|
2010-03-09 16:09:09 -07:00
|
|
|
print_version(uint32(r))
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-03-17 00:10:07 -06:00
|
|
|
// StringToUTF16 returns the UTF-16 encoding of the UTF-8 string s,
|
|
|
|
// with a terminating NUL added.
|
|
|
|
func StringToUTF16(s string) []uint16 { return utf16.Encode([]int(s + "\x00")) }
|
2010-03-09 16:09:09 -07:00
|
|
|
|
2010-03-17 00:10:07 -06:00
|
|
|
// UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s,
|
|
|
|
// with a terminating NUL removed.
|
|
|
|
func UTF16ToString(s []uint16) string {
|
2010-04-13 17:30:11 -06:00
|
|
|
for i, v := range s {
|
|
|
|
if v == 0 {
|
|
|
|
s = s[0:i]
|
|
|
|
break
|
|
|
|
}
|
2010-03-09 16:09:09 -07:00
|
|
|
}
|
2010-03-17 00:10:07 -06:00
|
|
|
return string(utf16.Decode(s))
|
2010-03-09 16:09:09 -07:00
|
|
|
}
|
|
|
|
|
2010-03-17 00:10:07 -06:00
|
|
|
// StringToUTF16Ptr returns pointer to the UTF-16 encoding of
|
|
|
|
// the UTF-8 string s, with a terminating NUL added.
|
|
|
|
func StringToUTF16Ptr(s string) *uint16 { return &StringToUTF16(s)[0] }
|
2010-03-09 16:09:09 -07:00
|
|
|
|
|
|
|
// dll helpers
|
|
|
|
|
2011-07-25 10:25:23 -06:00
|
|
|
// Implemented in ../runtime/windows/syscall.goc
|
2011-02-01 09:49:24 -07:00
|
|
|
func Syscall(trap, nargs, a1, a2, a3 uintptr) (r1, r2, err uintptr)
|
|
|
|
func Syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
|
|
|
|
func Syscall9(trap, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, err uintptr)
|
|
|
|
func Syscall12(trap, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 uintptr) (r1, r2, err uintptr)
|
2011-07-01 08:18:07 -06:00
|
|
|
func loadlibraryex(filename uintptr) (handle uintptr)
|
|
|
|
func getprocaddress(handle uintptr, procname uintptr) (proc uintptr)
|
2010-03-09 16:09:09 -07:00
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func loadDll(fname string) uintptr {
|
2010-03-09 16:09:09 -07:00
|
|
|
m := loadlibraryex(uintptr(unsafe.Pointer(StringBytePtr(fname))))
|
|
|
|
if m == 0 {
|
2010-03-30 14:15:16 -06:00
|
|
|
panic("syscall: could not LoadLibraryEx " + fname)
|
2010-03-09 16:09:09 -07:00
|
|
|
}
|
2010-03-17 00:10:07 -06:00
|
|
|
return m
|
2010-03-09 16:09:09 -07:00
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func getSysProcAddr(m uintptr, pname string) uintptr {
|
2010-03-17 00:10:07 -06:00
|
|
|
p := getprocaddress(m, uintptr(unsafe.Pointer(StringBytePtr(pname))))
|
2010-03-09 16:09:09 -07:00
|
|
|
if p == 0 {
|
2010-03-30 14:15:16 -06:00
|
|
|
panic("syscall: could not GetProcAddress for " + pname)
|
2010-03-09 16:09:09 -07:00
|
|
|
}
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2011-07-06 18:40:45 -06:00
|
|
|
func Getpagesize() int { return 4096 }
|
|
|
|
|
2011-02-01 09:49:24 -07:00
|
|
|
// Converts a Go function to a function pointer conforming
|
|
|
|
// to the stdcall calling convention. This is useful when
|
|
|
|
// interoperating with Windows code requiring callbacks.
|
2011-07-25 10:25:23 -06:00
|
|
|
// Implemented in ../runtime/windows/syscall.goc
|
2011-02-01 09:49:24 -07:00
|
|
|
func NewCallback(fn interface{}) uintptr
|
2011-01-21 19:55:53 -07:00
|
|
|
|
2010-03-17 00:10:07 -06:00
|
|
|
// windows api calls
|
|
|
|
|
|
|
|
//sys GetLastError() (lasterrno int)
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys LoadLibrary(libname string) (handle Handle, errno int) = LoadLibraryW
|
|
|
|
//sys FreeLibrary(handle Handle) (errno int)
|
|
|
|
//sys GetProcAddress(module Handle, procname string) (proc Handle, errno int)
|
2010-03-17 00:10:07 -06:00
|
|
|
//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
|
2010-04-02 02:11:17 -06:00
|
|
|
//sys ExitProcess(exitcode uint32)
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, errno int) [failretval==InvalidHandle] = CreateFileW
|
|
|
|
//sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (errno int)
|
|
|
|
//sys WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (errno int)
|
|
|
|
//sys SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, errno int) [failretval==0xffffffff]
|
|
|
|
//sys CloseHandle(handle Handle) (errno int)
|
|
|
|
//sys GetStdHandle(stdhandle int) (handle Handle, errno int) [failretval==InvalidHandle]
|
|
|
|
//sys FindFirstFile(name *uint16, data *Win32finddata) (handle Handle, errno int) [failretval==InvalidHandle] = FindFirstFileW
|
|
|
|
//sys FindNextFile(handle Handle, data *Win32finddata) (errno int) = FindNextFileW
|
|
|
|
//sys FindClose(handle Handle) (errno int)
|
|
|
|
//sys GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (errno int)
|
2010-04-27 00:17:14 -06:00
|
|
|
//sys GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, errno int) = GetCurrentDirectoryW
|
2011-02-10 16:15:51 -07:00
|
|
|
//sys SetCurrentDirectory(path *uint16) (errno int) = SetCurrentDirectoryW
|
|
|
|
//sys CreateDirectory(path *uint16, sa *SecurityAttributes) (errno int) = CreateDirectoryW
|
|
|
|
//sys RemoveDirectory(path *uint16) (errno int) = RemoveDirectoryW
|
|
|
|
//sys DeleteFile(path *uint16) (errno int) = DeleteFileW
|
|
|
|
//sys MoveFile(from *uint16, to *uint16) (errno int) = MoveFileW
|
|
|
|
//sys GetComputerName(buf *uint16, n *uint32) (errno int) = GetComputerNameW
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys SetEndOfFile(handle Handle) (errno int)
|
2010-04-27 00:17:14 -06:00
|
|
|
//sys GetSystemTimeAsFileTime(time *Filetime)
|
2010-06-29 23:29:09 -06:00
|
|
|
//sys sleep(msec uint32) = Sleep
|
2010-12-15 18:18:18 -07:00
|
|
|
//sys GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, errno int) [failretval==0xffffffff]
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, errno int)
|
|
|
|
//sys GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (errno int)
|
|
|
|
//sys CancelIo(s Handle) (errno int)
|
2011-03-23 18:20:28 -06:00
|
|
|
//sys CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (errno int) = CreateProcessW
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, errno int)
|
|
|
|
//sys TerminateProcess(handle Handle, exitcode uint32) (errno int)
|
|
|
|
//sys GetExitCodeProcess(handle Handle, exitcode *uint32) (errno int)
|
2011-02-10 16:15:51 -07:00
|
|
|
//sys GetStartupInfo(startupInfo *StartupInfo) (errno int) = GetStartupInfoW
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys GetCurrentProcess() (pseudoHandle Handle, errno int)
|
|
|
|
//sys DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (errno int)
|
|
|
|
//sys WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, errno int) [failretval==0xffffffff]
|
2010-06-30 14:52:34 -06:00
|
|
|
//sys GetTempPath(buflen uint32, buf *uint16) (n uint32, errno int) = GetTempPathW
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (errno int)
|
|
|
|
//sys GetFileType(filehandle Handle) (n uint32, errno int)
|
|
|
|
//sys CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (errno int) = advapi32.CryptAcquireContextW
|
|
|
|
//sys CryptReleaseContext(provhandle Handle, flags uint32) (errno int) = advapi32.CryptReleaseContext
|
|
|
|
//sys CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (errno int) = advapi32.CryptGenRandom
|
2010-12-15 18:18:18 -07:00
|
|
|
//sys GetEnvironmentStrings() (envs *uint16, errno int) [failretval==nil] = kernel32.GetEnvironmentStringsW
|
2011-02-10 16:15:51 -07:00
|
|
|
//sys FreeEnvironmentStrings(envs *uint16) (errno int) = kernel32.FreeEnvironmentStringsW
|
2010-08-12 22:29:23 -06:00
|
|
|
//sys GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, errno int) = kernel32.GetEnvironmentVariableW
|
2011-02-10 16:15:51 -07:00
|
|
|
//sys SetEnvironmentVariable(name *uint16, value *uint16) (errno int) = kernel32.SetEnvironmentVariableW
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (errno int)
|
2010-12-15 18:18:18 -07:00
|
|
|
//sys GetFileAttributes(name *uint16) (attrs uint32, errno int) [failretval==INVALID_FILE_ATTRIBUTES] = kernel32.GetFileAttributesW
|
2011-02-16 18:09:12 -07:00
|
|
|
//sys SetFileAttributes(name *uint16, attrs uint32) (errno int) = kernel32.SetFileAttributesW
|
2010-12-15 18:18:18 -07:00
|
|
|
//sys GetCommandLine() (cmd *uint16) = kernel32.GetCommandLineW
|
|
|
|
//sys CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, errno int) [failretval==nil] = shell32.CommandLineToArgvW
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys LocalFree(hmem Handle) (handle Handle, errno int) [failretval!=0]
|
|
|
|
//sys SetHandleInformation(handle Handle, mask uint32, flags uint32) (errno int)
|
|
|
|
//sys FlushFileBuffers(handle Handle) (errno int)
|
2011-03-23 18:20:28 -06:00
|
|
|
//sys GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, errno int) = kernel32.GetFullPathNameW
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, errno int) = kernel32.CreateFileMappingW
|
|
|
|
//sys MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, errno int)
|
2011-05-01 17:35:55 -06:00
|
|
|
//sys UnmapViewOfFile(addr uintptr) (errno int)
|
|
|
|
//sys FlushViewOfFile(addr uintptr, length uintptr) (errno int)
|
|
|
|
//sys VirtualLock(addr uintptr, length uintptr) (errno int)
|
|
|
|
//sys VirtualUnlock(addr uintptr, length uintptr) (errno int)
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (errno int) = wsock32.TransmitFile
|
2010-04-02 02:11:17 -06:00
|
|
|
|
|
|
|
// syscall interface implementation for other packages
|
2010-03-17 00:10:07 -06:00
|
|
|
|
2010-03-19 16:21:37 -06:00
|
|
|
func Errstr(errno int) string {
|
2010-08-02 20:04:41 -06:00
|
|
|
// deal with special go errors
|
|
|
|
e := errno - APPLICATION_ERROR
|
|
|
|
if 0 <= e && e < len(errors) {
|
|
|
|
return errors[e]
|
2010-03-17 00:10:07 -06:00
|
|
|
}
|
2010-08-02 20:04:41 -06:00
|
|
|
// ask windows for the remaining errors
|
2010-07-21 10:40:08 -06:00
|
|
|
var flags uint32 = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_IGNORE_INSERTS
|
2010-04-27 00:17:14 -06:00
|
|
|
b := make([]uint16, 300)
|
2010-07-21 10:40:08 -06:00
|
|
|
n, err := FormatMessage(flags, 0, uint32(errno), 0, b, nil)
|
2010-03-17 00:10:07 -06:00
|
|
|
if err != 0 {
|
2011-04-02 15:24:03 -06:00
|
|
|
return "error " + itoa(errno) + " (FormatMessage failed with err=" + itoa(err) + ")"
|
2010-03-17 00:10:07 -06:00
|
|
|
}
|
2010-12-12 23:02:01 -07:00
|
|
|
// trim terminating \r and \n
|
|
|
|
for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
|
|
|
|
}
|
|
|
|
return string(utf16.Decode(b[:n]))
|
2010-03-17 00:10:07 -06:00
|
|
|
}
|
|
|
|
|
2010-04-02 02:11:17 -06:00
|
|
|
func Exit(code int) { ExitProcess(uint32(code)) }
|
|
|
|
|
2011-02-02 18:50:41 -07:00
|
|
|
func makeInheritSa() *SecurityAttributes {
|
|
|
|
var sa SecurityAttributes
|
|
|
|
sa.Length = uint32(unsafe.Sizeof(sa))
|
|
|
|
sa.InheritHandle = 1
|
|
|
|
return &sa
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Open(path string, mode int, perm uint32) (fd Handle, errno int) {
|
2010-04-02 02:11:17 -06:00
|
|
|
if len(path) == 0 {
|
2011-07-01 08:18:07 -06:00
|
|
|
return InvalidHandle, ERROR_FILE_NOT_FOUND
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|
2010-04-13 23:30:41 -06:00
|
|
|
var access uint32
|
|
|
|
switch mode & (O_RDONLY | O_WRONLY | O_RDWR) {
|
|
|
|
case O_RDONLY:
|
2010-04-02 02:11:17 -06:00
|
|
|
access = GENERIC_READ
|
2010-04-13 23:30:41 -06:00
|
|
|
case O_WRONLY:
|
2010-04-02 02:11:17 -06:00
|
|
|
access = GENERIC_WRITE
|
2010-04-13 23:30:41 -06:00
|
|
|
case O_RDWR:
|
2010-04-02 02:11:17 -06:00
|
|
|
access = GENERIC_READ | GENERIC_WRITE
|
|
|
|
}
|
2010-04-13 23:30:41 -06:00
|
|
|
if mode&O_CREAT != 0 {
|
|
|
|
access |= GENERIC_WRITE
|
|
|
|
}
|
2010-09-21 21:12:25 -06:00
|
|
|
if mode&O_APPEND != 0 {
|
|
|
|
access &^= GENERIC_WRITE
|
|
|
|
access |= FILE_APPEND_DATA
|
|
|
|
}
|
2010-04-13 23:30:41 -06:00
|
|
|
sharemode := uint32(FILE_SHARE_READ | FILE_SHARE_WRITE)
|
2011-02-02 18:50:41 -07:00
|
|
|
var sa *SecurityAttributes
|
|
|
|
if mode&O_CLOEXEC == 0 {
|
|
|
|
sa = makeInheritSa()
|
|
|
|
}
|
2010-04-02 02:11:17 -06:00
|
|
|
var createmode uint32
|
|
|
|
switch {
|
2011-05-27 01:02:24 -06:00
|
|
|
case mode&(O_CREAT|O_EXCL) == (O_CREAT | O_EXCL):
|
|
|
|
createmode = CREATE_NEW
|
|
|
|
case mode&(O_CREAT|O_TRUNC) == (O_CREAT | O_TRUNC):
|
|
|
|
createmode = CREATE_ALWAYS
|
|
|
|
case mode&O_CREAT == O_CREAT:
|
|
|
|
createmode = OPEN_ALWAYS
|
|
|
|
case mode&O_TRUNC == O_TRUNC:
|
2010-04-02 02:11:17 -06:00
|
|
|
createmode = TRUNCATE_EXISTING
|
|
|
|
default:
|
|
|
|
createmode = OPEN_EXISTING
|
|
|
|
}
|
2011-02-02 18:50:41 -07:00
|
|
|
h, e := CreateFile(StringToUTF16Ptr(path), access, sharemode, sa, createmode, FILE_ATTRIBUTE_NORMAL, 0)
|
2011-07-01 08:18:07 -06:00
|
|
|
return h, int(e)
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Read(fd Handle, p []byte) (n int, errno int) {
|
2010-04-02 02:11:17 -06:00
|
|
|
var done uint32
|
2011-07-01 08:18:07 -06:00
|
|
|
e := ReadFile(fd, p, &done, nil)
|
2011-02-10 16:15:51 -07:00
|
|
|
if e != 0 {
|
2010-04-30 13:46:46 -06:00
|
|
|
if e == ERROR_BROKEN_PIPE {
|
2010-08-24 23:26:35 -06:00
|
|
|
// NOTE(brainman): work around ERROR_BROKEN_PIPE is returned on reading EOF from stdin
|
2010-04-30 13:46:46 -06:00
|
|
|
return 0, 0
|
|
|
|
}
|
2010-04-02 02:11:17 -06:00
|
|
|
return 0, e
|
|
|
|
}
|
|
|
|
return int(done), 0
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Write(fd Handle, p []byte) (n int, errno int) {
|
2010-04-02 02:11:17 -06:00
|
|
|
var done uint32
|
2011-07-01 08:18:07 -06:00
|
|
|
e := WriteFile(fd, p, &done, nil)
|
2011-02-10 16:15:51 -07:00
|
|
|
if e != 0 {
|
2010-04-02 02:11:17 -06:00
|
|
|
return 0, e
|
|
|
|
}
|
|
|
|
return int(done), 0
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Seek(fd Handle, offset int64, whence int) (newoffset int64, errno int) {
|
2010-04-02 02:11:17 -06:00
|
|
|
var w uint32
|
|
|
|
switch whence {
|
|
|
|
case 0:
|
|
|
|
w = FILE_BEGIN
|
|
|
|
case 1:
|
|
|
|
w = FILE_CURRENT
|
|
|
|
case 2:
|
|
|
|
w = FILE_END
|
|
|
|
}
|
|
|
|
hi := int32(offset >> 32)
|
|
|
|
lo := int32(offset)
|
2010-07-25 23:55:01 -06:00
|
|
|
// use GetFileType to check pipe, pipe can't do seek
|
2011-07-01 08:18:07 -06:00
|
|
|
ft, _ := GetFileType(fd)
|
2010-07-25 23:55:01 -06:00
|
|
|
if ft == FILE_TYPE_PIPE {
|
|
|
|
return 0, EPIPE
|
|
|
|
}
|
2011-07-01 08:18:07 -06:00
|
|
|
rlo, e := SetFilePointer(fd, lo, &hi, w)
|
2010-04-02 02:11:17 -06:00
|
|
|
if e != 0 {
|
|
|
|
return 0, e
|
|
|
|
}
|
|
|
|
return int64(hi)<<32 + int64(rlo), 0
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Close(fd Handle) (errno int) {
|
|
|
|
return CloseHandle(fd)
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
Stdin = getStdHandle(STD_INPUT_HANDLE)
|
|
|
|
Stdout = getStdHandle(STD_OUTPUT_HANDLE)
|
|
|
|
Stderr = getStdHandle(STD_ERROR_HANDLE)
|
|
|
|
)
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func getStdHandle(h int) (fd Handle) {
|
2010-04-02 02:11:17 -06:00
|
|
|
r, _ := GetStdHandle(h)
|
2011-07-01 08:18:07 -06:00
|
|
|
return r
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|
|
|
|
|
2010-04-13 17:30:11 -06:00
|
|
|
func Stat(path string, stat *Stat_t) (errno int) {
|
2010-10-30 06:55:22 -06:00
|
|
|
if len(path) == 0 {
|
|
|
|
return ERROR_PATH_NOT_FOUND
|
|
|
|
}
|
2010-10-30 06:06:49 -06:00
|
|
|
// Remove trailing slash.
|
|
|
|
if path[len(path)-1] == '/' || path[len(path)-1] == '\\' {
|
|
|
|
// Check if we're given root directory ("\" or "c:\").
|
|
|
|
if len(path) == 1 || (len(path) == 3 && path[1] == ':') {
|
|
|
|
// TODO(brainman): Perhaps should fetch other fields, not just FileAttributes.
|
|
|
|
stat.Windata = Win32finddata{}
|
|
|
|
a, e := GetFileAttributes(StringToUTF16Ptr(path))
|
|
|
|
if e != 0 {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
stat.Windata.FileAttributes = a
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
path = path[:len(path)-1]
|
|
|
|
}
|
2010-04-13 17:30:11 -06:00
|
|
|
h, e := FindFirstFile(StringToUTF16Ptr(path), &stat.Windata)
|
|
|
|
if e != 0 {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
defer FindClose(h)
|
|
|
|
stat.Mode = 0
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func Lstat(path string, stat *Stat_t) (errno int) {
|
|
|
|
// no links on windows, just call Stat
|
|
|
|
return Stat(path, stat)
|
|
|
|
}
|
|
|
|
|
2010-04-27 00:17:14 -06:00
|
|
|
const ImplementsGetwd = true
|
|
|
|
|
|
|
|
func Getwd() (wd string, errno int) {
|
|
|
|
b := make([]uint16, 300)
|
|
|
|
n, e := GetCurrentDirectory(uint32(len(b)), &b[0])
|
|
|
|
if e != 0 {
|
|
|
|
return "", e
|
|
|
|
}
|
|
|
|
return string(utf16.Decode(b[0:n])), 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func Chdir(path string) (errno int) {
|
2011-02-10 16:15:51 -07:00
|
|
|
return SetCurrentDirectory(&StringToUTF16(path)[0])
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
|
2010-08-03 16:34:52 -06:00
|
|
|
func Mkdir(path string, mode uint32) (errno int) {
|
2011-02-10 16:15:51 -07:00
|
|
|
return CreateDirectory(&StringToUTF16(path)[0], nil)
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func Rmdir(path string) (errno int) {
|
2011-02-10 16:15:51 -07:00
|
|
|
return RemoveDirectory(&StringToUTF16(path)[0])
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func Unlink(path string) (errno int) {
|
2011-02-10 16:15:51 -07:00
|
|
|
return DeleteFile(&StringToUTF16(path)[0])
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func Rename(oldpath, newpath string) (errno int) {
|
|
|
|
from := &StringToUTF16(oldpath)[0]
|
|
|
|
to := &StringToUTF16(newpath)[0]
|
2011-02-10 16:15:51 -07:00
|
|
|
return MoveFile(from, to)
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func ComputerName() (name string, errno int) {
|
|
|
|
var n uint32 = MAX_COMPUTERNAME_LENGTH + 1
|
|
|
|
b := make([]uint16, n)
|
2011-02-10 16:15:51 -07:00
|
|
|
e := GetComputerName(&b[0], &n)
|
|
|
|
if e != 0 {
|
2010-04-27 00:17:14 -06:00
|
|
|
return "", e
|
|
|
|
}
|
|
|
|
return string(utf16.Decode(b[0:n])), 0
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Ftruncate(fd Handle, length int64) (errno int) {
|
2010-04-27 00:17:14 -06:00
|
|
|
curoffset, e := Seek(fd, 0, 1)
|
|
|
|
if e != 0 {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
defer Seek(fd, curoffset, 0)
|
2011-02-10 16:15:51 -07:00
|
|
|
_, e = Seek(fd, length, 0)
|
|
|
|
if e != 0 {
|
2010-04-27 00:17:14 -06:00
|
|
|
return e
|
|
|
|
}
|
2011-07-01 08:18:07 -06:00
|
|
|
e = SetEndOfFile(fd)
|
2011-02-10 16:15:51 -07:00
|
|
|
if e != 0 {
|
2010-04-27 00:17:14 -06:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func Gettimeofday(tv *Timeval) (errno int) {
|
|
|
|
var ft Filetime
|
|
|
|
GetSystemTimeAsFileTime(&ft)
|
2010-09-22 20:36:52 -06:00
|
|
|
*tv = NsecToTimeval(ft.Nanoseconds())
|
2010-04-27 00:17:14 -06:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2010-06-29 23:29:09 -06:00
|
|
|
func Sleep(nsec int64) (errno int) {
|
|
|
|
sleep(uint32((nsec + 1e6 - 1) / 1e6)) // round up to milliseconds
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Pipe(p []Handle) (errno int) {
|
2010-07-25 23:55:01 -06:00
|
|
|
if len(p) != 2 {
|
|
|
|
return EINVAL
|
|
|
|
}
|
2011-07-01 08:18:07 -06:00
|
|
|
var r, w Handle
|
2011-02-10 16:15:51 -07:00
|
|
|
e := CreatePipe(&r, &w, makeInheritSa(), 0)
|
|
|
|
if e != 0 {
|
|
|
|
return e
|
2010-07-25 23:55:01 -06:00
|
|
|
}
|
2011-07-01 08:18:07 -06:00
|
|
|
p[0] = r
|
|
|
|
p[1] = w
|
2010-07-25 23:55:01 -06:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2010-05-24 12:48:14 -06:00
|
|
|
func Utimes(path string, tv []Timeval) (errno int) {
|
2010-09-22 20:36:52 -06:00
|
|
|
if len(tv) != 2 {
|
|
|
|
return EINVAL
|
|
|
|
}
|
|
|
|
h, e := CreateFile(StringToUTF16Ptr(path),
|
|
|
|
FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, nil,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
|
|
|
|
if e != 0 {
|
|
|
|
return e
|
|
|
|
}
|
2011-07-01 08:18:07 -06:00
|
|
|
defer Close(h)
|
2010-09-22 20:36:52 -06:00
|
|
|
a := NsecToFiletime(tv[0].Nanoseconds())
|
|
|
|
w := NsecToFiletime(tv[1].Nanoseconds())
|
2011-02-10 16:15:51 -07:00
|
|
|
return SetFileTime(h, nil, &a, &w)
|
2010-05-24 12:48:14 -06:00
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Fsync(fd Handle) (errno int) {
|
|
|
|
return FlushFileBuffers(fd)
|
2011-02-08 20:54:54 -07:00
|
|
|
}
|
|
|
|
|
2011-02-16 18:09:12 -07:00
|
|
|
func Chmod(path string, mode uint32) (errno int) {
|
|
|
|
if mode == 0 {
|
|
|
|
return EINVAL
|
|
|
|
}
|
|
|
|
p := StringToUTF16Ptr(path)
|
|
|
|
attrs, e := GetFileAttributes(p)
|
|
|
|
if e != 0 {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
if mode&S_IWRITE != 0 {
|
|
|
|
attrs &^= FILE_ATTRIBUTE_READONLY
|
|
|
|
} else {
|
|
|
|
attrs |= FILE_ATTRIBUTE_READONLY
|
|
|
|
}
|
|
|
|
return SetFileAttributes(p, attrs)
|
|
|
|
}
|
|
|
|
|
2010-06-29 21:23:39 -06:00
|
|
|
// net api calls
|
|
|
|
|
|
|
|
//sys WSAStartup(verreq uint32, data *WSAData) (sockerrno int) = wsock32.WSAStartup
|
2010-12-15 18:18:18 -07:00
|
|
|
//sys WSACleanup() (errno int) [failretval==-1] = wsock32.WSACleanup
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (errno int) [failretval==-1] = ws2_32.WSAIoctl
|
|
|
|
//sys socket(af int32, typ int32, protocol int32) (handle Handle, errno int) [failretval==InvalidHandle] = wsock32.socket
|
2011-07-13 16:34:21 -06:00
|
|
|
//sys Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (errno int) [failretval==-1] = wsock32.setsockopt
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys bind(s Handle, name uintptr, namelen int32) (errno int) [failretval==-1] = wsock32.bind
|
|
|
|
//sys connect(s Handle, name uintptr, namelen int32) (errno int) [failretval==-1] = wsock32.connect
|
|
|
|
//sys getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (errno int) [failretval==-1] = wsock32.getsockname
|
|
|
|
//sys getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (errno int) [failretval==-1] = wsock32.getpeername
|
|
|
|
//sys listen(s Handle, backlog int32) (errno int) [failretval==-1] = wsock32.listen
|
|
|
|
//sys shutdown(s Handle, how int32) (errno int) [failretval==-1] = wsock32.shutdown
|
|
|
|
//sys Closesocket(s Handle) (errno int) [failretval==-1] = wsock32.closesocket
|
|
|
|
//sys AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (errno int) = wsock32.AcceptEx
|
2010-06-29 21:23:39 -06:00
|
|
|
//sys GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) = wsock32.GetAcceptExSockaddrs
|
2011-07-01 08:18:07 -06:00
|
|
|
//sys WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (errno int) [failretval==-1] = ws2_32.WSARecv
|
|
|
|
//sys WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (errno int) [failretval==-1] = ws2_32.WSASend
|
|
|
|
//sys WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (errno int) [failretval==-1] = ws2_32.WSARecvFrom
|
|
|
|
//sys WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (errno int) [failretval==-1] = ws2_32.WSASendTo
|
2010-12-15 18:18:18 -07:00
|
|
|
//sys GetHostByName(name string) (h *Hostent, errno int) [failretval==nil] = ws2_32.gethostbyname
|
|
|
|
//sys GetServByName(name string, proto string) (s *Servent, errno int) [failretval==nil] = ws2_32.getservbyname
|
2010-07-28 22:58:28 -06:00
|
|
|
//sys Ntohs(netshort uint16) (u uint16) = ws2_32.ntohs
|
|
|
|
//sys DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status uint32) = dnsapi.DnsQuery_W
|
|
|
|
//sys DnsRecordListFree(rl *DNSRecord, freetype uint32) = dnsapi.DnsRecordListFree
|
2011-06-22 17:54:57 -06:00
|
|
|
//sys GetIfEntry(pIfRow *MibIfRow) (errcode int) = iphlpapi.GetIfEntry
|
|
|
|
//sys GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode int) = iphlpapi.GetAdaptersInfo
|
2010-07-28 22:58:28 -06:00
|
|
|
|
2010-09-11 20:02:29 -06:00
|
|
|
// For testing: clients can set this flag to force
|
|
|
|
// creation of IPv6 sockets to return EAFNOSUPPORT.
|
|
|
|
var SocketDisableIPv6 bool
|
2010-06-29 21:23:39 -06:00
|
|
|
|
|
|
|
type RawSockaddrInet4 struct {
|
|
|
|
Family uint16
|
|
|
|
Port uint16
|
|
|
|
Addr [4]byte /* in_addr */
|
|
|
|
Zero [8]uint8
|
|
|
|
}
|
|
|
|
|
|
|
|
type RawSockaddr struct {
|
|
|
|
Family uint16
|
|
|
|
Data [14]int8
|
|
|
|
}
|
|
|
|
|
|
|
|
type RawSockaddrAny struct {
|
|
|
|
Addr RawSockaddr
|
|
|
|
Pad [96]int8
|
|
|
|
}
|
|
|
|
|
|
|
|
type Sockaddr interface {
|
|
|
|
sockaddr() (ptr uintptr, len int32, errno int) // lowercase; only we can define Sockaddrs
|
|
|
|
}
|
|
|
|
|
|
|
|
type SockaddrInet4 struct {
|
|
|
|
Port int
|
|
|
|
Addr [4]byte
|
|
|
|
raw RawSockaddrInet4
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sa *SockaddrInet4) sockaddr() (uintptr, int32, int) {
|
|
|
|
if sa.Port < 0 || sa.Port > 0xFFFF {
|
|
|
|
return 0, 0, EINVAL
|
|
|
|
}
|
|
|
|
sa.raw.Family = AF_INET
|
|
|
|
p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
|
|
|
|
p[0] = byte(sa.Port >> 8)
|
|
|
|
p[1] = byte(sa.Port)
|
|
|
|
for i := 0; i < len(sa.Addr); i++ {
|
|
|
|
sa.raw.Addr[i] = sa.Addr[i]
|
|
|
|
}
|
|
|
|
return uintptr(unsafe.Pointer(&sa.raw)), int32(unsafe.Sizeof(sa.raw)), 0
|
|
|
|
}
|
|
|
|
|
|
|
|
type SockaddrInet6 struct {
|
2011-05-22 11:09:07 -06:00
|
|
|
Port int
|
|
|
|
ZoneId uint32
|
|
|
|
Addr [16]byte
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (sa *SockaddrInet6) sockaddr() (uintptr, int32, int) {
|
|
|
|
// TODO(brainman): implement SockaddrInet6.sockaddr()
|
|
|
|
return 0, 0, EWINDOWS
|
|
|
|
}
|
|
|
|
|
|
|
|
type SockaddrUnix struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sa *SockaddrUnix) sockaddr() (uintptr, int32, int) {
|
|
|
|
// TODO(brainman): implement SockaddrUnix.sockaddr()
|
|
|
|
return 0, 0, EWINDOWS
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rsa *RawSockaddrAny) Sockaddr() (Sockaddr, int) {
|
|
|
|
switch rsa.Addr.Family {
|
|
|
|
case AF_UNIX:
|
|
|
|
return nil, EWINDOWS
|
|
|
|
|
|
|
|
case AF_INET:
|
|
|
|
pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa))
|
|
|
|
sa := new(SockaddrInet4)
|
|
|
|
p := (*[2]byte)(unsafe.Pointer(&pp.Port))
|
|
|
|
sa.Port = int(p[0])<<8 + int(p[1])
|
|
|
|
for i := 0; i < len(sa.Addr); i++ {
|
|
|
|
sa.Addr[i] = pp.Addr[i]
|
|
|
|
}
|
|
|
|
return sa, 0
|
|
|
|
|
|
|
|
case AF_INET6:
|
|
|
|
return nil, EWINDOWS
|
|
|
|
}
|
|
|
|
return nil, EAFNOSUPPORT
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Socket(domain, typ, proto int) (fd Handle, errno int) {
|
2010-09-11 20:02:29 -06:00
|
|
|
if domain == AF_INET6 && SocketDisableIPv6 {
|
2011-07-01 08:18:07 -06:00
|
|
|
return InvalidHandle, EAFNOSUPPORT
|
2010-09-11 20:02:29 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
h, e := socket(int32(domain), int32(typ), int32(proto))
|
2011-07-01 08:18:07 -06:00
|
|
|
return h, int(e)
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func SetsockoptInt(fd Handle, level, opt int, value int) (errno int) {
|
2010-06-29 21:23:39 -06:00
|
|
|
v := int32(value)
|
2011-07-13 13:44:21 -06:00
|
|
|
return int(Setsockopt(fd, int32(level), int32(opt), (*byte)(unsafe.Pointer(&v)), int32(unsafe.Sizeof(v))))
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Bind(fd Handle, sa Sockaddr) (errno int) {
|
2010-06-29 21:23:39 -06:00
|
|
|
ptr, n, err := sa.sockaddr()
|
|
|
|
if err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
2011-07-01 08:18:07 -06:00
|
|
|
return bind(fd, ptr, n)
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Connect(fd Handle, sa Sockaddr) (errno int) {
|
2010-06-29 21:23:39 -06:00
|
|
|
ptr, n, err := sa.sockaddr()
|
|
|
|
if err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
2011-07-01 08:18:07 -06:00
|
|
|
return connect(fd, ptr, n)
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Getsockname(fd Handle) (sa Sockaddr, errno int) {
|
2010-06-29 21:23:39 -06:00
|
|
|
var rsa RawSockaddrAny
|
|
|
|
l := int32(unsafe.Sizeof(rsa))
|
2011-07-01 08:18:07 -06:00
|
|
|
if errno = getsockname(fd, &rsa, &l); errno != 0 {
|
2010-06-29 21:23:39 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
return rsa.Sockaddr()
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Getpeername(fd Handle) (sa Sockaddr, errno int) {
|
2010-06-29 21:23:39 -06:00
|
|
|
var rsa RawSockaddrAny
|
|
|
|
l := int32(unsafe.Sizeof(rsa))
|
2011-07-01 08:18:07 -06:00
|
|
|
if errno = getpeername(fd, &rsa, &l); errno != 0 {
|
2010-06-29 21:23:39 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
return rsa.Sockaddr()
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Listen(s Handle, n int) (errno int) {
|
|
|
|
return int(listen(s, int32(n)))
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Shutdown(fd Handle, how int) (errno int) {
|
|
|
|
return int(shutdown(fd, int32(how)))
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func WSASendto(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to Sockaddr, overlapped *Overlapped, croutine *byte) (errno int) {
|
2010-11-22 09:01:30 -07:00
|
|
|
rsa, l, err := to.sockaddr()
|
|
|
|
if err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
errno = WSASendTo(s, bufs, bufcnt, sent, flags, (*RawSockaddrAny)(unsafe.Pointer(rsa)), l, overlapped, croutine)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-02-03 20:41:26 -07:00
|
|
|
// Invented structures to support what package os expects.
|
|
|
|
type Rusage struct{}
|
|
|
|
|
|
|
|
type WaitStatus struct {
|
|
|
|
Status uint32
|
|
|
|
ExitCode uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w WaitStatus) Exited() bool { return true }
|
|
|
|
|
|
|
|
func (w WaitStatus) ExitStatus() int { return int(w.ExitCode) }
|
|
|
|
|
|
|
|
func (w WaitStatus) Signal() int { return -1 }
|
|
|
|
|
|
|
|
func (w WaitStatus) CoreDump() bool { return false }
|
|
|
|
|
|
|
|
func (w WaitStatus) Stopped() bool { return false }
|
|
|
|
|
|
|
|
func (w WaitStatus) Continued() bool { return false }
|
|
|
|
|
|
|
|
func (w WaitStatus) StopSignal() int { return -1 }
|
|
|
|
|
2011-04-07 18:27:47 -06:00
|
|
|
func (w WaitStatus) Signaled() bool { return false }
|
2011-02-03 20:41:26 -07:00
|
|
|
|
|
|
|
func (w WaitStatus) TrapCause() int { return -1 }
|
|
|
|
|
2010-06-29 21:23:39 -06:00
|
|
|
// TODO(brainman): fix all needed for net
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Accept(fd Handle) (nfd Handle, sa Sockaddr, errno int) { return 0, nil, EWINDOWS }
|
|
|
|
func Recvfrom(fd Handle, p []byte, flags int) (n int, from Sockaddr, errno int) {
|
|
|
|
return 0, nil, EWINDOWS
|
|
|
|
}
|
|
|
|
func Sendto(fd Handle, p []byte, flags int, to Sockaddr) (errno int) { return EWINDOWS }
|
|
|
|
func SetsockoptTimeval(fd Handle, level, opt int, tv *Timeval) (errno int) { return EWINDOWS }
|
2010-06-29 21:23:39 -06:00
|
|
|
|
|
|
|
type Linger struct {
|
|
|
|
Onoff int32
|
|
|
|
Linger int32
|
|
|
|
}
|
|
|
|
|
2011-02-16 18:00:02 -07:00
|
|
|
const (
|
|
|
|
IP_ADD_MEMBERSHIP = iota
|
|
|
|
IP_DROP_MEMBERSHIP
|
|
|
|
)
|
|
|
|
|
2011-06-02 08:10:17 -06:00
|
|
|
type IPMreq struct {
|
2011-02-16 18:00:02 -07:00
|
|
|
Multiaddr [4]byte /* in_addr */
|
|
|
|
Interface [4]byte /* in_addr */
|
|
|
|
}
|
|
|
|
|
2011-06-02 08:10:17 -06:00
|
|
|
type IPv6Mreq struct {
|
|
|
|
Multiaddr [16]byte /* in6_addr */
|
|
|
|
Interface uint32
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func SetsockoptLinger(fd Handle, level, opt int, l *Linger) (errno int) { return EWINDOWS }
|
|
|
|
func SetsockoptIPMreq(fd Handle, level, opt int, mreq *IPMreq) (errno int) { return EWINDOWS }
|
|
|
|
func SetsockoptIPv6Mreq(fd Handle, level, opt int, mreq *IPv6Mreq) (errno int) { return EWINDOWS }
|
|
|
|
func BindToDevice(fd Handle, device string) (errno int) { return EWINDOWS }
|
2010-06-29 21:23:39 -06:00
|
|
|
|
2010-04-02 02:11:17 -06:00
|
|
|
// TODO(brainman): fix all needed for os
|
|
|
|
|
|
|
|
func Getpid() (pid int) { return -1 }
|
|
|
|
func Getppid() (ppid int) { return -1 }
|
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Fchdir(fd Handle) (errno int) { return EWINDOWS }
|
2010-04-30 00:45:14 -06:00
|
|
|
func Link(oldpath, newpath string) (errno int) { return EWINDOWS }
|
|
|
|
func Symlink(path, link string) (errno int) { return EWINDOWS }
|
|
|
|
func Readlink(path string, buf []byte) (n int, errno int) { return 0, EWINDOWS }
|
2011-02-15 22:24:59 -07:00
|
|
|
|
2011-07-01 08:18:07 -06:00
|
|
|
func Fchmod(fd Handle, mode uint32) (errno int) { return EWINDOWS }
|
2011-02-15 22:24:59 -07:00
|
|
|
func Chown(path string, uid int, gid int) (errno int) { return EWINDOWS }
|
|
|
|
func Lchown(path string, uid int, gid int) (errno int) { return EWINDOWS }
|
2011-07-01 08:18:07 -06:00
|
|
|
func Fchown(fd Handle, uid int, gid int) (errno int) { return EWINDOWS }
|
2010-04-02 02:11:17 -06:00
|
|
|
|
2010-04-27 00:17:14 -06:00
|
|
|
func Getuid() (uid int) { return -1 }
|
|
|
|
func Geteuid() (euid int) { return -1 }
|
|
|
|
func Getgid() (gid int) { return -1 }
|
|
|
|
func Getegid() (egid int) { return -1 }
|
2010-04-30 00:45:14 -06:00
|
|
|
func Getgroups() (gids []int, errno int) { return nil, EWINDOWS }
|