Commit c017a829 authored by Russ Cox's avatar Russ Cox

syscall: use error

- syscall (not os) now defines the Errno type.
- the low-level assembly functions Syscall, Syscall6, and so on
  return Errno, not uintptr
- syscall wrappers all return error, not uintptr.

R=golang-dev, mikioh.mikioh, r, alex.brainman
CC=golang-dev
https://golang.org/cl/5372080
parent b126902e
......@@ -28,10 +28,7 @@ var (
)
func OpenFile(name string, mode int, perm uint32) (file *File, err error) {
r, e := syscall.Open(name, mode, perm)
if e != 0 {
err = os.Errno(e)
}
r, err := syscall.Open(name, mode, perm)
return newFile(r, name), err
}
......@@ -54,22 +51,16 @@ func (file *File) Close() error {
if file == nil {
return os.EINVAL
}
e := syscall.Close(file.fd)
err := syscall.Close(file.fd)
file.fd = -1 // so it can't be closed again
if e != 0 {
return os.Errno(e)
}
return nil
return err
}
func (file *File) Read(b []byte) (ret int, err error) {
if file == nil {
return -1, os.EINVAL
}
r, e := syscall.Read(file.fd, b)
if e != 0 {
err = os.Errno(e)
}
r, err := syscall.Read(file.fd, b)
return int(r), err
}
......@@ -77,10 +68,7 @@ func (file *File) Write(b []byte) (ret int, err error) {
if file == nil {
return -1, os.EINVAL
}
r, e := syscall.Write(file.fd, b)
if e != 0 {
err = os.Errno(e)
}
r, err := syscall.Write(file.fd, b)
return int(r), err
}
......
......@@ -45,10 +45,10 @@ func (p *Package) writeDefs() {
fmt.Fprintf(fgo2, "// Created by cgo - DO NOT EDIT\n\n")
fmt.Fprintf(fgo2, "package %s\n\n", p.PackageName)
fmt.Fprintf(fgo2, "import \"unsafe\"\n\n")
fmt.Fprintf(fgo2, "import \"os\"\n\n")
fmt.Fprintf(fgo2, "import \"syscall\"\n\n")
fmt.Fprintf(fgo2, "import _ \"runtime/cgo\"\n\n")
fmt.Fprintf(fgo2, "type _ unsafe.Pointer\n\n")
fmt.Fprintf(fgo2, "func _Cerrno(dst *error, x int) { *dst = os.Errno(x) }\n")
fmt.Fprintf(fgo2, "func _Cerrno(dst *error, x int) { *dst = syscall.Errno(x) }\n")
for name, def := range typedef {
fmt.Fprintf(fgo2, "type %s ", name)
......
......@@ -28,16 +28,16 @@ func (r *rngReader) Read(b []byte) (n int, err error) {
if r.prov == 0 {
const provType = syscall.PROV_RSA_FULL
const flags = syscall.CRYPT_VERIFYCONTEXT | syscall.CRYPT_SILENT
errno := syscall.CryptAcquireContext(&r.prov, nil, nil, provType, flags)
if errno != 0 {
err := syscall.CryptAcquireContext(&r.prov, nil, nil, provType, flags)
if err != nil {
r.mu.Unlock()
return 0, os.NewSyscallError("CryptAcquireContext", errno)
return 0, os.NewSyscallError("CryptAcquireContext", err)
}
}
r.mu.Unlock()
errno := syscall.CryptGenRandom(r.prov, uint32(len(b)), &b[0])
if errno != 0 {
return 0, os.NewSyscallError("CryptGenRandom", errno)
err = syscall.CryptGenRandom(r.prov, uint32(len(b)), &b[0])
if err != nil {
return 0, os.NewSyscallError("CryptGenRandom", err)
}
return len(b), nil
}
......@@ -12,8 +12,8 @@ import (
)
func loadStore(roots *x509.CertPool, name string) {
store, errno := syscall.CertOpenSystemStore(syscall.InvalidHandle, syscall.StringToUTF16Ptr(name))
if errno != 0 {
store, err := syscall.CertOpenSystemStore(syscall.InvalidHandle, syscall.StringToUTF16Ptr(name))
if err != nil {
return
}
......
......@@ -105,9 +105,9 @@ func (w *Watcher) AddWatch(path string, flags uint32) error {
watchEntry.flags |= flags
flags |= syscall.IN_MASK_ADD
}
wd, errno := syscall.InotifyAddWatch(w.fd, path, flags)
if wd == -1 {
return &os.PathError{"inotify_add_watch", path, os.Errno(errno)}
wd, err := syscall.InotifyAddWatch(w.fd, path, flags)
if err != nil {
return &os.PathError{"inotify_add_watch", path, err}
}
if !found {
......@@ -139,14 +139,10 @@ func (w *Watcher) RemoveWatch(path string) error {
// readEvents reads from the inotify file descriptor, converts the
// received events into Event objects and sends them via the Event channel
func (w *Watcher) readEvents() {
var (
buf [syscall.SizeofInotifyEvent * 4096]byte // Buffer for a maximum of 4096 raw events
n int // Number of bytes read with read()
errno int // Syscall errno
)
var buf [syscall.SizeofInotifyEvent * 4096]byte
for {
n, errno = syscall.Read(w.fd, buf[0:])
n, err := syscall.Read(w.fd, buf[0:])
// See if there is a message on the "done" channel
var done bool
select {
......@@ -156,16 +152,16 @@ func (w *Watcher) readEvents() {
// If EOF or a "done" message is received
if n == 0 || done {
errno := syscall.Close(w.fd)
if errno == -1 {
w.Error <- os.NewSyscallError("close", errno)
err := syscall.Close(w.fd)
if err != nil {
w.Error <- os.NewSyscallError("close", err)
}
close(w.Event)
close(w.Error)
return
}
if n < 0 {
w.Error <- os.NewSyscallError("read", errno)
w.Error <- os.NewSyscallError("read", err)
continue
}
if n < syscall.SizeofInotifyEvent {
......
......@@ -278,8 +278,8 @@ func startServer() {
func newFD(fd, family, proto int, net string) (f *netFD, err error) {
onceStartServer.Do(startServer)
if e := syscall.SetNonblock(fd, true); e != 0 {
return nil, os.Errno(e)
if e := syscall.SetNonblock(fd, true); e != nil {
return nil, e
}
f = &netFD{
sysfd: fd,
......@@ -306,19 +306,19 @@ func (fd *netFD) setAddr(laddr, raddr Addr) {
}
func (fd *netFD) connect(ra syscall.Sockaddr) (err error) {
e := syscall.Connect(fd.sysfd, ra)
if e == syscall.EINPROGRESS {
var errno int
err = syscall.Connect(fd.sysfd, ra)
if err == syscall.EINPROGRESS {
pollserver.WaitWrite(fd)
e, errno = syscall.GetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_ERROR)
if errno != 0 {
return os.NewSyscallError("getsockopt", errno)
var e int
e, err = syscall.GetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_ERROR)
if err != nil {
return os.NewSyscallError("getsockopt", err)
}
if e != 0 {
err = syscall.Errno(e)
}
}
if e != 0 {
return os.Errno(e)
}
return nil
return err
}
// Add a reference to this fd.
......@@ -362,9 +362,9 @@ func (fd *netFD) shutdown(how int) error {
if fd == nil || fd.sysfile == nil {
return os.EINVAL
}
errno := syscall.Shutdown(fd.sysfd, how)
if errno != 0 {
return &OpError{"shutdown", fd.net, fd.laddr, os.Errno(errno)}
err := syscall.Shutdown(fd.sysfd, how)
if err != nil {
return &OpError{"shutdown", fd.net, fd.laddr, err}
}
return nil
}
......@@ -377,6 +377,14 @@ func (fd *netFD) CloseWrite() error {
return fd.shutdown(syscall.SHUT_WR)
}
type timeoutError struct{}
func (e *timeoutError) Error() string { return "i/o timeout" }
func (e *timeoutError) Timeout() bool { return true }
func (e *timeoutError) Temporary() bool { return true }
var errTimeout error = &timeoutError{}
func (fd *netFD) Read(p []byte) (n int, err error) {
if fd == nil {
return 0, os.EINVAL
......@@ -393,24 +401,24 @@ func (fd *netFD) Read(p []byte) (n int, err error) {
} else {
fd.rdeadline = 0
}
var oserr error
for {
var errno int
n, errno = syscall.Read(fd.sysfile.Fd(), p)
if errno == syscall.EAGAIN && fd.rdeadline >= 0 {
pollserver.WaitRead(fd)
continue
n, err = syscall.Read(fd.sysfile.Fd(), p)
if err == syscall.EAGAIN {
if fd.rdeadline >= 0 {
pollserver.WaitRead(fd)
continue
}
err = errTimeout
}
if errno != 0 {
if err != nil {
n = 0
oserr = os.Errno(errno)
} else if n == 0 && errno == 0 && fd.proto != syscall.SOCK_DGRAM {
} else if n == 0 && err == nil && fd.proto != syscall.SOCK_DGRAM {
err = io.EOF
}
break
}
if oserr != nil {
err = &OpError{"read", fd.net, fd.raddr, oserr}
if err != nil && err != io.EOF {
err = &OpError{"read", fd.net, fd.raddr, err}
}
return
}
......@@ -428,22 +436,22 @@ func (fd *netFD) ReadFrom(p []byte) (n int, sa syscall.Sockaddr, err error) {
} else {
fd.rdeadline = 0
}
var oserr error
for {
var errno int
n, sa, errno = syscall.Recvfrom(fd.sysfd, p, 0)
if errno == syscall.EAGAIN && fd.rdeadline >= 0 {
pollserver.WaitRead(fd)
continue
n, sa, err = syscall.Recvfrom(fd.sysfd, p, 0)
if err == syscall.EAGAIN {
if fd.rdeadline >= 0 {
pollserver.WaitRead(fd)
continue
}
err = errTimeout
}
if errno != 0 {
if err != nil {
n = 0
oserr = os.Errno(errno)
}
break
}
if oserr != nil {
err = &OpError{"read", fd.net, fd.laddr, oserr}
if err != nil {
err = &OpError{"read", fd.net, fd.laddr, err}
}
return
}
......@@ -461,24 +469,22 @@ func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S
} else {
fd.rdeadline = 0
}
var oserr error
for {
var errno int
n, oobn, flags, sa, errno = syscall.Recvmsg(fd.sysfd, p, oob, 0)
if errno == syscall.EAGAIN && fd.rdeadline >= 0 {
pollserver.WaitRead(fd)
continue
}
if errno != 0 {
oserr = os.Errno(errno)
n, oobn, flags, sa, err = syscall.Recvmsg(fd.sysfd, p, oob, 0)
if err == syscall.EAGAIN {
if fd.rdeadline >= 0 {
pollserver.WaitRead(fd)
continue
}
err = errTimeout
}
if n == 0 {
oserr = io.EOF
if err == nil && n == 0 {
err = io.EOF
}
break
}
if oserr != nil {
err = &OpError{"read", fd.net, fd.laddr, oserr}
if err != nil && err != io.EOF {
err = &OpError{"read", fd.net, fd.laddr, err}
return
}
return
......@@ -501,32 +507,34 @@ func (fd *netFD) Write(p []byte) (n int, err error) {
fd.wdeadline = 0
}
nn := 0
var oserr error
for {
n, errno := syscall.Write(fd.sysfile.Fd(), p[nn:])
var n int
n, err = syscall.Write(fd.sysfile.Fd(), p[nn:])
if n > 0 {
nn += n
}
if nn == len(p) {
break
}
if errno == syscall.EAGAIN && fd.wdeadline >= 0 {
pollserver.WaitWrite(fd)
continue
if err == syscall.EAGAIN {
if fd.wdeadline >= 0 {
pollserver.WaitWrite(fd)
continue
}
err = errTimeout
}
if errno != 0 {
if err != nil {
n = 0
oserr = os.Errno(errno)
break
}
if n == 0 {
oserr = io.ErrUnexpectedEOF
err = io.ErrUnexpectedEOF
break
}
}
if oserr != nil {
err = &OpError{"write", fd.net, fd.raddr, oserr}
if err != nil {
err = &OpError{"write", fd.net, fd.raddr, err}
}
return nn, err
}
......@@ -544,22 +552,21 @@ func (fd *netFD) WriteTo(p []byte, sa syscall.Sockaddr) (n int, err error) {
} else {
fd.wdeadline = 0
}
var oserr error
for {
errno := syscall.Sendto(fd.sysfd, p, 0, sa)
if errno == syscall.EAGAIN && fd.wdeadline >= 0 {
pollserver.WaitWrite(fd)
continue
}
if errno != 0 {
oserr = os.Errno(errno)
err = syscall.Sendto(fd.sysfd, p, 0, sa)
if err == syscall.EAGAIN {
if fd.wdeadline >= 0 {
pollserver.WaitWrite(fd)
continue
}
err = errTimeout
}
break
}
if oserr == nil {
if err == nil {
n = len(p)
} else {
err = &OpError{"write", fd.net, fd.raddr, oserr}
err = &OpError{"write", fd.net, fd.raddr, err}
}
return
}
......@@ -577,24 +584,22 @@ func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob
} else {
fd.wdeadline = 0
}
var oserr error
for {
var errno int
errno = syscall.Sendmsg(fd.sysfd, p, oob, sa, 0)
if errno == syscall.EAGAIN && fd.wdeadline >= 0 {
pollserver.WaitWrite(fd)
continue
}
if errno != 0 {
oserr = os.Errno(errno)
err = syscall.Sendmsg(fd.sysfd, p, oob, sa, 0)
if err == syscall.EAGAIN {
if fd.wdeadline >= 0 {
pollserver.WaitWrite(fd)
continue
}
err = errTimeout
}
break
}
if oserr == nil {
if err == nil {
n = len(p)
oobn = len(oob)
} else {
err = &OpError{"write", fd.net, fd.raddr, oserr}
err = &OpError{"write", fd.net, fd.raddr, err}
}
return
}
......@@ -615,25 +620,26 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err err
// See ../syscall/exec.go for description of ForkLock.
// It is okay to hold the lock across syscall.Accept
// because we have put fd.sysfd into non-blocking mode.
syscall.ForkLock.RLock()
var s, e int
var s int
var rsa syscall.Sockaddr
for {
if fd.closing {
syscall.ForkLock.RUnlock()
return nil, os.EINVAL
}
s, rsa, e = syscall.Accept(fd.sysfd)
if e != syscall.EAGAIN || fd.rdeadline < 0 {
break
}
syscall.ForkLock.RUnlock()
pollserver.WaitRead(fd)
syscall.ForkLock.RLock()
}
if e != 0 {
syscall.ForkLock.RUnlock()
return nil, &OpError{"accept", fd.net, fd.laddr, os.Errno(e)}
s, rsa, err = syscall.Accept(fd.sysfd)
if err != nil {
syscall.ForkLock.RUnlock()
if err == syscall.EAGAIN {
if fd.rdeadline >= 0 {
pollserver.WaitRead(fd)
continue
}
err = errTimeout
}
return nil, &OpError{"accept", fd.net, fd.laddr, err}
}
break
}
syscall.CloseOnExec(s)
syscall.ForkLock.RUnlock()
......@@ -648,19 +654,19 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err err
}
func (fd *netFD) dup() (f *os.File, err error) {
ns, e := syscall.Dup(fd.sysfd)
if e != 0 {
return nil, &OpError{"dup", fd.net, fd.laddr, os.Errno(e)}
ns, err := syscall.Dup(fd.sysfd)
if err != nil {
return nil, &OpError{"dup", fd.net, fd.laddr, err}
}
// We want blocking mode for the new fd, hence the double negative.
if e = syscall.SetNonblock(ns, false); e != 0 {
return nil, &OpError{"setnonblock", fd.net, fd.laddr, os.Errno(e)}
if err = syscall.SetNonblock(ns, false); err != nil {
return nil, &OpError{"setnonblock", fd.net, fd.laddr, err}
}
return os.NewFile(ns, fd.sysfile.Name()), nil
}
func closesocket(s int) (errno int) {
func closesocket(s int) error {
return syscall.Close(s)
}
......@@ -24,9 +24,8 @@ type pollster struct {
func newpollster() (p *pollster, err error) {
p = new(pollster)
var e int
if p.kq, e = syscall.Kqueue(); e != 0 {
return nil, os.NewSyscallError("kqueue", e)
if p.kq, err = syscall.Kqueue(); err != nil {
return nil, os.NewSyscallError("kqueue", err)
}
p.events = p.eventbuf[0:0]
return p, nil
......@@ -52,15 +51,15 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
}
syscall.SetKevent(ev, fd, kmode, flags)
n, e := syscall.Kevent(p.kq, p.kbuf[0:], p.kbuf[0:], nil)
if e != 0 {
return false, os.NewSyscallError("kevent", e)
n, err := syscall.Kevent(p.kq, p.kbuf[0:], p.kbuf[0:], nil)
if err != nil {
return false, os.NewSyscallError("kevent", err)
}
if n != 1 || (ev.Flags&syscall.EV_ERROR) == 0 || int(ev.Ident) != fd || int(ev.Filter) != kmode {
return false, errors.New("kqueue phase error")
}
if ev.Data != 0 {
return false, os.Errno(int(ev.Data))
return false, syscall.Errno(ev.Data)
}
return false, nil
}
......@@ -96,11 +95,11 @@ func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err erro
nn, e := syscall.Kevent(p.kq, nil, p.eventbuf[0:], t)
s.Lock()
if e != 0 {
if e != nil {
if e == syscall.EINTR {
continue
}
return -1, 0, os.NewSyscallError("kevent", e)
return -1, 0, os.NewSyscallError("kevent", nil)
}
if nn == 0 {
return -1, 0, nil
......
......@@ -23,9 +23,8 @@ type pollster struct {
func newpollster() (p *pollster, err error) {
p = new(pollster)
var e int
if p.kq, e = syscall.Kqueue(); e != 0 {
return nil, os.NewSyscallError("kqueue", e)
if p.kq, err = syscall.Kqueue(); err != nil {
return nil, os.NewSyscallError("kqueue", err)
}
p.events = p.eventbuf[0:0]
return p, nil
......@@ -50,14 +49,14 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
syscall.SetKevent(ev, fd, kmode, flags)
n, e := syscall.Kevent(p.kq, p.kbuf[:], nil, nil)
if e != 0 {
if e != nil {
return false, os.NewSyscallError("kevent", e)
}
if n != 1 || (ev.Flags&syscall.EV_ERROR) == 0 || int(ev.Ident) != fd || int(ev.Filter) != kmode {
return false, os.NewSyscallError("kqueue phase error", e)
}
if ev.Data != 0 {
return false, os.Errno(int(ev.Data))
return false, syscall.Errno(int(ev.Data))
}
return false, nil
}
......@@ -91,7 +90,7 @@ func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err erro
nn, e := syscall.Kevent(p.kq, nil, p.eventbuf[:], t)
s.Lock()
if e != 0 {
if e != nil {
if e == syscall.EINTR {
continue
}
......
......@@ -35,12 +35,12 @@ type pollster struct {
func newpollster() (p *pollster, err error) {
p = new(pollster)
var e int
var e error
// The arg to epoll_create is a hint to the kernel
// about the number of FDs we will care about.
// We don't know, and since 2.6.8 the kernel ignores it anyhow.
if p.epfd, e = syscall.EpollCreate(16); e != 0 {
if p.epfd, e = syscall.EpollCreate(16); e != nil {
return nil, os.NewSyscallError("epoll_create", e)
}
p.events = make(map[int]uint32)
......@@ -68,7 +68,7 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
} else {
op = syscall.EPOLL_CTL_ADD
}
if e := syscall.EpollCtl(p.epfd, op, fd, &p.ctlEvent); e != 0 {
if e := syscall.EpollCtl(p.epfd, op, fd, &p.ctlEvent); e != nil {
return false, os.NewSyscallError("epoll_ctl", e)
}
p.events[fd] = p.ctlEvent.Events
......@@ -97,13 +97,13 @@ func (p *pollster) StopWaiting(fd int, bits uint) {
if int32(events)&^syscall.EPOLLONESHOT != 0 {
p.ctlEvent.Fd = int32(fd)
p.ctlEvent.Events = events
if e := syscall.EpollCtl(p.epfd, syscall.EPOLL_CTL_MOD, fd, &p.ctlEvent); e != 0 {
print("Epoll modify fd=", fd, ": ", os.Errno(e).Error(), "\n")
if e := syscall.EpollCtl(p.epfd, syscall.EPOLL_CTL_MOD, fd, &p.ctlEvent); e != nil {
print("Epoll modify fd=", fd, ": ", e.Error(), "\n")
}
p.events[fd] = events
} else {
if e := syscall.EpollCtl(p.epfd, syscall.EPOLL_CTL_DEL, fd, nil); e != 0 {
print("Epoll delete fd=", fd, ": ", os.Errno(e).Error(), "\n")
if e := syscall.EpollCtl(p.epfd, syscall.EPOLL_CTL_DEL, fd, nil); e != nil {
print("Epoll delete fd=", fd, ": ", e.Error(), "\n")
}
delete(p.events, fd)
}
......@@ -141,7 +141,7 @@ func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err erro
n, e := syscall.EpollWait(p.epfd, p.waitEventBuf[0:], msec)
s.Lock()
if e != 0 {
if e != nil {
if e == syscall.EAGAIN || e == syscall.EINTR {
continue
}
......
......@@ -23,9 +23,8 @@ type pollster struct {
func newpollster() (p *pollster, err error) {
p = new(pollster)
var e int
if p.kq, e = syscall.Kqueue(); e != 0 {
return nil, os.NewSyscallError("kqueue", e)
if p.kq, err = syscall.Kqueue(); err != nil {
return nil, os.NewSyscallError("kqueue", err)
}
p.events = p.eventbuf[0:0]
return p, nil
......@@ -50,14 +49,14 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
syscall.SetKevent(ev, fd, kmode, flags)
n, e := syscall.Kevent(p.kq, p.kbuf[:], nil, nil)
if e != 0 {
if e != nil {
return false, os.NewSyscallError("kevent", e)
}
if n != 1 || (ev.Flags&syscall.EV_ERROR) == 0 || int(ev.Ident) != fd || int(ev.Filter) != kmode {
return false, os.NewSyscallError("kqueue phase error", e)
}
if ev.Data != 0 {
return false, os.Errno(int(ev.Data))
return false, syscall.Errno(int(ev.Data))
}
return false, nil
}
......@@ -91,7 +90,7 @@ func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err erro
nn, e := syscall.Kevent(p.kq, nil, p.eventbuf[:], t)
s.Lock()
if e != 0 {
if e != nil {
if e == syscall.EINTR {
continue
}
......
......@@ -26,11 +26,11 @@ func init() {
var d syscall.WSAData
e := syscall.WSAStartup(uint32(0x202), &d)
if e != 0 {
initErr = os.NewSyscallError("WSAStartup", e)
initErr = os.NewSyscallError("WSAStartup", syscall.Errno(e))
}
}
func closesocket(s syscall.Handle) (errno int) {
func closesocket(s syscall.Handle) (err error) {
return syscall.Closesocket(s)
}
......@@ -38,13 +38,13 @@ func closesocket(s syscall.Handle) (errno int) {
type anOpIface interface {
Op() *anOp
Name() string
Submit() (errno int)
Submit() (err error)
}
// IO completion result parameters.
type ioResult struct {
qty uint32
err int
err error
}
// anOp implements functionality common to all io operations.
......@@ -54,7 +54,7 @@ type anOp struct {
o syscall.Overlapped
resultc chan ioResult
errnoc chan int
errnoc chan error
fd *netFD
}
......@@ -71,7 +71,7 @@ func (o *anOp) Init(fd *netFD, mode int) {
}
o.resultc = fd.resultc[i]
if fd.errnoc[i] == nil {
fd.errnoc[i] = make(chan int)
fd.errnoc[i] = make(chan error)
}
o.errnoc = fd.errnoc[i]
}
......@@ -111,14 +111,14 @@ func (s *resultSrv) Run() {
for {
r.err = syscall.GetQueuedCompletionStatus(s.iocp, &(r.qty), &key, &o, syscall.INFINITE)
switch {
case r.err == 0:
case r.err == nil:
// Dequeued successfully completed io packet.
case r.err == syscall.WAIT_TIMEOUT && o == nil:
case r.err == syscall.Errno(syscall.WAIT_TIMEOUT) && o == nil:
// Wait has timed out (should not happen now, but might be used in the future).
panic("GetQueuedCompletionStatus timed out")
case o == nil:
// Failed to dequeue anything -> report the error.
panic("GetQueuedCompletionStatus failed " + syscall.Errstr(r.err))
panic("GetQueuedCompletionStatus failed " + r.err.Error())
default:
// Dequeued failed io packet.
}
......@@ -153,7 +153,7 @@ func (s *ioSrv) ProcessRemoteIO() {
// inline, or, if timeouts are employed, passes the request onto
// a special goroutine and waits for completion or cancels request.
func (s *ioSrv) ExecIO(oi anOpIface, deadline_delta int64) (n int, err error) {
var e int
var e error
o := oi.Op()
if deadline_delta > 0 {
// Send request to a special dedicated thread,
......@@ -164,12 +164,12 @@ func (s *ioSrv) ExecIO(oi anOpIface, deadline_delta int64) (n int, err error) {
e = oi.Submit()
}
switch e {
case 0:
case nil:
// IO completed immediately, but we need to get our completion message anyway.
case syscall.ERROR_IO_PENDING:
// IO started, and we have to wait for its completion.
default:
return 0, &OpError{oi.Name(), o.fd.net, o.fd.laddr, os.Errno(e)}
return 0, &OpError{oi.Name(), o.fd.net, o.fd.laddr, e}
}
// Wait for our request to complete.
var r ioResult
......@@ -187,8 +187,8 @@ func (s *ioSrv) ExecIO(oi anOpIface, deadline_delta int64) (n int, err error) {
} else {
r = <-o.resultc
}
if r.err != 0 {
err = &OpError{oi.Name(), o.fd.net, o.fd.laddr, os.Errno(r.err)}
if r.err != nil {
err = &OpError{oi.Name(), o.fd.net, o.fd.laddr, r.err}
}
return int(r.qty), err
}
......@@ -200,10 +200,10 @@ var onceStartServer sync.Once
func startServer() {
resultsrv = new(resultSrv)
var errno int
resultsrv.iocp, errno = syscall.CreateIoCompletionPort(syscall.InvalidHandle, 0, 0, 1)
if errno != 0 {
panic("CreateIoCompletionPort failed " + syscall.Errstr(errno))
var err error
resultsrv.iocp, err = syscall.CreateIoCompletionPort(syscall.InvalidHandle, 0, 0, 1)
if err != nil {
panic("CreateIoCompletionPort: " + err.Error())
}
go resultsrv.Run()
......@@ -228,7 +228,7 @@ type netFD struct {
laddr Addr
raddr Addr
resultc [2]chan ioResult // read/write completion results
errnoc [2]chan int // read/write submit or cancel operation errors
errnoc [2]chan error // read/write submit or cancel operation errors
// owned by client
rdeadline_delta int64
......@@ -256,8 +256,8 @@ func newFD(fd syscall.Handle, family, proto int, net string) (f *netFD, err erro
}
onceStartServer.Do(startServer)
// Associate our socket with resultsrv.iocp.
if _, e := syscall.CreateIoCompletionPort(syscall.Handle(fd), resultsrv.iocp, 0, 0); e != 0 {
return nil, os.Errno(e)
if _, e := syscall.CreateIoCompletionPort(syscall.Handle(fd), resultsrv.iocp, 0, 0); e != nil {
return nil, e
}
return allocFD(fd, family, proto, net), nil
}
......@@ -268,11 +268,7 @@ func (fd *netFD) setAddr(laddr, raddr Addr) {
}
func (fd *netFD) connect(ra syscall.Sockaddr) (err error) {
e := syscall.Connect(fd.sysfd, ra)
if e != 0 {
return os.Errno(e)
}
return nil
return syscall.Connect(fd.sysfd, ra)
}
// Add a reference to this fd.
......@@ -317,9 +313,9 @@ func (fd *netFD) shutdown(how int) error {
if fd == nil || fd.sysfd == syscall.InvalidHandle {
return os.EINVAL
}
errno := syscall.Shutdown(fd.sysfd, how)
if errno != 0 {
return &OpError{"shutdown", fd.net, fd.laddr, os.Errno(errno)}
err := syscall.Shutdown(fd.sysfd, how)
if err != nil {
return &OpError{"shutdown", fd.net, fd.laddr, err}
}
return nil
}
......@@ -338,7 +334,7 @@ type readOp struct {
bufOp
}
func (o *readOp) Submit() (errno int) {
func (o *readOp) Submit() (err error) {
var d, f uint32
return syscall.WSARecv(syscall.Handle(o.fd.sysfd), &o.buf, 1, &d, &f, &o.o, nil)
}
......@@ -375,7 +371,7 @@ type readFromOp struct {
rsan int32
}
func (o *readFromOp) Submit() (errno int) {
func (o *readFromOp) Submit() (err error) {
var d, f uint32
return syscall.WSARecvFrom(o.fd.sysfd, &o.buf, 1, &d, &f, &o.rsa, &o.rsan, &o.o, nil)
}
......@@ -415,7 +411,7 @@ type writeOp struct {
bufOp
}
func (o *writeOp) Submit() (errno int) {
func (o *writeOp) Submit() (err error) {
var d uint32
return syscall.WSASend(o.fd.sysfd, &o.buf, 1, &d, 0, &o.o, nil)
}
......@@ -447,7 +443,7 @@ type writeToOp struct {
sa syscall.Sockaddr
}
func (o *writeToOp) Submit() (errno int) {
func (o *writeToOp) Submit() (err error) {
var d uint32
return syscall.WSASendto(o.fd.sysfd, &o.buf, 1, &d, 0, o.sa, &o.o, nil)
}
......@@ -484,7 +480,7 @@ type acceptOp struct {
attrs [2]syscall.RawSockaddrAny // space for local and remote address only
}
func (o *acceptOp) Submit() (errno int) {
func (o *acceptOp) Submit() (err error) {
var d uint32
l := uint32(unsafe.Sizeof(o.attrs[0]))
return syscall.AcceptEx(o.fd.sysfd, o.newsock,
......@@ -506,17 +502,17 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err err
// See ../syscall/exec.go for description of ForkLock.
syscall.ForkLock.RLock()
s, e := syscall.Socket(fd.family, fd.proto, 0)
if e != 0 {
if e != nil {
syscall.ForkLock.RUnlock()
return nil, os.Errno(e)
return nil, e
}
syscall.CloseOnExec(s)
syscall.ForkLock.RUnlock()
// Associate our new socket with IOCP.
onceStartServer.Do(startServer)
if _, e = syscall.CreateIoCompletionPort(s, resultsrv.iocp, 0, 0); e != 0 {
return nil, &OpError{"CreateIoCompletionPort", fd.net, fd.laddr, os.Errno(e)}
if _, e = syscall.CreateIoCompletionPort(s, resultsrv.iocp, 0, 0); e != nil {
return nil, &OpError{"CreateIoCompletionPort", fd.net, fd.laddr, e}
}
// Submit accept request.
......@@ -531,9 +527,9 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err err
// Inherit properties of the listening socket.
e = syscall.Setsockopt(s, syscall.SOL_SOCKET, syscall.SO_UPDATE_ACCEPT_CONTEXT, (*byte)(unsafe.Pointer(&fd.sysfd)), int32(unsafe.Sizeof(fd.sysfd)))
if e != 0 {
if e != nil {
closesocket(s)
return nil, err
return nil, e
}
// Get local and peer addr out of AcceptEx buffer.
......
......@@ -13,12 +13,12 @@ import (
func newFileFD(f *os.File) (nfd *netFD, err error) {
fd, errno := syscall.Dup(f.Fd())
if errno != 0 {
if errno != nil {
return nil, os.NewSyscallError("dup", errno)
}
proto, errno := syscall.GetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_TYPE)
if errno != 0 {
if errno != nil {
return nil, os.NewSyscallError("getsockopt", errno)
}
......
......@@ -1145,7 +1145,7 @@ func TestAcceptMaxFds(t *testing.T) {
ln := &errorListener{[]error{
&net.OpError{
Op: "accept",
Err: os.Errno(syscall.EMFILE),
Err: syscall.EMFILE,
}}}
err := Serve(ln, HandlerFunc(HandlerFunc(func(ResponseWriter, *Request) {})))
if err != io.EOF {
......
......@@ -6,14 +6,14 @@ package http
import (
"net"
"os"
"syscall"
)
func init() {
remoteSideClosedFunc = func(err error) (out bool) {
op, ok := err.(*net.OpError)
if ok && op.Op == "WSARecv" && op.Net == "tcp" && op.Err == os.Errno(10058) {
// TODO(bradfitz): find the symbol for 10058
if ok && op.Op == "WSARecv" && op.Net == "tcp" && op.Err == syscall.Errno(10058) {
// TODO(brainman,rsc): Fix whatever is generating this.
return true
}
return false
......
......@@ -20,18 +20,18 @@ import (
func interfaceTable(ifindex int) ([]Interface, error) {
var (
tab []byte
e int
e error
msgs []syscall.RoutingMessage
ift []Interface
)
tab, e = syscall.RouteRIB(syscall.NET_RT_IFLIST, ifindex)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route rib", e)
}
msgs, e = syscall.ParseRoutingMessage(tab)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route message", e)
}
......@@ -55,7 +55,7 @@ func newLink(m *syscall.InterfaceMessage) ([]Interface, error) {
var ift []Interface
sas, e := syscall.ParseRoutingSockaddr(m)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route sockaddr", e)
}
......@@ -110,18 +110,18 @@ func linkFlags(rawFlags int32) Flags {
func interfaceAddrTable(ifindex int) ([]Addr, error) {
var (
tab []byte
e int
e error
msgs []syscall.RoutingMessage
ifat []Addr
)
tab, e = syscall.RouteRIB(syscall.NET_RT_IFLIST, ifindex)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route rib", e)
}
msgs, e = syscall.ParseRoutingMessage(tab)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route message", e)
}
......@@ -145,7 +145,7 @@ func newAddr(m *syscall.InterfaceAddrMessage) ([]Addr, error) {
var ifat []Addr
sas, e := syscall.ParseRoutingSockaddr(m)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route sockaddr", e)
}
......
......@@ -17,18 +17,18 @@ import (
func interfaceMulticastAddrTable(ifindex int) ([]Addr, error) {
var (
tab []byte
e int
e error
msgs []syscall.RoutingMessage
ifmat []Addr
)
tab, e = syscall.RouteRIB(syscall.NET_RT_IFLIST2, ifindex)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route rib", e)
}
msgs, e = syscall.ParseRoutingMessage(tab)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route message", e)
}
......@@ -52,7 +52,7 @@ func newMulticastAddr(m *syscall.InterfaceMulticastAddrMessage) ([]Addr, error)
var ifmat []Addr
sas, e := syscall.ParseRoutingSockaddr(m)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route sockaddr", e)
}
......
......@@ -17,18 +17,18 @@ import (
func interfaceMulticastAddrTable(ifindex int) ([]Addr, error) {
var (
tab []byte
e int
e error
msgs []syscall.RoutingMessage
ifmat []Addr
)
tab, e = syscall.RouteRIB(syscall.NET_RT_IFMALIST, ifindex)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route rib", e)
}
msgs, e = syscall.ParseRoutingMessage(tab)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route message", e)
}
......@@ -52,7 +52,7 @@ func newMulticastAddr(m *syscall.InterfaceMulticastAddrMessage) ([]Addr, error)
var ifmat []Addr
sas, e := syscall.ParseRoutingSockaddr(m)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("route sockaddr", e)
}
......
......@@ -21,16 +21,16 @@ func interfaceTable(ifindex int) ([]Interface, error) {
ift []Interface
tab []byte
msgs []syscall.NetlinkMessage
e int
e error
)
tab, e = syscall.NetlinkRIB(syscall.RTM_GETLINK, syscall.AF_UNSPEC)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("netlink rib", e)
}
msgs, e = syscall.ParseNetlinkMessage(tab)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("netlink message", e)
}
......@@ -42,7 +42,7 @@ func interfaceTable(ifindex int) ([]Interface, error) {
ifim := (*syscall.IfInfomsg)(unsafe.Pointer(&m.Data[0]))
if ifindex == 0 || ifindex == int(ifim.Index) {
attrs, e := syscall.ParseNetlinkRouteAttr(&m)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("netlink routeattr", e)
}
ifi := newLink(attrs, ifim)
......@@ -102,27 +102,19 @@ func linkFlags(rawFlags uint32) Flags {
// for all network interfaces. Otherwise it returns addresses
// for a specific interface.
func interfaceAddrTable(ifindex int) ([]Addr, error) {
var (
tab []byte
e int
err error
ifat []Addr
msgs []syscall.NetlinkMessage
)
tab, e = syscall.NetlinkRIB(syscall.RTM_GETADDR, syscall.AF_UNSPEC)
if e != 0 {
tab, e := syscall.NetlinkRIB(syscall.RTM_GETADDR, syscall.AF_UNSPEC)
if e != nil {
return nil, os.NewSyscallError("netlink rib", e)
}
msgs, e = syscall.ParseNetlinkMessage(tab)
if e != 0 {
msgs, e := syscall.ParseNetlinkMessage(tab)
if e != nil {
return nil, os.NewSyscallError("netlink message", e)
}
ifat, err = addrTable(msgs, ifindex)
if err != nil {
return nil, err
ifat, e := addrTable(msgs, ifindex)
if e != nil {
return nil, e
}
return ifat, nil
......@@ -139,7 +131,7 @@ func addrTable(msgs []syscall.NetlinkMessage, ifindex int) ([]Addr, error) {
ifam := (*syscall.IfAddrmsg)(unsafe.Pointer(&m.Data[0]))
if ifindex == 0 || ifindex == int(ifam.Index) {
attrs, e := syscall.ParseNetlinkRouteAttr(&m)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("netlink routeattr", e)
}
ifat = append(ifat, newAddr(attrs, int(ifam.Family))...)
......
......@@ -39,7 +39,7 @@ func getAdapterList() (*syscall.IpAdapterInfo, error) {
func getInterfaceList() ([]syscall.InterfaceInfo, error) {
s, e := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("Socket", e)
}
defer syscall.Closesocket(s)
......@@ -48,7 +48,7 @@ func getInterfaceList() ([]syscall.InterfaceInfo, error) {
ret := uint32(0)
size := uint32(unsafe.Sizeof(ii))
e = syscall.WSAIoctl(s, syscall.SIO_GET_INTERFACE_LIST, nil, 0, (*byte)(unsafe.Pointer(&ii[0])), size, &ret, nil, 0)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("WSAIoctl", e)
}
c := ret / uint32(unsafe.Sizeof(ii[0]))
......
......@@ -33,8 +33,8 @@ func probeIPv6Stack() (supportsIPv6, supportsIPv4map bool) {
}
for i := range probes {
s, errno := syscall.Socket(syscall.AF_INET6, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
if errno != 0 {
s, err := syscall.Socket(syscall.AF_INET6, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
if err != nil {
continue
}
defer closesocket(s)
......@@ -42,8 +42,8 @@ func probeIPv6Stack() (supportsIPv6, supportsIPv4map bool) {
if err != nil {
continue
}
errno = syscall.Bind(s, sa)
if errno != 0 {
err = syscall.Bind(s, sa)
if err != nil {
continue
}
probes[i].ok = true
......
......@@ -22,7 +22,7 @@ func lookupProtocol(name string) (proto int, err error) {
protoentLock.Lock()
defer protoentLock.Unlock()
p, e := syscall.GetProtoByName(name)
if e != 0 {
if e != nil {
return 0, os.NewSyscallError("GetProtoByName", e)
}
return int(p.Proto), nil
......@@ -44,7 +44,7 @@ func LookupIP(name string) (addrs []IP, err error) {
hostentLock.Lock()
defer hostentLock.Unlock()
h, e := syscall.GetHostByName(name)
if e != 0 {
if e != nil {
return nil, os.NewSyscallError("GetHostByName", e)
}
switch h.AddrType {
......@@ -71,7 +71,7 @@ func LookupPort(network, service string) (port int, err error) {
serventLock.Lock()
defer serventLock.Unlock()
s, e := syscall.GetServByName(service, network)
if e != 0 {
if e != nil {
return 0, os.NewSyscallError("GetServByName", e)
}
return int(syscall.Ntohs(s.Port)), nil
......@@ -81,7 +81,7 @@ func LookupCNAME(name string) (cname string, err error) {
var r *syscall.DNSRecord
e := syscall.DnsQuery(name, syscall.DNS_TYPE_CNAME, 0, nil, &r, nil)
if e != 0 {
return "", os.NewSyscallError("LookupCNAME", int(e))
return "", os.NewSyscallError("LookupCNAME", e)
}
defer syscall.DnsRecordListFree(r, 1)
if r != nil && r.Type == syscall.DNS_TYPE_CNAME {
......@@ -110,7 +110,7 @@ func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err err
var r *syscall.DNSRecord
e := syscall.DnsQuery(target, syscall.DNS_TYPE_SRV, 0, nil, &r, nil)
if e != 0 {
return "", nil, os.NewSyscallError("LookupSRV", int(e))
return "", nil, os.NewSyscallError("LookupSRV", e)
}
defer syscall.DnsRecordListFree(r, 1)
addrs = make([]*SRV, 0, 10)
......@@ -126,7 +126,7 @@ func LookupMX(name string) (mx []*MX, err error) {
var r *syscall.DNSRecord
e := syscall.DnsQuery(name, syscall.DNS_TYPE_MX, 0, nil, &r, nil)
if e != 0 {
return nil, os.NewSyscallError("LookupMX", int(e))
return nil, os.NewSyscallError("LookupMX", e)
}
defer syscall.DnsRecordListFree(r, 1)
mx = make([]*MX, 0, 10)
......@@ -142,7 +142,7 @@ func LookupTXT(name string) (txt []string, err error) {
var r *syscall.DNSRecord
e := syscall.DnsQuery(name, syscall.DNS_TYPE_TEXT, 0, nil, &r, nil)
if e != 0 {
return nil, os.NewSyscallError("LookupTXT", int(e))
return nil, os.NewSyscallError("LookupTXT", e)
}
defer syscall.DnsRecordListFree(r, 1)
txt = make([]string, 0, 10)
......@@ -164,7 +164,7 @@ func LookupAddr(addr string) (name []string, err error) {
var r *syscall.DNSRecord
e := syscall.DnsQuery(arpa, syscall.DNS_TYPE_PTR, 0, nil, &r, nil)
if e != 0 {
return nil, os.NewSyscallError("LookupAddr", int(e))
return nil, os.NewSyscallError("LookupAddr", e)
}
defer syscall.DnsRecordListFree(r, 1)
name = make([]string, 0, 10)
......
......@@ -18,11 +18,10 @@ func newPollServer() (s *pollServer, err error) {
if s.pr, s.pw, err = os.Pipe(); err != nil {
return nil, err
}
var e int
if e = syscall.SetNonblock(s.pr.Fd(), true); e != 0 {
if err = syscall.SetNonblock(s.pr.Fd(), true); err != nil {
goto Errno
}
if e = syscall.SetNonblock(s.pw.Fd(), true); e != 0 {
if err = syscall.SetNonblock(s.pw.Fd(), true); err != nil {
goto Errno
}
if s.poll, err = newpollster(); err != nil {
......@@ -37,7 +36,7 @@ func newPollServer() (s *pollServer, err error) {
return s, nil
Errno:
err = &os.PathError{"setnonblock", s.pr.Name(), os.Errno(e)}
err = &os.PathError{"setnonblock", s.pr.Name(), err}
Error:
s.pr.Close()
s.pw.Close()
......
......@@ -62,18 +62,18 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
written += int64(n)
remain -= int64(n)
}
if n == 0 && errno == 0 {
if n == 0 && errno == nil {
break
}
if errno == syscall.EAGAIN && c.wdeadline >= 0 {
pollserver.WaitWrite(c)
continue
}
if errno != 0 {
if errno != nil {
// This includes syscall.ENOSYS (no kernel
// support) and syscall.EINVAL (fd types which
// don't implement sendfile together)
err = &OpError{"sendfile", c.net, c.raddr, os.Errno(errno)}
err = &OpError{"sendfile", c.net, c.raddr, errno}
break
}
}
......
......@@ -16,7 +16,7 @@ type sendfileOp struct {
n uint32
}
func (o *sendfileOp) Submit() (errno int) {
func (o *sendfileOp) Submit() (err error) {
return syscall.TransmitFile(o.fd.sysfd, o.src, o.n, 0, &o.o, nil, syscall.TF_WRITE_BEHIND)
}
......
......@@ -28,9 +28,9 @@ func socket(net string, f, p, t int, la, ra syscall.Sockaddr, toAddr func(syscal
// See ../syscall/exec.go for description of ForkLock.
syscall.ForkLock.RLock()
s, e := syscall.Socket(f, p, t)
if e != 0 {
if err != nil {
syscall.ForkLock.RUnlock()
return nil, os.Errno(e)
return nil, err
}
syscall.CloseOnExec(s)
syscall.ForkLock.RUnlock()
......@@ -39,9 +39,9 @@ func socket(net string, f, p, t int, la, ra syscall.Sockaddr, toAddr func(syscal
if la != nil {
e = syscall.Bind(s, la)
if e != 0 {
if e != nil {
closesocket(s)
return nil, os.Errno(e)
return nil, e
}
}
......
......@@ -250,9 +250,9 @@ func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err error) {
return nil, err
}
errno := syscall.Listen(fd.sysfd, listenBacklog())
if errno != 0 {
if errno != nil {
closesocket(fd.sysfd)
return nil, &OpError{"listen", "tcp", laddr, os.Errno(errno)}
return nil, &OpError{"listen", "tcp", laddr, errno}
}
l = new(TCPListener)
l.fd = fd
......
......@@ -327,9 +327,9 @@ func ListenUnix(net string, laddr *UnixAddr) (l *UnixListener, err error) {
return nil, err
}
e1 := syscall.Listen(fd.sysfd, 8) // listenBacklog());
if e1 != 0 {
if e1 != nil {
closesocket(fd.sysfd)
return nil, &OpError{Op: "listen", Net: "unix", Addr: laddr, Err: os.Errno(e1)}
return nil, &OpError{Op: "listen", Net: "unix", Addr: laddr, Err: e1}
}
return &UnixListener{fd, laddr.Name}, nil
}
......
......@@ -47,9 +47,9 @@ func (f *File) Readdirnames(n int) (names []string, err error) {
// Refill the buffer if necessary
if d.bufp >= d.nbuf {
d.bufp = 0
var errno int
var errno error
d.nbuf, errno = syscall.ReadDirent(f.fd, d.buf)
if errno != 0 {
if errno != nil {
return names, NewSyscallError("readdirent", errno)
}
if d.nbuf <= 0 {
......
......@@ -21,7 +21,7 @@ func Getenverror(key string) (value string, err error) {
return "", EINVAL
}
f, e := Open("/env/" + key)
if iserror(e) {
if e != nil {
return "", ENOENV
}
defer f.Close()
......@@ -30,7 +30,7 @@ func Getenverror(key string) (value string, err error) {
f.Seek(0, 0)
buf := make([]byte, l)
n, e := f.Read(buf)
if iserror(e) {
if e != nil {
return "", ENOENV
}
......@@ -55,7 +55,7 @@ func Setenv(key, value string) error {
}
f, e := Create("/env/" + key)
if iserror(e) {
if e != nil {
return e
}
defer f.Close()
......@@ -75,18 +75,18 @@ func Environ() []string {
env := make([]string, 0, 100)
f, e := Open("/env")
if iserror(e) {
if e != nil {
panic(e)
}
defer f.Close()
names, e := f.Readdirnames(-1)
if iserror(e) {
if e != nil {
panic(e)
}
for _, k := range names {
if v, e := Getenverror(k); !iserror(e) {
if v, e := Getenverror(k); e == nil {
env = append(env, k+"="+v)
}
}
......
......@@ -52,7 +52,7 @@ func Setenv(key, value string) error {
v = syscall.StringToUTF16Ptr(value)
}
e := syscall.SetEnvironmentVariable(syscall.StringToUTF16Ptr(key), v)
if e != 0 {
if e != nil {
return NewSyscallError("SetEnvironmentVariable", e)
}
return nil
......@@ -77,7 +77,7 @@ func Clearenv() {
// in the form "key=value".
func Environ() []string {
s, e := syscall.GetEnvironmentStrings()
if e != 0 {
if e != nil {
return nil
}
defer syscall.FreeEnvironmentStrings(s)
......@@ -117,7 +117,7 @@ func init() {
var argc int32
cmd := syscall.GetCommandLine()
argv, e := syscall.CommandLineToArgv(cmd, &argc)
if e != 0 {
if e != nil {
return
}
defer syscall.LocalFree(syscall.Handle(uintptr(unsafe.Pointer(argv))))
......
......@@ -57,9 +57,3 @@ var (
EPIPE = errors.New("Broken Pipe")
EPLAN9 = errors.New("not supported by plan 9")
)
func iserror(err syscall.Error) bool {
return err != nil
}
func Errno(e syscall.Error) syscall.Error { return e }
......@@ -8,67 +8,53 @@ package os
import syscall "syscall"
// Errno is the Unix error number. Names such as EINVAL are simple
// wrappers to convert the error number into an error.
type Errno int64
func (e Errno) Error() string { return syscall.Errstr(int(e)) }
func (e Errno) Temporary() bool {
return e == Errno(syscall.EINTR) || e == Errno(syscall.EMFILE) || e.Timeout()
}
func (e Errno) Timeout() bool {
return e == Errno(syscall.EAGAIN) || e == Errno(syscall.EWOULDBLOCK) || e == Errno(syscall.ETIMEDOUT)
}
// Commonly known Unix errors.
var (
EPERM error = Errno(syscall.EPERM)
ENOENT error = Errno(syscall.ENOENT)
ESRCH error = Errno(syscall.ESRCH)
EINTR error = Errno(syscall.EINTR)
EIO error = Errno(syscall.EIO)
ENXIO error = Errno(syscall.ENXIO)
E2BIG error = Errno(syscall.E2BIG)
ENOEXEC error = Errno(syscall.ENOEXEC)
EBADF error = Errno(syscall.EBADF)
ECHILD error = Errno(syscall.ECHILD)
EDEADLK error = Errno(syscall.EDEADLK)
ENOMEM error = Errno(syscall.ENOMEM)
EACCES error = Errno(syscall.EACCES)
EFAULT error = Errno(syscall.EFAULT)
EBUSY error = Errno(syscall.EBUSY)
EEXIST error = Errno(syscall.EEXIST)
EXDEV error = Errno(syscall.EXDEV)
ENODEV error = Errno(syscall.ENODEV)
ENOTDIR error = Errno(syscall.ENOTDIR)
EISDIR error = Errno(syscall.EISDIR)
EINVAL error = Errno(syscall.EINVAL)
ENFILE error = Errno(syscall.ENFILE)
EMFILE error = Errno(syscall.EMFILE)
ENOTTY error = Errno(syscall.ENOTTY)
EFBIG error = Errno(syscall.EFBIG)
ENOSPC error = Errno(syscall.ENOSPC)
ESPIPE error = Errno(syscall.ESPIPE)
EROFS error = Errno(syscall.EROFS)
EMLINK error = Errno(syscall.EMLINK)
EPIPE error = Errno(syscall.EPIPE)
EAGAIN error = Errno(syscall.EAGAIN)
EDOM error = Errno(syscall.EDOM)
ERANGE error = Errno(syscall.ERANGE)
EADDRINUSE error = Errno(syscall.EADDRINUSE)
ECONNREFUSED error = Errno(syscall.ECONNREFUSED)
ENAMETOOLONG error = Errno(syscall.ENAMETOOLONG)
EAFNOSUPPORT error = Errno(syscall.EAFNOSUPPORT)
ETIMEDOUT error = Errno(syscall.ETIMEDOUT)
ENOTCONN error = Errno(syscall.ENOTCONN)
EPERM error = syscall.EPERM
ENOENT error = syscall.ENOENT
ESRCH error = syscall.ESRCH
EINTR error = syscall.EINTR
EIO error = syscall.EIO
ENXIO error = syscall.ENXIO
E2BIG error = syscall.E2BIG
ENOEXEC error = syscall.ENOEXEC
EBADF error = syscall.EBADF
ECHILD error = syscall.ECHILD
EDEADLK error = syscall.EDEADLK
ENOMEM error = syscall.ENOMEM
EACCES error = syscall.EACCES
EFAULT error = syscall.EFAULT
EBUSY error = syscall.EBUSY
EEXIST error = syscall.EEXIST
EXDEV error = syscall.EXDEV
ENODEV error = syscall.ENODEV
ENOTDIR error = syscall.ENOTDIR
EISDIR error = syscall.EISDIR
EINVAL error = syscall.EINVAL
ENFILE error = syscall.ENFILE
EMFILE error = syscall.EMFILE
ENOTTY error = syscall.ENOTTY
EFBIG error = syscall.EFBIG
ENOSPC error = syscall.ENOSPC
ESPIPE error = syscall.ESPIPE
EROFS error = syscall.EROFS
EMLINK error = syscall.EMLINK
EPIPE error = syscall.EPIPE
EAGAIN error = syscall.EAGAIN
EDOM error = syscall.EDOM
ERANGE error = syscall.ERANGE
EADDRINUSE error = syscall.EADDRINUSE
ECONNREFUSED error = syscall.ECONNREFUSED
ENAMETOOLONG error = syscall.ENAMETOOLONG
EAFNOSUPPORT error = syscall.EAFNOSUPPORT
ETIMEDOUT error = syscall.ETIMEDOUT
ENOTCONN error = syscall.ENOTCONN
)
// SyscallError records an error from a specific system call.
type SyscallError struct {
Syscall string
Errno Errno
Errno error
}
func (e *SyscallError) Error() string { return e.Syscall + ": " + e.Errno.Error() }
......@@ -79,14 +65,10 @@ func (e *SyscallError) Error() string { return e.Syscall + ": " + e.Errno.Error(
// NewSyscallError returns, as an error, a new SyscallError
// with the given system call name and error details.
// As a convenience, if errno is 0, NewSyscallError returns nil.
func NewSyscallError(syscall string, errno int) error {
if errno == 0 {
// As a convenience, if err is nil, NewSyscallError returns nil.
func NewSyscallError(syscall string, err error) error {
if err == nil {
return nil
}
return &SyscallError{syscall, Errno(errno)}
}
func iserror(errno int) bool {
return errno != 0
return &SyscallError{syscall, err}
}
......@@ -32,7 +32,7 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
sysattr.Files = intfd
pid, h, e := syscall.StartProcess(name, argv, sysattr)
if iserror(e) {
if e != nil {
return nil, &PathError{"fork/exec", name, e}
}
......@@ -52,7 +52,7 @@ func (p *Process) Signal(sig Signal) error {
}
f, e := OpenFile("/proc/"+itoa(p.Pid)+"/note", O_WRONLY, 0)
if iserror(e) {
if e != nil {
return NewSyscallError("signal", e)
}
defer f.Close()
......@@ -63,7 +63,7 @@ func (p *Process) Signal(sig Signal) error {
// Kill causes the Process to exit immediately.
func (p *Process) Kill() error {
f, e := OpenFile("/proc/"+itoa(p.Pid)+"/ctl", O_WRONLY, 0)
if iserror(e) {
if e != nil {
return NewSyscallError("kill", e)
}
defer f.Close()
......@@ -77,7 +77,7 @@ func (p *Process) Kill() error {
// ForkExec is almost always a better way to execute a program.
func Exec(name string, argv []string, envv []string) error {
e := syscall.Exec(name, argv, envv)
if iserror(e) {
if e != nil {
return &PathError{"exec", name, e}
}
......@@ -102,7 +102,7 @@ func (p *Process) Wait(options int) (w *Waitmsg, err error) {
for true {
err = syscall.Await(&waitmsg)
if iserror(err) {
if err != nil {
return nil, NewSyscallError("wait", err)
}
......
......@@ -40,8 +40,8 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
}
pid, h, e := syscall.StartProcess(name, argv, sysattr)
if iserror(e) {
return nil, &PathError{"fork/exec", name, Errno(e)}
if e != nil {
return nil, &PathError{"fork/exec", name, e}
}
return newProcess(pid, h), nil
}
......@@ -62,8 +62,8 @@ func Exec(name string, argv []string, envv []string) error {
envv = Environ()
}
e := syscall.Exec(name, argv, envv)
if iserror(e) {
return &PathError{"exec", name, Errno(e)}
if e != nil {
return &PathError{"exec", name, e}
}
return nil
}
......
......@@ -38,7 +38,7 @@ func (p *Process) Wait(options int) (w *Waitmsg, err error) {
options ^= WRUSAGE
}
pid1, e := syscall.Wait4(p.Pid, &status, options, rusage)
if e != 0 {
if e != nil {
return nil, NewSyscallError("wait", e)
}
// With WNOHANG pid is 0 if child has not exited.
......@@ -57,8 +57,8 @@ func (p *Process) Signal(sig Signal) error {
if p.done {
return errors.New("os: process already finished")
}
if e := syscall.Kill(p.Pid, int(sig.(UnixSignal))); e != 0 {
return Errno(e)
if e := syscall.Kill(p.Pid, int(sig.(UnixSignal))); e != nil {
return e
}
return nil
}
......
......@@ -22,7 +22,7 @@ func (p *Process) Wait(options int) (w *Waitmsg, err error) {
}
var ec uint32
e = syscall.GetExitCodeProcess(syscall.Handle(p.handle), &ec)
if e != 0 {
if e != nil {
return nil, NewSyscallError("GetExitCodeProcess", e)
}
p.done = true
......@@ -39,7 +39,7 @@ func (p *Process) Signal(sig Signal) error {
e := syscall.TerminateProcess(syscall.Handle(p.handle), 1)
return NewSyscallError("TerminateProcess", e)
}
return Errno(syscall.EWINDOWS)
return syscall.Errno(syscall.EWINDOWS)
}
func (p *Process) Release() error {
......@@ -47,7 +47,7 @@ func (p *Process) Release() error {
return EINVAL
}
e := syscall.CloseHandle(syscall.Handle(p.handle))
if e != 0 {
if e != nil {
return NewSyscallError("CloseHandle", e)
}
p.handle = -1
......@@ -60,7 +60,7 @@ func FindProcess(pid int) (p *Process, err error) {
const da = syscall.STANDARD_RIGHTS_READ |
syscall.PROCESS_QUERY_INFORMATION | syscall.SYNCHRONIZE
h, e := syscall.OpenProcess(da, false, uint32(pid))
if e != 0 {
if e != nil {
return nil, NewSyscallError("OpenProcess", e)
}
return newProcess(pid, int(h)), nil
......
......@@ -59,11 +59,11 @@ func (file *File) Read(b []byte) (n int, err error) {
if n < 0 {
n = 0
}
if n == 0 && len(b) > 0 && !iserror(e) {
if n == 0 && len(b) > 0 && e == nil {
return 0, io.EOF
}
if iserror(e) {
err = &PathError{"read", file.name, Errno(e)}
if e != nil {
err = &PathError{"read", file.name, e}
}
return n, err
}
......@@ -78,11 +78,11 @@ func (file *File) ReadAt(b []byte, off int64) (n int, err error) {
}
for len(b) > 0 {
m, e := file.pread(b, off)
if m == 0 && !iserror(e) {
if m == 0 && e == nil {
return n, io.EOF
}
if iserror(e) {
err = &PathError{"read", file.name, Errno(e)}
if e != nil {
err = &PathError{"read", file.name, e}
break
}
n += m
......@@ -106,8 +106,8 @@ func (file *File) Write(b []byte) (n int, err error) {
epipecheck(file, e)
if iserror(e) {
err = &PathError{"write", file.name, Errno(e)}
if e != nil {
err = &PathError{"write", file.name, e}
}
return n, err
}
......@@ -121,8 +121,8 @@ func (file *File) WriteAt(b []byte, off int64) (n int, err error) {
}
for len(b) > 0 {
m, e := file.pwrite(b, off)
if iserror(e) {
err = &PathError{"write", file.name, Errno(e)}
if e != nil {
err = &PathError{"write", file.name, e}
break
}
n += m
......@@ -138,11 +138,11 @@ func (file *File) WriteAt(b []byte, off int64) (n int, err error) {
// It returns the new offset and an error, if any.
func (file *File) Seek(offset int64, whence int) (ret int64, err error) {
r, e := file.seek(offset, whence)
if !iserror(e) && file.dirinfo != nil && r != 0 {
if e == nil && file.dirinfo != nil && r != 0 {
e = syscall.EISDIR
}
if iserror(e) {
return 0, &PathError{"seek", file.name, Errno(e)}
if e != nil {
return 0, &PathError{"seek", file.name, e}
}
return r, nil
}
......@@ -160,16 +160,16 @@ func (file *File) WriteString(s string) (ret int, err error) {
// It returns an error, if any.
func Mkdir(name string, perm uint32) error {
e := syscall.Mkdir(name, perm)
if iserror(e) {
return &PathError{"mkdir", name, Errno(e)}
if e != nil {
return &PathError{"mkdir", name, e}
}
return nil
}
// Chdir changes the current working directory to the named directory.
func Chdir(dir string) error {
if e := syscall.Chdir(dir); iserror(e) {
return &PathError{"chdir", dir, Errno(e)}
if e := syscall.Chdir(dir); e != nil {
return &PathError{"chdir", dir, e}
}
return nil
}
......@@ -177,8 +177,8 @@ func Chdir(dir string) error {
// Chdir changes the current working directory to the file,
// which must be a directory.
func (f *File) Chdir() error {
if e := syscall.Fchdir(f.fd); iserror(e) {
return &PathError{"chdir", f.name, Errno(e)}
if e := syscall.Fchdir(f.fd); e != nil {
return &PathError{"chdir", f.name, e}
}
return nil
}
......
......@@ -41,7 +41,7 @@ type dirInfo struct {
bufp int // location of next record in buf.
}
func epipecheck(file *File, e syscall.Error) {
func epipecheck(file *File, e error) {
}
// DevNull is the name of the operating system's ``null device.''
......@@ -130,7 +130,7 @@ func (file *File) Close() error {
// It returns the FileInfo and an error, if any.
func (f *File) Stat() (fi *FileInfo, err error) {
d, err := dirstat(f)
if iserror(err) {
if err != nil {
return nil, err
}
return fileInfoFromStat(new(FileInfo), d), err
......@@ -144,7 +144,7 @@ func (f *File) Truncate(size int64) error {
d.Length = uint64(size)
if e := syscall.Fwstat(f.fd, pdir(nil, &d)); iserror(e) {
if e := syscall.Fwstat(f.fd, pdir(nil, &d)); e != nil {
return &PathError{"truncate", f.name, e}
}
return nil
......@@ -157,12 +157,12 @@ func (f *File) Chmod(mode uint32) error {
d.Null()
odir, e := dirstat(f)
if iserror(e) {
if e != nil {
return &PathError{"chmod", f.name, e}
}
d.Mode = (odir.Mode & mask) | (mode &^ mask)
if e := syscall.Fwstat(f.fd, pdir(nil, &d)); iserror(e) {
if e := syscall.Fwstat(f.fd, pdir(nil, &d)); e != nil {
return &PathError{"chmod", f.name, e}
}
return nil
......@@ -179,7 +179,7 @@ func (f *File) Sync() (err error) {
var d Dir
d.Null()
if e := syscall.Fwstat(f.fd, pdir(nil, &d)); iserror(e) {
if e := syscall.Fwstat(f.fd, pdir(nil, &d)); e != nil {
return NewSyscallError("fsync", e)
}
return nil
......@@ -226,7 +226,7 @@ func Truncate(name string, size int64) error {
d.Length = uint64(size)
if e := syscall.Wstat(name, pdir(nil, &d)); iserror(e) {
if e := syscall.Wstat(name, pdir(nil, &d)); e != nil {
return &PathError{"truncate", name, e}
}
return nil
......@@ -234,7 +234,7 @@ func Truncate(name string, size int64) error {
// Remove removes the named file or directory.
func Remove(name string) error {
if e := syscall.Remove(name); iserror(e) {
if e := syscall.Remove(name); e != nil {
return &PathError{"remove", name, e}
}
return nil
......@@ -247,7 +247,7 @@ func Rename(oldname, newname string) error {
d.Name = newname
if e := syscall.Wstat(oldname, pdir(nil, &d)); iserror(e) {
if e := syscall.Wstat(oldname, pdir(nil, &d)); e != nil {
return &PathError{"rename", oldname, e}
}
return nil
......@@ -260,12 +260,12 @@ func Chmod(name string, mode uint32) error {
d.Null()
odir, e := dirstat(name)
if iserror(e) {
if e != nil {
return &PathError{"chmod", name, e}
}
d.Mode = (odir.Mode & mask) | (mode &^ mask)
if e := syscall.Wstat(name, pdir(nil, &d)); iserror(e) {
if e := syscall.Wstat(name, pdir(nil, &d)); e != nil {
return &PathError{"chmod", name, e}
}
return nil
......@@ -284,7 +284,7 @@ func Chtimes(name string, atimeNs int64, mtimeNs int64) error {
d.Atime = uint32(atimeNs / 1e9)
d.Mtime = uint32(mtimeNs / 1e9)
if e := syscall.Wstat(name, pdir(nil, &d)); iserror(e) {
if e := syscall.Wstat(name, pdir(nil, &d)); e != nil {
return &PathError{"chtimes", name, e}
}
return nil
......@@ -294,7 +294,7 @@ func Pipe() (r *File, w *File, err error) {
var p [2]int
syscall.ForkLock.RLock()
if e := syscall.Pipe(p[0:]); iserror(e) {
if e := syscall.Pipe(p[0:]); e != nil {
syscall.ForkLock.RUnlock()
return nil, nil, NewSyscallError("pipe", e)
}
......
......@@ -12,7 +12,7 @@ import (
func sigpipe() // implemented in package runtime
func epipecheck(file *File, e int) {
func epipecheck(file *File, e error) {
if e == syscall.EPIPE {
file.nepipe++
if file.nepipe >= 10 {
......@@ -30,11 +30,11 @@ func Remove(name string) error {
// Try both: it is cheaper on average than
// doing a Stat plus the right one.
e := syscall.Unlink(name)
if !iserror(e) {
if e == nil {
return nil
}
e1 := syscall.Rmdir(name)
if !iserror(e1) {
if e1 == nil {
return nil
}
......@@ -53,7 +53,7 @@ func Remove(name string) error {
if e1 != syscall.ENOTDIR {
e = e1
}
return &PathError{"remove", name, Errno(e)}
return &PathError{"remove", name, e}
}
// LinkError records an error during a link or symlink or rename
......@@ -72,8 +72,8 @@ func (e *LinkError) Error() string {
// Link creates a hard link.
func Link(oldname, newname string) error {
e := syscall.Link(oldname, newname)
if iserror(e) {
return &LinkError{"link", oldname, newname, Errno(e)}
if e != nil {
return &LinkError{"link", oldname, newname, e}
}
return nil
}
......@@ -81,8 +81,8 @@ func Link(oldname, newname string) error {
// Symlink creates a symbolic link.
func Symlink(oldname, newname string) error {
e := syscall.Symlink(oldname, newname)
if iserror(e) {
return &LinkError{"symlink", oldname, newname, Errno(e)}
if e != nil {
return &LinkError{"symlink", oldname, newname, e}
}
return nil
}
......@@ -93,8 +93,8 @@ func Readlink(name string) (string, error) {
for len := 128; ; len *= 2 {
b := make([]byte, len)
n, e := syscall.Readlink(name, b)
if iserror(e) {
return "", &PathError{"readlink", name, Errno(e)}
if e != nil {
return "", &PathError{"readlink", name, e}
}
if n < len {
return string(b[0:n]), nil
......@@ -107,8 +107,8 @@ func Readlink(name string) (string, error) {
// Rename renames a file.
func Rename(oldname, newname string) error {
e := syscall.Rename(oldname, newname)
if iserror(e) {
return &LinkError{"rename", oldname, newname, Errno(e)}
if e != nil {
return &LinkError{"rename", oldname, newname, e}
}
return nil
}
......@@ -116,16 +116,16 @@ func Rename(oldname, newname string) error {
// Chmod changes the mode of the named file to mode.
// If the file is a symbolic link, it changes the mode of the link's target.
func Chmod(name string, mode uint32) error {
if e := syscall.Chmod(name, mode); iserror(e) {
return &PathError{"chmod", name, Errno(e)}
if e := syscall.Chmod(name, mode); e != nil {
return &PathError{"chmod", name, e}
}
return nil
}
// Chmod changes the mode of the file to mode.
func (f *File) Chmod(mode uint32) error {
if e := syscall.Fchmod(f.fd, mode); iserror(e) {
return &PathError{"chmod", f.name, Errno(e)}
if e := syscall.Fchmod(f.fd, mode); e != nil {
return &PathError{"chmod", f.name, e}
}
return nil
}
......@@ -133,8 +133,8 @@ func (f *File) Chmod(mode uint32) error {
// Chown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link's target.
func Chown(name string, uid, gid int) error {
if e := syscall.Chown(name, uid, gid); iserror(e) {
return &PathError{"chown", name, Errno(e)}
if e := syscall.Chown(name, uid, gid); e != nil {
return &PathError{"chown", name, e}
}
return nil
}
......@@ -142,16 +142,16 @@ func Chown(name string, uid, gid int) error {
// Lchown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link itself.
func Lchown(name string, uid, gid int) error {
if e := syscall.Lchown(name, uid, gid); iserror(e) {
return &PathError{"lchown", name, Errno(e)}
if e := syscall.Lchown(name, uid, gid); e != nil {
return &PathError{"lchown", name, e}
}
return nil
}
// Chown changes the numeric uid and gid of the named file.
func (f *File) Chown(uid, gid int) error {
if e := syscall.Fchown(f.fd, uid, gid); iserror(e) {
return &PathError{"chown", f.name, Errno(e)}
if e := syscall.Fchown(f.fd, uid, gid); e != nil {
return &PathError{"chown", f.name, e}
}
return nil
}
......@@ -159,8 +159,8 @@ func (f *File) Chown(uid, gid int) error {
// Truncate changes the size of the file.
// It does not change the I/O offset.
func (f *File) Truncate(size int64) error {
if e := syscall.Ftruncate(f.fd, size); iserror(e) {
return &PathError{"truncate", f.name, Errno(e)}
if e := syscall.Ftruncate(f.fd, size); e != nil {
return &PathError{"truncate", f.name, e}
}
return nil
}
......@@ -172,7 +172,7 @@ func (file *File) Sync() (err error) {
if file == nil {
return EINVAL
}
if e := syscall.Fsync(file.fd); iserror(e) {
if e := syscall.Fsync(file.fd); e != nil {
return NewSyscallError("fsync", e)
}
return nil
......@@ -188,8 +188,8 @@ func Chtimes(name string, atime_ns int64, mtime_ns int64) error {
var utimes [2]syscall.Timeval
utimes[0] = syscall.NsecToTimeval(atime_ns)
utimes[1] = syscall.NsecToTimeval(mtime_ns)
if e := syscall.Utimes(name, utimes[0:]); iserror(e) {
return &PathError{"chtimes", name, Errno(e)}
if e := syscall.Utimes(name, utimes[0:]); e != nil {
return &PathError{"chtimes", name, e}
}
return nil
}
......@@ -55,8 +55,8 @@ const DevNull = "/dev/null"
// It returns the File and an error, if any.
func OpenFile(name string, flag int, perm uint32) (file *File, err error) {
r, e := syscall.Open(name, flag|syscall.O_CLOEXEC, perm)
if e != 0 {
return nil, &PathError{"open", name, Errno(e)}
if e != nil {
return nil, &PathError{"open", name, e}
}
// There's a race here with fork/exec, which we are
......@@ -75,8 +75,8 @@ func (file *File) Close() error {
return EINVAL
}
var err error
if e := syscall.Close(file.fd); e != 0 {
err = &PathError{"close", file.name, Errno(e)}
if e := syscall.Close(file.fd); e != nil {
err = &PathError{"close", file.name, e}
}
file.fd = -1 // so it can't be closed again
......@@ -90,8 +90,8 @@ func (file *File) Close() error {
func (file *File) Stat() (fi *FileInfo, err error) {
var stat syscall.Stat_t
e := syscall.Fstat(file.fd, &stat)
if e != 0 {
return nil, &PathError{"stat", file.name, Errno(e)}
if e != nil {
return nil, &PathError{"stat", file.name, e}
}
return fileInfoFromStat(file.name, new(FileInfo), &stat, &stat), nil
}
......@@ -104,13 +104,13 @@ func (file *File) Stat() (fi *FileInfo, err error) {
func Stat(name string) (fi *FileInfo, err error) {
var lstat, stat syscall.Stat_t
e := syscall.Lstat(name, &lstat)
if iserror(e) {
return nil, &PathError{"stat", name, Errno(e)}
if e != nil {
return nil, &PathError{"stat", name, e}
}
statp := &lstat
if lstat.Mode&syscall.S_IFMT == syscall.S_IFLNK {
e := syscall.Stat(name, &stat)
if !iserror(e) {
if e == nil {
statp = &stat
}
}
......@@ -123,8 +123,8 @@ func Stat(name string) (fi *FileInfo, err error) {
func Lstat(name string) (fi *FileInfo, err error) {
var stat syscall.Stat_t
e := syscall.Lstat(name, &stat)
if iserror(e) {
return nil, &PathError{"lstat", name, Errno(e)}
if e != nil {
return nil, &PathError{"lstat", name, e}
}
return fileInfoFromStat(name, new(FileInfo), &stat, &stat), nil
}
......@@ -165,26 +165,26 @@ func (file *File) Readdir(n int) (fi []FileInfo, err error) {
// read reads up to len(b) bytes from the File.
// It returns the number of bytes read and an error, if any.
func (f *File) read(b []byte) (n int, err int) {
func (f *File) read(b []byte) (n int, err error) {
return syscall.Read(f.fd, b)
}
// pread reads len(b) bytes from the File starting at byte offset off.
// It returns the number of bytes read and the error, if any.
// EOF is signaled by a zero count with err set to 0.
func (f *File) pread(b []byte, off int64) (n int, err int) {
func (f *File) pread(b []byte, off int64) (n int, err error) {
return syscall.Pread(f.fd, b, off)
}
// write writes len(b) bytes to the File.
// It returns the number of bytes written and an error, if any.
func (f *File) write(b []byte) (n int, err int) {
func (f *File) write(b []byte) (n int, err error) {
return syscall.Write(f.fd, b)
}
// pwrite writes len(b) bytes to the File starting at byte offset off.
// It returns the number of bytes written and an error, if any.
func (f *File) pwrite(b []byte, off int64) (n int, err int) {
func (f *File) pwrite(b []byte, off int64) (n int, err error) {
return syscall.Pwrite(f.fd, b, off)
}
......@@ -192,15 +192,15 @@ func (f *File) pwrite(b []byte, off int64) (n int, err int) {
// according to whence: 0 means relative to the origin of the file, 1 means
// relative to the current offset, and 2 means relative to the end.
// It returns the new offset and an error, if any.
func (f *File) seek(offset int64, whence int) (ret int64, err int) {
func (f *File) seek(offset int64, whence int) (ret int64, err error) {
return syscall.Seek(f.fd, offset, whence)
}
// Truncate changes the size of the named file.
// If the file is a symbolic link, it changes the size of the link's target.
func Truncate(name string, size int64) error {
if e := syscall.Truncate(name, size); e != 0 {
return &PathError{"truncate", name, Errno(e)}
if e := syscall.Truncate(name, size); e != nil {
return &PathError{"truncate", name, e}
}
return nil
}
......@@ -231,7 +231,7 @@ func Pipe() (r *File, w *File, err error) {
// See ../syscall/exec.go for description of lock.
syscall.ForkLock.RLock()
e := syscall.Pipe(p[0:])
if iserror(e) {
if e != nil {
syscall.ForkLock.RUnlock()
return nil, nil, NewSyscallError("pipe", e)
}
......
......@@ -50,8 +50,8 @@ func (file *File) isdir() bool { return file != nil && file.dirinfo != nil }
func openFile(name string, flag int, perm uint32) (file *File, err error) {
r, e := syscall.Open(name, flag|syscall.O_CLOEXEC, perm)
if e != 0 {
return nil, &PathError{"open", name, Errno(e)}
if e != nil {
return nil, &PathError{"open", name, e}
}
// There's a race here with fork/exec, which we are
......@@ -66,8 +66,8 @@ func openFile(name string, flag int, perm uint32) (file *File, err error) {
func openDir(name string) (file *File, err error) {
d := new(dirInfo)
r, e := syscall.FindFirstFile(syscall.StringToUTF16Ptr(name+`\*`), &d.data)
if e != 0 {
return nil, &PathError{"open", name, Errno(e)}
if e != nil {
return nil, &PathError{"open", name, e}
}
f := NewFile(r, name)
f.dirinfo = d
......@@ -102,15 +102,15 @@ func (file *File) Close() error {
if file == nil || file.fd < 0 {
return EINVAL
}
var e int
var e error
if file.isdir() {
e = syscall.FindClose(syscall.Handle(file.fd))
} else {
e = syscall.CloseHandle(syscall.Handle(file.fd))
}
var err error
if e != 0 {
err = &PathError{"close", file.name, Errno(e)}
if e != nil {
err = &PathError{"close", file.name, e}
}
file.fd = syscall.InvalidHandle // so it can't be closed again
......@@ -152,11 +152,11 @@ func (file *File) Readdir(n int) (fi []FileInfo, err error) {
for n != 0 {
if file.dirinfo.needdata {
e := syscall.FindNextFile(syscall.Handle(file.fd), d)
if e != 0 {
if e != nil {
if e == syscall.ERROR_NO_MORE_FILES {
break
} else {
err = &PathError{"FindNextFile", file.name, Errno(e)}
err = &PathError{"FindNextFile", file.name, e}
if !wantAll {
fi = nil
}
......@@ -181,7 +181,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err error) {
// read reads up to len(b) bytes from the File.
// It returns the number of bytes read and an error, if any.
func (f *File) read(b []byte) (n int, err int) {
func (f *File) read(b []byte) (n int, err error) {
f.l.Lock()
defer f.l.Unlock()
return syscall.Read(f.fd, b)
......@@ -190,11 +190,11 @@ func (f *File) read(b []byte) (n int, err int) {
// pread reads len(b) bytes from the File starting at byte offset off.
// It returns the number of bytes read and the error, if any.
// EOF is signaled by a zero count with err set to 0.
func (f *File) pread(b []byte, off int64) (n int, err int) {
func (f *File) pread(b []byte, off int64) (n int, err error) {
f.l.Lock()
defer f.l.Unlock()
curoffset, e := syscall.Seek(f.fd, 0, 1)
if e != 0 {
if e != nil {
return 0, e
}
defer syscall.Seek(f.fd, curoffset, 0)
......@@ -204,15 +204,15 @@ func (f *File) pread(b []byte, off int64) (n int, err int) {
}
var done uint32
e = syscall.ReadFile(syscall.Handle(f.fd), b, &done, &o)
if e != 0 {
if e != nil {
return 0, e
}
return int(done), 0
return int(done), nil
}
// write writes len(b) bytes to the File.
// It returns the number of bytes written and an error, if any.
func (f *File) write(b []byte) (n int, err int) {
func (f *File) write(b []byte) (n int, err error) {
f.l.Lock()
defer f.l.Unlock()
return syscall.Write(f.fd, b)
......@@ -220,11 +220,11 @@ func (f *File) write(b []byte) (n int, err int) {
// pwrite writes len(b) bytes to the File starting at byte offset off.
// It returns the number of bytes written and an error, if any.
func (f *File) pwrite(b []byte, off int64) (n int, err int) {
func (f *File) pwrite(b []byte, off int64) (n int, err error) {
f.l.Lock()
defer f.l.Unlock()
curoffset, e := syscall.Seek(f.fd, 0, 1)
if e != 0 {
if e != nil {
return 0, e
}
defer syscall.Seek(f.fd, curoffset, 0)
......@@ -234,17 +234,17 @@ func (f *File) pwrite(b []byte, off int64) (n int, err int) {
}
var done uint32
e = syscall.WriteFile(syscall.Handle(f.fd), b, &done, &o)
if e != 0 {
if e != nil {
return 0, e
}
return int(done), 0
return int(done), nil
}
// seek sets the offset for the next Read or Write on file to offset, interpreted
// according to whence: 0 means relative to the origin of the file, 1 means
// relative to the current offset, and 2 means relative to the end.
// It returns the new offset and an error, if any.
func (f *File) seek(offset int64, whence int) (ret int64, err int) {
func (f *File) seek(offset int64, whence int) (ret int64, err error) {
f.l.Lock()
defer f.l.Unlock()
return syscall.Seek(f.fd, offset, whence)
......@@ -273,7 +273,7 @@ func Pipe() (r *File, w *File, err error) {
// See ../syscall/exec.go for description of lock.
syscall.ForkLock.RLock()
e := syscall.Pipe(p[0:])
if iserror(e) {
if e != nil {
syscall.ForkLock.RUnlock()
return nil, nil, NewSyscallError("pipe", e)
}
......
......@@ -72,7 +72,7 @@ func dirstat(arg interface{}) (d *Dir, err error) {
// Stat returns a FileInfo structure describing the named file and an error, if any.
func Stat(name string) (fi *FileInfo, err error) {
d, err := dirstat(name)
if iserror(err) {
if err != nil {
return nil, err
}
return fileInfoFromStat(new(FileInfo), d), err
......@@ -83,7 +83,7 @@ func Stat(name string) (fi *FileInfo, err error) {
// the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link.
func Lstat(name string) (fi *FileInfo, err error) {
d, err := dirstat(name)
if iserror(err) {
if err != nil {
return nil, err
}
return fileInfoFromStat(new(FileInfo), d), err
......
......@@ -21,8 +21,8 @@ func (file *File) Stat() (fi *FileInfo, err error) {
}
var d syscall.ByHandleFileInformation
e := syscall.GetFileInformationByHandle(syscall.Handle(file.fd), &d)
if e != 0 {
return nil, &PathError{"GetFileInformationByHandle", file.name, Errno(e)}
if e != nil {
return nil, &PathError{"GetFileInformationByHandle", file.name, e}
}
return setFileInfo(new(FileInfo), basename(file.name), d.FileAttributes, d.FileSizeHigh, d.FileSizeLow, d.CreationTime, d.LastAccessTime, d.LastWriteTime), nil
}
......@@ -34,12 +34,12 @@ func (file *File) Stat() (fi *FileInfo, err error) {
// the link itself and has fi.FollowedSymlink set to false.
func Stat(name string) (fi *FileInfo, err error) {
if len(name) == 0 {
return nil, &PathError{"Stat", name, Errno(syscall.ERROR_PATH_NOT_FOUND)}
return nil, &PathError{"Stat", name, syscall.Errno(syscall.ERROR_PATH_NOT_FOUND)}
}
var d syscall.Win32FileAttributeData
e := syscall.GetFileAttributesEx(syscall.StringToUTF16Ptr(name), syscall.GetFileExInfoStandard, (*byte)(unsafe.Pointer(&d)))
if e != 0 {
return nil, &PathError{"GetFileAttributesEx", name, Errno(e)}
if e != nil {
return nil, &PathError{"GetFileAttributesEx", name, e}
}
return setFileInfo(new(FileInfo), basename(name), d.FileAttributes, d.FileSizeHigh, d.FileSizeLow, d.CreationTime, d.LastAccessTime, d.LastWriteTime), nil
}
......
......@@ -12,10 +12,9 @@ package os
import "syscall"
func Hostname() (name string, err error) {
var errno int
name, errno = syscall.Sysctl("kern.hostname")
if errno != 0 {
return "", NewSyscallError("sysctl kern.hostname", errno)
name, err = syscall.Sysctl("kern.hostname")
if err != nil {
return "", NewSyscallError("sysctl kern.hostname", err)
}
return name, nil
}
......@@ -8,7 +8,7 @@ import "syscall"
func Hostname() (name string, err error) {
s, e := syscall.ComputerName()
if e != 0 {
if e != nil {
return "", NewSyscallError("ComputerName", e)
}
return s, nil
......
......@@ -12,7 +12,7 @@ import "syscall"
// time is the Unix epoch.
func Time() (sec int64, nsec int64, err error) {
var tv syscall.Timeval
if e := syscall.Gettimeofday(&tv); iserror(e) {
if e := syscall.Gettimeofday(&tv); e != nil {
return 0, 0, NewSyscallError("gettimeofday", e)
}
return int64(tv.Sec), int64(tv.Usec) * 1000, err
......
......@@ -8,9 +8,9 @@ package user
import (
"fmt"
"os"
"runtime"
"strings"
"syscall"
"unsafe"
)
......@@ -71,7 +71,7 @@ func lookup(uid int, username string, lookupByName bool) (*User, error) {
C.size_t(bufSize),
&result)
if rv != 0 {
return nil, fmt.Errorf("user: lookup username %s: %s", username, os.Errno(rv))
return nil, fmt.Errorf("user: lookup username %s: %s", username, syscall.Errno(rv))
}
if result == nil {
return nil, UnknownUserError(username)
......@@ -86,7 +86,7 @@ func lookup(uid int, username string, lookupByName bool) (*User, error) {
C.size_t(bufSize),
&result)
if rv != 0 {
return nil, fmt.Errorf("user: lookup userid %d: %s", uid, os.Errno(rv))
return nil, fmt.Errorf("user: lookup userid %d: %s", uid, syscall.Errno(rv))
}
if result == nil {
return nil, UnknownUserIdError(uid)
......
......@@ -20,54 +20,54 @@ func BpfJump(code, k, jt, jf int) *BpfInsn {
return &BpfInsn{Code: uint16(code), Jt: uint8(jt), Jf: uint8(jf), K: uint32(k)}
}
func BpfBuflen(fd int) (int, int) {
func BpfBuflen(fd int) (int, error) {
var l int
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGBLEN, uintptr(unsafe.Pointer(&l)))
if e := int(ep); e != 0 {
return 0, e
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGBLEN, uintptr(unsafe.Pointer(&l)))
if err != 0 {
return 0, Errno(err)
}
return l, 0
return l, nil
}
func SetBpfBuflen(fd, l int) (int, int) {
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSBLEN, uintptr(unsafe.Pointer(&l)))
if e := int(ep); e != 0 {
return 0, e
func SetBpfBuflen(fd, l int) (int, error) {
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSBLEN, uintptr(unsafe.Pointer(&l)))
if err != 0 {
return 0, Errno(err)
}
return l, 0
return l, nil
}
func BpfDatalink(fd int) (int, int) {
func BpfDatalink(fd int) (int, error) {
var t int
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGDLT, uintptr(unsafe.Pointer(&t)))
if e := int(ep); e != 0 {
return 0, e
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGDLT, uintptr(unsafe.Pointer(&t)))
if err != 0 {
return 0, Errno(err)
}
return t, 0
return t, nil
}
func SetBpfDatalink(fd, t int) (int, int) {
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSDLT, uintptr(unsafe.Pointer(&t)))
if e := int(ep); e != 0 {
return 0, e
func SetBpfDatalink(fd, t int) (int, error) {
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSDLT, uintptr(unsafe.Pointer(&t)))
if err != 0 {
return 0, Errno(err)
}
return t, 0
return t, nil
}
func SetBpfPromisc(fd, m int) int {
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCPROMISC, uintptr(unsafe.Pointer(&m)))
if e := int(ep); e != 0 {
return e
func SetBpfPromisc(fd, m int) error {
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCPROMISC, uintptr(unsafe.Pointer(&m)))
if err != 0 {
return Errno(err)
}
return 0
return nil
}
func FlushBpf(fd int) int {
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCFLUSH, 0)
if e := int(ep); e != 0 {
return e
func FlushBpf(fd int) error {
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCFLUSH, 0)
if err != 0 {
return Errno(err)
}
return 0
return nil
}
type ivalue struct {
......@@ -75,95 +75,95 @@ type ivalue struct {
value int16
}
func BpfInterface(fd int, name string) (string, int) {
func BpfInterface(fd int, name string) (string, error) {
var iv ivalue
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGETIF, uintptr(unsafe.Pointer(&iv)))
if e := int(ep); e != 0 {
return "", e
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGETIF, uintptr(unsafe.Pointer(&iv)))
if err != 0 {
return "", Errno(err)
}
return name, 0
return name, nil
}
func SetBpfInterface(fd int, name string) int {
func SetBpfInterface(fd int, name string) error {
var iv ivalue
copy(iv.name[:], []byte(name))
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSETIF, uintptr(unsafe.Pointer(&iv)))
if e := int(ep); e != 0 {
return e
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSETIF, uintptr(unsafe.Pointer(&iv)))
if err != 0 {
return Errno(err)
}
return 0
return nil
}
func BpfTimeout(fd int) (*Timeval, int) {
func BpfTimeout(fd int) (*Timeval, error) {
var tv Timeval
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGRTIMEOUT, uintptr(unsafe.Pointer(&tv)))
if e := int(ep); e != 0 {
return nil, e
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGRTIMEOUT, uintptr(unsafe.Pointer(&tv)))
if err != 0 {
return nil, Errno(err)
}
return &tv, 0
return &tv, nil
}
func SetBpfTimeout(fd int, tv *Timeval) int {
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSRTIMEOUT, uintptr(unsafe.Pointer(tv)))
if e := int(ep); e != 0 {
return e
func SetBpfTimeout(fd int, tv *Timeval) error {
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSRTIMEOUT, uintptr(unsafe.Pointer(tv)))
if err != 0 {
return Errno(err)
}
return 0
return nil
}
func BpfStats(fd int) (*BpfStat, int) {
func BpfStats(fd int) (*BpfStat, error) {
var s BpfStat
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGSTATS, uintptr(unsafe.Pointer(&s)))
if e := int(ep); e != 0 {
return nil, e
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGSTATS, uintptr(unsafe.Pointer(&s)))
if err != 0 {
return nil, Errno(err)
}
return &s, 0
return &s, nil
}
func SetBpfImmediate(fd, m int) int {
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCIMMEDIATE, uintptr(unsafe.Pointer(&m)))
if e := int(ep); e != 0 {
return e
func SetBpfImmediate(fd, m int) error {
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCIMMEDIATE, uintptr(unsafe.Pointer(&m)))
if err != 0 {
return Errno(err)
}
return 0
return nil
}
func SetBpf(fd int, i []BpfInsn) int {
func SetBpf(fd int, i []BpfInsn) error {
var p BpfProgram
p.Len = uint32(len(i))
p.Insns = (*BpfInsn)(unsafe.Pointer(&i[0]))
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSETF, uintptr(unsafe.Pointer(&p)))
if e := int(ep); e != 0 {
return e
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSETF, uintptr(unsafe.Pointer(&p)))
if err != 0 {
return Errno(err)
}
return 0
return nil
}
func CheckBpfVersion(fd int) int {
func CheckBpfVersion(fd int) error {
var v BpfVersion
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCVERSION, uintptr(unsafe.Pointer(&v)))
if e := int(ep); e != 0 {
return e
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCVERSION, uintptr(unsafe.Pointer(&v)))
if err != 0 {
return Errno(err)
}
if v.Major != BPF_MAJOR_VERSION || v.Minor != BPF_MINOR_VERSION {
return EINVAL
}
return 0
return nil
}
func BpfHeadercmpl(fd int) (int, int) {
func BpfHeadercmpl(fd int) (int, error) {
var f int
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCGHDRCMPLT, uintptr(unsafe.Pointer(&f)))
if e := int(ep); e != 0 {
return 0, e
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGHDRCMPLT, uintptr(unsafe.Pointer(&f)))
if err != 0 {
return 0, Errno(err)
}
return f, 0
return f, nil
}
func SetBpfHeadercmpl(fd, f int) int {
_, _, ep := Syscall(SYS_IOCTL, uintptr(fd), BIOCSHDRCMPLT, uintptr(unsafe.Pointer(&f)))
if e := int(ep); e != 0 {
return e
func SetBpfHeadercmpl(fd, f int) error {
_, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSHDRCMPLT, uintptr(unsafe.Pointer(&f)))
if err != 0 {
return Errno(err)
}
return 0
return nil
}
......@@ -9,13 +9,15 @@ import (
)
// Errno is the Windows error number.
type Errno uint64
type Errno uintptr
func (e Errno) Error() string { return Errstr(int(e)) }
func (e Errno) Error() string {
return errstr(e)
}
// DLLError describes reasons for DLL load failures.
type DLLError struct {
Errno Errno
Err error
ObjName string
Msg string
}
......@@ -23,12 +25,12 @@ type DLLError struct {
func (e *DLLError) Error() string { return e.Msg }
// Implemented in ../runtime/windows/syscall.goc.
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)
func loadlibrary(filename *uint16) (handle, err uintptr)
func getprocaddress(handle uintptr, procname *uint8) (proc, err uintptr)
func Syscall(trap, nargs, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
func Syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
func Syscall9(trap, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
func Syscall12(trap, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 uintptr) (r1, r2 uintptr, err Errno)
func loadlibrary(filename *uint16) (handle, err Errno)
func getprocaddress(handle uintptr, procname *uint8) (proc uintptr, err Errno)
// A DLL implements access to a single DLL.
type DLL struct {
......@@ -41,9 +43,9 @@ func LoadDLL(name string) (dll *DLL, err error) {
h, e := loadlibrary(StringToUTF16Ptr(name))
if e != 0 {
return nil, &DLLError{
Errno: Errno(e),
Err: e,
ObjName: name,
Msg: "Failed to load " + name + ": " + Errstr(int(e)),
Msg: "Failed to load " + name + ": " + e.Error(),
}
}
d := &DLL{
......@@ -68,9 +70,9 @@ func (d *DLL) FindProc(name string) (proc *Proc, err error) {
a, e := getprocaddress(uintptr(d.Handle), StringBytePtr(name))
if e != 0 {
return nil, &DLLError{
Errno: Errno(e),
Err: e,
ObjName: name,
Msg: "Failed to find " + name + " procedure in " + d.Name + ": " + Errstr(int(e)),
Msg: "Failed to find " + name + " procedure in " + d.Name + ": " + e.Error(),
}
}
p := &Proc{
......@@ -91,8 +93,8 @@ func (d *DLL) MustFindProc(name string) *Proc {
}
// Release unloads DLL d from memory.
func (d *DLL) Release() (err Errno) {
return Errno(FreeLibrary(d.Handle))
func (d *DLL) Release() (err error) {
return FreeLibrary(d.Handle)
}
// A Proc implements access to a procedure inside a DLL.
......@@ -109,7 +111,7 @@ func (p *Proc) Addr() uintptr {
}
// Call executes procedure p with arguments a.
func (p *Proc) Call(a ...uintptr) (r1, r2, err uintptr) {
func (p *Proc) Call(a ...uintptr) (r1, r2 uintptr, err error) {
switch len(a) {
case 0:
return Syscall(p.Addr(), uintptr(len(a)), 0, 0, 0)
......@@ -241,7 +243,7 @@ func (p *LazyProc) Addr() uintptr {
}
// Call executes procedure p with arguments a.
func (p *LazyProc) Call(a ...uintptr) (r1, r2, err uintptr) {
func (p *LazyProc) Call(a ...uintptr) (r1, r2 uintptr, err error) {
p.mustFind()
return p.proc.Call(a...)
}
......@@ -75,9 +75,9 @@ func StringSlicePtr(ss []string) []*byte {
func CloseOnExec(fd int) { fcntl(fd, F_SETFD, FD_CLOEXEC) }
func SetNonblock(fd int, nonblocking bool) (errno int) {
func SetNonblock(fd int, nonblocking bool) (err error) {
flag, err := fcntl(fd, F_GETFL, 0)
if err != 0 {
if err != nil {
return err
}
if nonblocking {
......@@ -90,19 +90,22 @@ func SetNonblock(fd int, nonblocking bool) (errno int) {
}
// Fork, dup fd onto 0..len(fd), and exec(argv0, argvv, envv) in child.
// If a dup or exec fails, write the errno int to pipe.
// If a dup or exec fails, write the errno error to pipe.
// (Pipe is close-on-exec so if exec succeeds, it will be closed.)
// In the child, this function must not acquire any locks, because
// they might have been locked at the time of the fork. This means
// no rescheduling, no malloc calls, and no new stack segments.
// The calls to RawSyscall are okay because they are assembly
// functions that do not grow the stack.
func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err int) {
func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) {
// Declare all variables at top in case any
// declarations require heap allocation (e.g., err1).
var r1, r2, err1 uintptr
var nextfd int
var i int
var (
r1, r2 uintptr
err1 Errno
nextfd int
i int
)
// guard against side effects of shuffling fds below.
fd := append([]int(nil), attr.Files...)
......@@ -113,7 +116,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
// No more allocation or calls of non-assembly functions.
r1, r2, err1 = RawSyscall(SYS_FORK, 0, 0, 0)
if err1 != 0 {
return 0, int(err1)
return 0, err1
}
// On Darwin:
......@@ -315,10 +318,10 @@ type SysProcAttr struct {
var zeroProcAttr ProcAttr
var zeroSysProcAttr SysProcAttr
func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err int) {
func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) {
var p [2]int
var n int
var err1 uintptr
var err1 Errno
var wstatus WaitStatus
if attr == nil {
......@@ -356,19 +359,20 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err int) {
ForkLock.Lock()
// Allocate child status pipe close on exec.
if err = Pipe(p[0:]); err != 0 {
if err = Pipe(p[0:]); err != nil {
goto error
}
if _, err = fcntl(p[0], F_SETFD, FD_CLOEXEC); err != 0 {
if _, err = fcntl(p[0], F_SETFD, FD_CLOEXEC); err != nil {
goto error
}
if _, err = fcntl(p[1], F_SETFD, FD_CLOEXEC); err != 0 {
if _, err = fcntl(p[1], F_SETFD, FD_CLOEXEC); err != nil {
goto error
}
// Kick off child.
pid, err = forkAndExecInChild(argv0p, argvp, envvp, chroot, dir, attr, sys, p[1])
if err != 0 {
pid, err1 = forkAndExecInChild(argv0p, argvp, envvp, chroot, dir, attr, sys, p[1])
if err1 != 0 {
err = Errno(err1)
goto error
}
ForkLock.Unlock()
......@@ -377,11 +381,11 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err int) {
Close(p[1])
n, err = read(p[0], (*byte)(unsafe.Pointer(&err1)), int(unsafe.Sizeof(err1)))
Close(p[0])
if err != 0 || n != 0 {
if err != nil || n != 0 {
if n == int(unsafe.Sizeof(err1)) {
err = int(err1)
err = Errno(err1)
}
if err == 0 {
if err == nil {
err = EPIPE
}
......@@ -395,7 +399,7 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err int) {
}
// Read got EOF, so pipe closed on exec, so exec succeeded.
return pid, 0
return pid, nil
error:
if p[0] >= 0 {
......@@ -407,21 +411,21 @@ error:
}
// Combination of fork and exec, careful to be thread safe.
func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err int) {
func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) {
return forkExec(argv0, argv, attr)
}
// StartProcess wraps ForkExec for package os.
func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int, err int) {
func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int, err error) {
pid, err = forkExec(argv0, argv, attr)
return pid, 0, err
}
// Ordinary exec.
func Exec(argv0 string, argv []string, envv []string) (err int) {
func Exec(argv0 string, argv []string, envv []string) (err error) {
_, _, err1 := RawSyscall(SYS_EXECVE,
uintptr(unsafe.Pointer(StringBytePtr(argv0))),
uintptr(unsafe.Pointer(&StringSlicePtr(argv)[0])),
uintptr(unsafe.Pointer(&StringSlicePtr(envv)[0])))
return int(err1)
return Errno(err1)
}
......@@ -125,47 +125,47 @@ func CloseOnExec(fd Handle) {
SetHandleInformation(Handle(fd), HANDLE_FLAG_INHERIT, 0)
}
func SetNonblock(fd Handle, nonblocking bool) (errno int) {
return 0
func SetNonblock(fd Handle, nonblocking bool) (err error) {
return nil
}
// getFullPath retrieves the full path of the specified file.
// Just a wrapper for Windows GetFullPathName api.
func getFullPath(name string) (path string, err int) {
func getFullPath(name string) (path string, err error) {
p := StringToUTF16Ptr(name)
buf := make([]uint16, 100)
n, err := GetFullPathName(p, uint32(len(buf)), &buf[0], nil)
if err != 0 {
if err != nil {
return "", err
}
if n > uint32(len(buf)) {
// Windows is asking for bigger buffer.
buf = make([]uint16, n)
n, err = GetFullPathName(p, uint32(len(buf)), &buf[0], nil)
if err != 0 {
if err != nil {
return "", err
}
if n > uint32(len(buf)) {
return "", EINVAL
}
}
return UTF16ToString(buf[:n]), 0
return UTF16ToString(buf[:n]), nil
}
func isSlash(c uint8) bool {
return c == '\\' || c == '/'
}
func normalizeDir(dir string) (name string, err int) {
func normalizeDir(dir string) (name string, err error) {
ndir, err := getFullPath(dir)
if err != 0 {
if err != nil {
return "", err
}
if len(ndir) > 2 && isSlash(ndir[0]) && isSlash(ndir[1]) {
// dir cannot have \\server\share\path form
return "", EINVAL
}
return ndir, 0
return ndir, nil
}
func volToUpper(ch int) int {
......@@ -175,13 +175,13 @@ func volToUpper(ch int) int {
return ch
}
func joinExeDirAndFName(dir, p string) (name string, err int) {
func joinExeDirAndFName(dir, p string) (name string, err error) {
if len(p) == 0 {
return "", EINVAL
}
if len(p) > 2 && isSlash(p[0]) && isSlash(p[1]) {
// \\server\share\path form
return p, 0
return p, nil
}
if len(p) > 1 && p[1] == ':' {
// has drive letter
......@@ -189,10 +189,10 @@ func joinExeDirAndFName(dir, p string) (name string, err int) {
return "", EINVAL
}
if isSlash(p[2]) {
return p, 0
return p, nil
} else {
d, err := normalizeDir(dir)
if err != 0 {
if err != nil {
return "", err
}
if volToUpper(int(p[0])) == volToUpper(int(d[0])) {
......@@ -204,7 +204,7 @@ func joinExeDirAndFName(dir, p string) (name string, err int) {
} else {
// no drive letter
d, err := normalizeDir(dir)
if err != 0 {
if err != nil {
return "", err
}
if isSlash(p[0]) {
......@@ -232,7 +232,7 @@ type SysProcAttr struct {
var zeroProcAttr ProcAttr
var zeroSysProcAttr SysProcAttr
func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int, err int) {
func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int, err error) {
if len(argv0) == 0 {
return 0, 0, EWINDOWS
}
......@@ -255,9 +255,9 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int,
// argv0 relative to the current directory, and, only once the new
// process is started, it does Chdir(attr.Dir). We are adjusting
// for that difference here by making argv0 absolute.
var err int
var err error
argv0, err = joinExeDirAndFName(attr.Dir, argv0)
if err != 0 {
if err != nil {
return 0, 0, err
}
}
......@@ -294,7 +294,7 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int,
for i := range attr.Files {
if attr.Files[i] > 0 {
err := DuplicateHandle(p, Handle(attr.Files[i]), p, &fd[i], 0, true, DUPLICATE_SAME_ACCESS)
if err != 0 {
if err != nil {
return 0, 0, err
}
defer CloseHandle(Handle(fd[i]))
......@@ -314,14 +314,14 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int,
pi := new(ProcessInformation)
err = CreateProcess(argv0p, argvp, nil, nil, true, CREATE_UNICODE_ENVIRONMENT, createEnvBlock(attr.Env), dirp, si, pi)
if err != 0 {
if err != nil {
return 0, 0, err
}
defer CloseHandle(Handle(pi.Thread))
return int(pi.ProcessId), int(pi.Process), 0
return int(pi.ProcessId), int(pi.Process), nil
}
func Exec(argv0 string, argv []string, envv []string) (err int) {
func Exec(argv0 string, argv []string, envv []string) (err error) {
return EWINDOWS
}
......@@ -18,10 +18,10 @@ func LsfJump(code, k, jt, jf int) *SockFilter {
return &SockFilter{Code: uint16(code), Jt: uint8(jt), Jf: uint8(jf), K: uint32(k)}
}
func LsfSocket(ifindex, proto int) (int, int) {
func LsfSocket(ifindex, proto int) (int, error) {
var lsall SockaddrLinklayer
s, e := Socket(AF_PACKET, SOCK_RAW, proto)
if e != 0 {
if e != nil {
return 0, e
}
p := (*[2]byte)(unsafe.Pointer(&lsall.Protocol))
......@@ -29,11 +29,11 @@ func LsfSocket(ifindex, proto int) (int, int) {
p[1] = byte(proto)
lsall.Ifindex = ifindex
e = Bind(s, &lsall)
if e != 0 {
if e != nil {
Close(s)
return 0, e
}
return s, 0
return s, nil
}
type iflags struct {
......@@ -41,17 +41,17 @@ type iflags struct {
flags uint16
}
func SetLsfPromisc(name string, m bool) int {
func SetLsfPromisc(name string, m bool) error {
s, e := Socket(AF_INET, SOCK_DGRAM, 0)
if e != 0 {
if e != nil {
return e
}
defer Close(s)
var ifl iflags
copy(ifl.name[:], []byte(name))
_, _, ep := Syscall(SYS_IOCTL, uintptr(s), SIOCGIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
if e := int(ep); e != 0 {
return e
if ep != 0 {
return Errno(ep)
}
if m {
ifl.flags |= uint16(IFF_PROMISC)
......@@ -59,20 +59,20 @@ func SetLsfPromisc(name string, m bool) int {
ifl.flags &= ^uint16(IFF_PROMISC)
}
_, _, ep = Syscall(SYS_IOCTL, uintptr(s), SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
if e := int(ep); e != 0 {
return e
if ep != 0 {
return Errno(ep)
}
return 0
return nil
}
func AttachLsf(fd int, i []SockFilter) int {
func AttachLsf(fd int, i []SockFilter) error {
var p SockFprog
p.Len = uint16(len(i))
p.Filter = (*SockFilter)(unsafe.Pointer(&i[0]))
return setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, uintptr(unsafe.Pointer(&p)), unsafe.Sizeof(p))
}
func DetachLsf(fd int) int {
func DetachLsf(fd int) error {
var dummy int
return setsockopt(fd, SOL_SOCKET, SO_DETACH_FILTER, uintptr(unsafe.Pointer(&dummy)), unsafe.Sizeof(dummy))
}
......@@ -189,10 +189,21 @@ errors=$(
sort
)
# Again, writing regexps to a file.
echo '#include <errno.h>' | $GCC -x c - -E -dM $ccflags |
awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' |
sort >_error.grep
echo '// mkerrors.sh' "$@"
echo '// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT'
echo
cgo -godefs -- "$@" _const.go
cgo -godefs -- "$@" _const.go >_error.out
cat _error.out | grep -vf _error.grep
echo
echo '// Errors'
echo 'const ('
cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= Errno(\1)/'
echo ')'
# Run C program to print error strings.
(
......@@ -250,4 +261,4 @@ main(void)
'
) >_errors.c
$GCC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go
$GCC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _error.out
......@@ -78,7 +78,7 @@ while(<>) {
next if !/^\/\/sys / && !$nonblock;
# Line must be of the form
# func Open(path string, mode int, perm int) (fd int, errno int)
# func Open(path string, mode int, perm int) (fd int, errno error)
# Split into name, in params, out params.
if(!/^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(SYS_[A-Z0-9_]+))?$/) {
print STDERR "$ARGV:$.: malformed //sys declaration\n";
......@@ -177,15 +177,17 @@ while(<>) {
# Assign return values.
my $body = "";
my @ret = ("_", "_", "_");
my $do_errno = 0;
for(my $i=0; $i<@out; $i++) {
my $p = $out[$i];
my ($name, $type) = parseparam($p);
my $reg = "";
if($name eq "errno" && !$plan9) {
if($name eq "err" && !$plan9) {
$reg = "e1";
$ret[2] = $reg;
} elsif ($name eq "err" && $plan9) {
$ret[0] = "r0";
$do_errno = 1;
} elsif($name eq "err" && $plan9) {
$ret[0] = "r0";
$ret[2] = "e1";
next;
} else {
......@@ -208,7 +210,9 @@ while(<>) {
$ret[$i] = sprintf("r%d", $i);
$ret[$i+1] = sprintf("r%d", $i+1);
}
$body .= "\t$name = $type($reg)\n";
if($reg ne "e1" || $plan9) {
$body .= "\t$name = $type($reg)\n";
}
}
if ($ret[0] eq "_" && $ret[1] eq "_" && $ret[2] eq "_") {
$text .= "\t$call\n";
......@@ -218,12 +222,14 @@ while(<>) {
$text .= $body;
if ($plan9 && $ret[2] eq "e1") {
$text .= "\terr = nil\n";
$text .= "\tif int(r0) == -1 {\n";
$text .= "\t\terr = NewError(e1)\n";
$text .= "\t\terr = e1\n";
$text .= "\t}\n";
} elsif ($do_errno) {
$text .= "\tif e1 != 0 {\n";
$text .= "\t\terr = e1;\n";
$text .= "\t}\n";
}
$text .= "\treturn\n";
$text .= "}\n\n";
}
......
......@@ -11,16 +11,16 @@
# This includes return parameters.
# * The parameter lists must give a type for each argument:
# the (x, y, z int) shorthand is not allowed.
# * If the return parameter is an error number, it must be named errno.
# * If the return parameter is an error number, it must be named err.
# * If go func name needs to be different from it's winapi dll name,
# the winapi name could be specified at the end, after "=" sign, like
# //sys LoadLibrary(libname string) (handle uint32, errno int) = LoadLibraryA
# * Each function, that returns errno, needs to supply a condition,
# //sys LoadLibrary(libname string) (handle uint32, err error) = LoadLibraryA
# * Each function that returns err needs to supply a condition,
# that return value of winapi will be tested against to
# detect failure. This would set errno to windows "last-error",
# otherwise it will be 0. The value can be provided
# detect failure. This would set err to windows "last-error",
# otherwise it will be nil. The value can be provided
# at end of //sys declaration, like
# //sys LoadLibrary(libname string) (handle uint32, errno int) [failretval==-1] = LoadLibraryA
# //sys LoadLibrary(libname string) (handle uint32, err error) [failretval==-1] = LoadLibraryA
# and is [failretval==0] by default.
use strict;
......@@ -81,7 +81,7 @@ while(<>) {
$syscalldot = "syscall." if $package ne "syscall";
# Line must be of the form
# func Open(path string, mode int, perm int) (fd int, errno int)
# func Open(path string, mode int, perm int) (fd int, err error)
# Split into name, in params, out params.
if(!/^\/\/sys (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:\[failretval(.*)\])?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$/) {
print STDERR "$ARGV:$.: malformed //sys declaration\n";
......@@ -207,7 +207,7 @@ while(<>) {
my $p = $out[$i];
my ($name, $type) = parseparam($p);
my $reg = "";
if($name eq "errno") {
if($name eq "err") {
$reg = "e1";
$ret[2] = $reg;
} else {
......@@ -238,7 +238,7 @@ while(<>) {
if($i == 0) {
if($type eq "bool") {
$failexpr = "!$name";
} elsif($name eq "errno") {
} elsif($name eq "err") {
$ret[$i] = "r1";
$failexpr = "int(r1) $failcond";
} else {
......@@ -246,16 +246,14 @@ while(<>) {
}
}
$failexpr =~ s/(=)([0-9A-Za-z\-+])/$1 $2/; # gofmt compatible
if($name eq "errno") {
# Set errno to "last error" only if returned value indicate failure
if($name eq "err") {
# Set err to "last error" only if returned value indicate failure
$body .= "\tif $failexpr {\n";
$body .= "\t\tif $reg != 0 {\n";
$body .= "\t\t\t$name = $type($reg)\n";
$body .= "\t\t} else {\n";
$body .= "\t\t\t$name = ${syscalldot}EINVAL\n";
$body .= "\t\t}\n";
$body .= "\t} else {\n";
$body .= "\t\t$name = 0\n";
$body .= "\t}\n";
} else {
$body .= "\t$name = $rettype($reg)\n";
......
......@@ -63,31 +63,28 @@ func newNetlinkRouteRequest(proto, seq, family int) []byte {
// NetlinkRIB returns routing information base, as known as RIB,
// which consists of network facility information, states and
// parameters.
func NetlinkRIB(proto, family int) ([]byte, int) {
func NetlinkRIB(proto, family int) ([]byte, error) {
var (
s int
e int
lsanl SockaddrNetlink
seq int
tab []byte
)
s, e = Socket(AF_NETLINK, SOCK_RAW, 0)
if e != 0 {
s, e := Socket(AF_NETLINK, SOCK_RAW, 0)
if e != nil {
return nil, e
}
defer Close(s)
lsanl.Family = AF_NETLINK
e = Bind(s, &lsanl)
if e != 0 {
if e != nil {
return nil, e
}
seq++
seq := 1
wb := newNetlinkRouteRequest(proto, seq, family)
e = Sendto(s, wb, 0, &lsanl)
if e != 0 {
if e != nil {
return nil, e
}
......@@ -100,7 +97,7 @@ func NetlinkRIB(proto, family int) ([]byte, int) {
rb = make([]byte, Getpagesize())
nr, _, e = Recvfrom(s, rb, 0)
if e != 0 {
if e != nil {
return nil, e
}
if nr < NLMSG_HDRLEN {
......@@ -111,7 +108,7 @@ func NetlinkRIB(proto, family int) ([]byte, int) {
msgs, _ := ParseNetlinkMessage(rb)
for _, m := range msgs {
if lsa, e = Getsockname(s); e != 0 {
if lsa, e = Getsockname(s); e != nil {
return nil, e
}
switch v := lsa.(type) {
......@@ -132,7 +129,7 @@ func NetlinkRIB(proto, family int) ([]byte, int) {
}
done:
return tab, 0
return tab, nil
}
// NetlinkMessage represents the netlink message.
......@@ -143,18 +140,18 @@ type NetlinkMessage struct {
// ParseNetlinkMessage parses buf as netlink messages and returns
// the slice containing the NetlinkMessage structs.
func ParseNetlinkMessage(buf []byte) ([]NetlinkMessage, int) {
func ParseNetlinkMessage(buf []byte) ([]NetlinkMessage, error) {
var (
h *NlMsghdr
dbuf []byte
dlen int
e int
e error
msgs []NetlinkMessage
)
for len(buf) >= NLMSG_HDRLEN {
h, dbuf, dlen, e = netlinkMessageHeaderAndData(buf)
if e != 0 {
if e != nil {
break
}
m := NetlinkMessage{}
......@@ -167,12 +164,12 @@ func ParseNetlinkMessage(buf []byte) ([]NetlinkMessage, int) {
return msgs, e
}
func netlinkMessageHeaderAndData(buf []byte) (*NlMsghdr, []byte, int, int) {
func netlinkMessageHeaderAndData(buf []byte) (*NlMsghdr, []byte, int, error) {
h := (*NlMsghdr)(unsafe.Pointer(&buf[0]))
if h.Len < NLMSG_HDRLEN || int(h.Len) > len(buf) {
return nil, nil, 0, EINVAL
}
return h, buf[NLMSG_HDRLEN:], nlmAlignOf(int(h.Len)), 0
return h, buf[NLMSG_HDRLEN:], nlmAlignOf(int(h.Len)), nil
}
// NetlinkRouteAttr represents the netlink route attribute.
......@@ -184,13 +181,13 @@ type NetlinkRouteAttr struct {
// ParseNetlinkRouteAttr parses msg's payload as netlink route
// attributes and returns the slice containing the NetlinkRouteAttr
// structs.
func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, int) {
func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, error) {
var (
buf []byte
a *RtAttr
alen int
vbuf []byte
e int
e error
attrs []NetlinkRouteAttr
)
......@@ -207,7 +204,7 @@ func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, int) {
for len(buf) >= SizeofRtAttr {
a, vbuf, alen, e = netlinkRouteAttrAndValue(buf)
if e != 0 {
if e != nil {
break
}
ra := NetlinkRouteAttr{}
......@@ -217,13 +214,13 @@ func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, int) {
buf = buf[alen:]
}
return attrs, 0
return attrs, nil
}
func netlinkRouteAttrAndValue(buf []byte) (*RtAttr, []byte, int, int) {
func netlinkRouteAttrAndValue(buf []byte) (*RtAttr, []byte, int, error) {
h := (*RtAttr)(unsafe.Pointer(&buf[0]))
if h.Len < SizeofRtAttr || int(h.Len) > len(buf) {
return nil, nil, 0, EINVAL
}
return h, buf[SizeofRtAttr:], rtaAlignOf(int(h.Len)), 0
return h, buf[SizeofRtAttr:], rtaAlignOf(int(h.Len)), nil
}
......@@ -29,29 +29,24 @@ func rsaAlignOf(salen int) int {
// RouteRIB returns routing information base, as known as RIB,
// which consists of network facility information, states and
// parameters.
func RouteRIB(facility, param int) ([]byte, int) {
var (
tab []byte
e int
)
func RouteRIB(facility, param int) ([]byte, error) {
mib := []_C_int{CTL_NET, AF_ROUTE, 0, 0, _C_int(facility), _C_int(param)}
// Find size.
n := uintptr(0)
if e = sysctl(mib, nil, &n, nil, 0); e != 0 {
return nil, e
if err := sysctl(mib, nil, &n, nil, 0); err != nil {
return nil, err
}
if n == 0 {
return nil, 0
return nil, nil
}
tab = make([]byte, n)
if e = sysctl(mib, &tab[0], &n, nil, 0); e != 0 {
return nil, e
tab := make([]byte, n)
if err := sysctl(mib, &tab[0], &n, nil, 0); err != nil {
return nil, err
}
return tab[:n], 0
return tab[:n], nil
}
// RoutingMessage represents a routing message.
......@@ -91,7 +86,7 @@ func (m *RouteMessage) sockaddr() []Sockaddr {
switch i {
case RTAX_DST, RTAX_GATEWAY:
sa, e := anyToSockaddr((*RawSockaddrAny)(unsafe.Pointer(rsa)))
if e != 0 {
if e != nil {
return nil
}
if i == RTAX_DST {
......@@ -134,7 +129,7 @@ func (m *InterfaceMessage) sockaddr() (sas []Sockaddr) {
return nil
}
sa, e := anyToSockaddr((*RawSockaddrAny)(unsafe.Pointer(&m.Data[0])))
if e != 0 {
if e != nil {
return nil
}
return append(sas, sa)
......@@ -163,7 +158,7 @@ func (m *InterfaceAddrMessage) sockaddr() (sas []Sockaddr) {
switch i {
case RTAX_IFA:
sa, e := anyToSockaddr((*RawSockaddrAny)(unsafe.Pointer(rsa)))
if e != 0 {
if e != nil {
return nil
}
sas = append(sas, sa)
......@@ -178,7 +173,7 @@ func (m *InterfaceAddrMessage) sockaddr() (sas []Sockaddr) {
// ParseRoutingMessage parses buf as routing messages and returns
// the slice containing the RoutingMessage interfaces.
func ParseRoutingMessage(buf []byte) (msgs []RoutingMessage, errno int) {
func ParseRoutingMessage(buf []byte) (msgs []RoutingMessage, err error) {
for len(buf) >= anyMessageLen {
any := (*anyMessage)(unsafe.Pointer(&buf[0]))
if any.Version != RTM_VERSION {
......@@ -187,11 +182,11 @@ func ParseRoutingMessage(buf []byte) (msgs []RoutingMessage, errno int) {
msgs = append(msgs, any.toRoutingMessage(buf))
buf = buf[any.Msglen:]
}
return msgs, 0
return msgs, nil
}
// ParseRoutingMessage parses msg's payload as raw sockaddrs and
// returns the slice containing the Sockaddr interfaces.
func ParseRoutingSockaddr(msg RoutingMessage) (sas []Sockaddr, errno int) {
return append(sas, msg.sockaddr()...), 0
func ParseRoutingSockaddr(msg RoutingMessage) (sas []Sockaddr, err error) {
return append(sas, msg.sockaddr()...), nil
}
......@@ -63,7 +63,7 @@ func (m *InterfaceMulticastAddrMessage) sockaddr() (sas []Sockaddr) {
switch i {
case RTAX_IFA:
sa, e := anyToSockaddr((*RawSockaddrAny)(unsafe.Pointer(rsa)))
if e != 0 {
if e != nil {
return nil
}
sas = append(sas, sa)
......
......@@ -63,7 +63,7 @@ func (m *InterfaceMulticastAddrMessage) sockaddr() (sas []Sockaddr) {
switch i {
case RTAX_IFA:
sa, e := anyToSockaddr((*RawSockaddrAny)(unsafe.Pointer(rsa)))
if e != 0 {
if e != nil {
return nil
}
sas = append(sas, sa)
......
......@@ -26,7 +26,7 @@ func UnixCredentials(ucred *Ucred) []byte {
// ParseUnixCredentials decodes a socket control message that contains
// credentials in a Ucred structure. To receive such a message, the
// SO_PASSCRED option must be enabled on the socket.
func ParseUnixCredentials(msg *SocketControlMessage) (*Ucred, int) {
func ParseUnixCredentials(msg *SocketControlMessage) (*Ucred, error) {
if msg.Header.Level != SOL_SOCKET {
return nil, EINVAL
}
......@@ -34,5 +34,5 @@ func ParseUnixCredentials(msg *SocketControlMessage) (*Ucred, int) {
return nil, EINVAL
}
ucred := *(*Ucred)(unsafe.Pointer(&msg.Data[0]))
return &ucred, 0
return &ucred, nil
}
......@@ -47,17 +47,17 @@ type SocketControlMessage struct {
Data []byte
}
func ParseSocketControlMessage(buf []byte) ([]SocketControlMessage, int) {
func ParseSocketControlMessage(buf []byte) ([]SocketControlMessage, error) {
var (
h *Cmsghdr
dbuf []byte
e int
e error
cmsgs []SocketControlMessage
)
for len(buf) >= CmsgLen(0) {
h, dbuf, e = socketControlMessageHeaderAndData(buf)
if e != 0 {
if e != nil {
break
}
m := SocketControlMessage{}
......@@ -70,12 +70,12 @@ func ParseSocketControlMessage(buf []byte) ([]SocketControlMessage, int) {
return cmsgs, e
}
func socketControlMessageHeaderAndData(buf []byte) (*Cmsghdr, []byte, int) {
func socketControlMessageHeaderAndData(buf []byte) (*Cmsghdr, []byte, error) {
h := (*Cmsghdr)(unsafe.Pointer(&buf[0]))
if h.Len < SizeofCmsghdr || int(h.Len) > len(buf) {
return nil, nil, EINVAL
}
return h, buf[cmsgAlignOf(SizeofCmsghdr):], 0
return h, buf[cmsgAlignOf(SizeofCmsghdr):], nil
}
// UnixRights encodes a set of open file descriptors into a socket
......@@ -99,7 +99,7 @@ func UnixRights(fds ...int) []byte {
// ParseUnixRights decodes a socket control message that contains an
// integer array of open file descriptors from another process.
func ParseUnixRights(msg *SocketControlMessage) ([]int, int) {
func ParseUnixRights(msg *SocketControlMessage) ([]int, error) {
if msg.Header.Level != SOL_SOCKET {
return nil, EINVAL
}
......@@ -111,5 +111,5 @@ func ParseUnixRights(msg *SocketControlMessage) ([]int, int) {
fds[j] = int(*(*int32)(unsafe.Pointer(&msg.Data[i])))
j++
}
return fds, 0
return fds, nil
}
......@@ -9,8 +9,9 @@
// packages rather than this one if you can.
// For details of the functions and data types in this package consult
// the manuals for the appropriate operating system.
// These calls return errno == 0 to indicate success; otherwise
// errno is an operating system error number describing the failure.
// These calls return err == nil to indicate success; otherwise
// err is an operating system error describing the failure.
// On most systems, that error has type syscall.Errno.
package syscall
// StringByteSlice returns a NUL-terminated slice of bytes
......
This diff is collapsed.
......@@ -56,22 +56,22 @@ func ParseDirent(buf []byte, max int, names []string) (consumed int, count int,
return origlen - len(buf), count, names
}
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (errno int)
func PtraceAttach(pid int) (errno int) { return ptrace(PT_ATTACH, pid, 0, 0) }
func PtraceDetach(pid int) (errno int) { return ptrace(PT_DETACH, pid, 0, 0) }
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
func PtraceAttach(pid int) (err error) { return ptrace(PT_ATTACH, pid, 0, 0) }
func PtraceDetach(pid int) (err error) { return ptrace(PT_DETACH, pid, 0, 0) }
//sysnb pipe() (r int, w int, errno int)
//sysnb pipe() (r int, w int, err error)
func Pipe(p []int) (errno int) {
func Pipe(p []int) (err error) {
if len(p) != 2 {
return EINVAL
}
p[0], p[1], errno = pipe()
p[0], p[1], err = pipe()
return
}
// TODO
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, errno int) {
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
return -1, ENOSYS
}
......@@ -79,97 +79,97 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, errno
* Wrapped
*/
//sys kill(pid int, signum int, posix int) (errno int)
//sys kill(pid int, signum int, posix int) (err error)
func Kill(pid int, signum int) (errno int) { return kill(pid, signum, 1) }
func Kill(pid int, signum int) (err error) { return kill(pid, signum, 1) }
/*
* Exposed directly
*/
//sys Access(path string, mode uint32) (errno int)
//sys Adjtime(delta *Timeval, olddelta *Timeval) (errno int)
//sys Chdir(path string) (errno int)
//sys Chflags(path string, flags int) (errno int)
//sys Chmod(path string, mode uint32) (errno int)
//sys Chown(path string, uid int, gid int) (errno int)
//sys Chroot(path string) (errno int)
//sys Close(fd int) (errno int)
//sysnb Dup(fd int) (nfd int, errno int)
//sysnb Dup2(from int, to int) (errno int)
//sys Exchangedata(path1 string, path2 string, options int) (errno int)
//sys Access(path string, mode uint32) (err error)
//sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
//sys Chdir(path string) (err error)
//sys Chflags(path string, flags int) (err error)
//sys Chmod(path string, mode uint32) (err error)
//sys Chown(path string, uid int, gid int) (err error)
//sys Chroot(path string) (err error)
//sys Close(fd int) (err error)
//sysnb Dup(fd int) (nfd int, err error)
//sysnb Dup2(from int, to int) (err error)
//sys Exchangedata(path1 string, path2 string, options int) (err error)
//sys Exit(code int)
//sys Fchdir(fd int) (errno int)
//sys Fchflags(path string, flags int) (errno int)
//sys Fchmod(fd int, mode uint32) (errno int)
//sys Fchown(fd int, uid int, gid int) (errno int)
//sys Flock(fd int, how int) (errno int)
//sys Fpathconf(fd int, name int) (val int, errno int)
//sys Fstat(fd int, stat *Stat_t) (errno int) = SYS_FSTAT64
//sys Fstatfs(fd int, stat *Statfs_t) (errno int) = SYS_FSTATFS64
//sys Fsync(fd int) (errno int)
//sys Ftruncate(fd int, length int64) (errno int)
//sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, errno int) = SYS_GETDIRENTRIES64
//sys Fchdir(fd int) (err error)
//sys Fchflags(path string, flags int) (err error)
//sys Fchmod(fd int, mode uint32) (err error)
//sys Fchown(fd int, uid int, gid int) (err error)
//sys Flock(fd int, how int) (err error)
//sys Fpathconf(fd int, name int) (val int, err error)
//sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64
//sys Fstatfs(fd int, stat *Statfs_t) (err error) = SYS_FSTATFS64
//sys Fsync(fd int) (err error)
//sys Ftruncate(fd int, length int64) (err error)
//sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) = SYS_GETDIRENTRIES64
//sys Getdtablesize() (size int)
//sysnb Getegid() (egid int)
//sysnb Geteuid() (uid int)
//sys Getfsstat(buf []Statfs_t, flags int) (n int, errno int) = SYS_GETFSSTAT64
//sys Getfsstat(buf []Statfs_t, flags int) (n int, err error) = SYS_GETFSSTAT64
//sysnb Getgid() (gid int)
//sysnb Getpgid(pid int) (pgid int, errno int)
//sysnb Getpgid(pid int) (pgid int, err error)
//sysnb Getpgrp() (pgrp int)
//sysnb Getpid() (pid int)
//sysnb Getppid() (ppid int)
//sys Getpriority(which int, who int) (prio int, errno int)
//sysnb Getrlimit(which int, lim *Rlimit) (errno int)
//sysnb Getrusage(who int, rusage *Rusage) (errno int)
//sysnb Getsid(pid int) (sid int, errno int)
//sys Getpriority(which int, who int) (prio int, err error)
//sysnb Getrlimit(which int, lim *Rlimit) (err error)
//sysnb Getrusage(who int, rusage *Rusage) (err error)
//sysnb Getsid(pid int) (sid int, err error)
//sysnb Getuid() (uid int)
//sysnb Issetugid() (tainted bool)
//sys Kqueue() (fd int, errno int)
//sys Lchown(path string, uid int, gid int) (errno int)
//sys Link(path string, link string) (errno int)
//sys Listen(s int, backlog int) (errno int)
//sys Lstat(path string, stat *Stat_t) (errno int) = SYS_LSTAT64
//sys Mkdir(path string, mode uint32) (errno int)
//sys Mkfifo(path string, mode uint32) (errno int)
//sys Mknod(path string, mode uint32, dev int) (errno int)
//sys Open(path string, mode int, perm uint32) (fd int, errno int)
//sys Pathconf(path string, name int) (val int, errno int)
//sys Pread(fd int, p []byte, offset int64) (n int, errno int)
//sys Pwrite(fd int, p []byte, offset int64) (n int, errno int)
//sys Read(fd int, p []byte) (n int, errno int)
//sys Readlink(path string, buf []byte) (n int, errno int)
//sys Rename(from string, to string) (errno int)
//sys Revoke(path string) (errno int)
//sys Rmdir(path string) (errno int)
//sys Seek(fd int, offset int64, whence int) (newoffset int64, errno int) = SYS_LSEEK
//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (errno int)
//sys Setegid(egid int) (errno int)
//sysnb Seteuid(euid int) (errno int)
//sysnb Setgid(gid int) (errno int)
//sys Setlogin(name string) (errno int)
//sysnb Setpgid(pid int, pgid int) (errno int)
//sys Setpriority(which int, who int, prio int) (errno int)
//sys Setprivexec(flag int) (errno int)
//sysnb Setregid(rgid int, egid int) (errno int)
//sysnb Setreuid(ruid int, euid int) (errno int)
//sysnb Setrlimit(which int, lim *Rlimit) (errno int)
//sysnb Setsid() (pid int, errno int)
//sysnb Settimeofday(tp *Timeval) (errno int)
//sysnb Setuid(uid int) (errno int)
//sys Stat(path string, stat *Stat_t) (errno int) = SYS_STAT64
//sys Statfs(path string, stat *Statfs_t) (errno int) = SYS_STATFS64
//sys Symlink(path string, link string) (errno int)
//sys Sync() (errno int)
//sys Truncate(path string, length int64) (errno int)
//sys Kqueue() (fd int, err error)
//sys Lchown(path string, uid int, gid int) (err error)
//sys Link(path string, link string) (err error)
//sys Listen(s int, backlog int) (err error)
//sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64
//sys Mkdir(path string, mode uint32) (err error)
//sys Mkfifo(path string, mode uint32) (err error)
//sys Mknod(path string, mode uint32, dev int) (err error)
//sys Open(path string, mode int, perm uint32) (fd int, err error)
//sys Pathconf(path string, name int) (val int, err error)
//sys Pread(fd int, p []byte, offset int64) (n int, err error)
//sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
//sys Read(fd int, p []byte) (n int, err error)
//sys Readlink(path string, buf []byte) (n int, err error)
//sys Rename(from string, to string) (err error)
//sys Revoke(path string) (err error)
//sys Rmdir(path string) (err error)
//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
//sys Setegid(egid int) (err error)
//sysnb Seteuid(euid int) (err error)
//sysnb Setgid(gid int) (err error)
//sys Setlogin(name string) (err error)
//sysnb Setpgid(pid int, pgid int) (err error)
//sys Setpriority(which int, who int, prio int) (err error)
//sys Setprivexec(flag int) (err error)
//sysnb Setregid(rgid int, egid int) (err error)
//sysnb Setreuid(ruid int, euid int) (err error)
//sysnb Setrlimit(which int, lim *Rlimit) (err error)
//sysnb Setsid() (pid int, err error)
//sysnb Settimeofday(tp *Timeval) (err error)
//sysnb Setuid(uid int) (err error)
//sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64
//sys Statfs(path string, stat *Statfs_t) (err error) = SYS_STATFS64
//sys Symlink(path string, link string) (err error)
//sys Sync() (err error)
//sys Truncate(path string, length int64) (err error)
//sys Umask(newmask int) (oldmask int)
//sys Undelete(path string) (errno int)
//sys Unlink(path string) (errno int)
//sys Unmount(path string, flags int) (errno int)
//sys Write(fd int, p []byte) (n int, errno int)
//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, errno int)
//sys munmap(addr uintptr, length uintptr) (errno int)
//sys read(fd int, buf *byte, nbuf int) (n int, errno int)
//sys write(fd int, buf *byte, nbuf int) (n int, errno int)
//sys Undelete(path string) (err error)
//sys Unlink(path string) (err error)
//sys Unmount(path string, flags int) (err error)
//sys Write(fd int, p []byte) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
//sys munmap(addr uintptr, length uintptr) (err error)
//sys read(fd int, buf *byte, nbuf int) (n int, err error)
//sys write(fd int, buf *byte, nbuf int) (n int, err error)
/*
* Unimplemented
......
......@@ -23,8 +23,8 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
return
}
//sysnb gettimeofday(tp *Timeval) (sec int32, usec int32, errno int)
func Gettimeofday(tv *Timeval) (errno int) {
//sysnb gettimeofday(tp *Timeval) (sec int32, usec int32, err error)
func Gettimeofday(tv *Timeval) (err error) {
// The tv passed to gettimeofday must be non-nil
// but is otherwise unused. The answers come back
// in the two registers.
......@@ -52,4 +52,4 @@ func (cmsg *Cmsghdr) SetLen(length int) {
cmsg.Len = uint32(length)
}
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, err uintptr) // sic
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) // sic
......@@ -23,8 +23,8 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
return
}
//sysnb gettimeofday(tp *Timeval) (sec int64, usec int32, errno int)
func Gettimeofday(tv *Timeval) (errno int) {
//sysnb gettimeofday(tp *Timeval) (sec int64, usec int32, err error)
func Gettimeofday(tv *Timeval) (err error) {
// The tv passed to gettimeofday must be non-nil
// but is otherwise unused. The answers come back
// in the two registers.
......
......@@ -56,120 +56,120 @@ func ParseDirent(buf []byte, max int, names []string) (consumed int, count int,
return origlen - len(buf), count, names
}
//sysnb pipe() (r int, w int, errno int)
//sysnb pipe() (r int, w int, err error)
func Pipe(p []int) (errno int) {
func Pipe(p []int) (err error) {
if len(p) != 2 {
return EINVAL
}
p[0], p[1], errno = pipe()
p[0], p[1], err = pipe()
return
}
// TODO
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, errno int) {
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
return -1, ENOSYS
}
func GetsockoptIPMreqn(fd, level, opt int) (*IPMreqn, int) {
func GetsockoptIPMreqn(fd, level, opt int) (*IPMreqn, error) {
var value IPMreqn
vallen := _Socklen(SizeofIPMreqn)
errno := getsockopt(fd, level, opt, uintptr(unsafe.Pointer(&value)), &vallen)
return &value, errno
}
func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (errno int) {
func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error) {
return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(mreq)), unsafe.Sizeof(*mreq))
}
/*
* Exposed directly
*/
//sys Access(path string, mode uint32) (errno int)
//sys Adjtime(delta *Timeval, olddelta *Timeval) (errno int)
//sys Chdir(path string) (errno int)
//sys Chflags(path string, flags int) (errno int)
//sys Chmod(path string, mode uint32) (errno int)
//sys Chown(path string, uid int, gid int) (errno int)
//sys Chroot(path string) (errno int)
//sys Close(fd int) (errno int)
//sysnb Dup(fd int) (nfd int, errno int)
//sysnb Dup2(from int, to int) (errno int)
//sys Access(path string, mode uint32) (err error)
//sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
//sys Chdir(path string) (err error)
//sys Chflags(path string, flags int) (err error)
//sys Chmod(path string, mode uint32) (err error)
//sys Chown(path string, uid int, gid int) (err error)
//sys Chroot(path string) (err error)
//sys Close(fd int) (err error)
//sysnb Dup(fd int) (nfd int, err error)
//sysnb Dup2(from int, to int) (err error)
//sys Exit(code int)
//sys Fchdir(fd int) (errno int)
//sys Fchflags(path string, flags int) (errno int)
//sys Fchmod(fd int, mode uint32) (errno int)
//sys Fchown(fd int, uid int, gid int) (errno int)
//sys Flock(fd int, how int) (errno int)
//sys Fpathconf(fd int, name int) (val int, errno int)
//sys Fstat(fd int, stat *Stat_t) (errno int)
//sys Fstatfs(fd int, stat *Statfs_t) (errno int)
//sys Fsync(fd int) (errno int)
//sys Ftruncate(fd int, length int64) (errno int)
//sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, errno int)
//sys Fchdir(fd int) (err error)
//sys Fchflags(path string, flags int) (err error)
//sys Fchmod(fd int, mode uint32) (err error)
//sys Fchown(fd int, uid int, gid int) (err error)
//sys Flock(fd int, how int) (err error)
//sys Fpathconf(fd int, name int) (val int, err error)
//sys Fstat(fd int, stat *Stat_t) (err error)
//sys Fstatfs(fd int, stat *Statfs_t) (err error)
//sys Fsync(fd int) (err error)
//sys Ftruncate(fd int, length int64) (err error)
//sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error)
//sys Getdtablesize() (size int)
//sysnb Getegid() (egid int)
//sysnb Geteuid() (uid int)
//sys Getfsstat(buf []Statfs_t, flags int) (n int, errno int)
//sys Getfsstat(buf []Statfs_t, flags int) (n int, err error)
//sysnb Getgid() (gid int)
//sysnb Getpgid(pid int) (pgid int, errno int)
//sysnb Getpgid(pid int) (pgid int, err error)
//sysnb Getpgrp() (pgrp int)
//sysnb Getpid() (pid int)
//sysnb Getppid() (ppid int)
//sys Getpriority(which int, who int) (prio int, errno int)
//sysnb Getrlimit(which int, lim *Rlimit) (errno int)
//sysnb Getrusage(who int, rusage *Rusage) (errno int)
//sysnb Getsid(pid int) (sid int, errno int)
//sysnb Gettimeofday(tv *Timeval) (errno int)
//sys Getpriority(which int, who int) (prio int, err error)
//sysnb Getrlimit(which int, lim *Rlimit) (err error)
//sysnb Getrusage(who int, rusage *Rusage) (err error)
//sysnb Getsid(pid int) (sid int, err error)
//sysnb Gettimeofday(tv *Timeval) (err error)
//sysnb Getuid() (uid int)
//sys Issetugid() (tainted bool)
//sys Kill(pid int, signum int) (errno int)
//sys Kqueue() (fd int, errno int)
//sys Lchown(path string, uid int, gid int) (errno int)
//sys Link(path string, link string) (errno int)
//sys Listen(s int, backlog int) (errno int)
//sys Lstat(path string, stat *Stat_t) (errno int)
//sys Mkdir(path string, mode uint32) (errno int)
//sys Mkfifo(path string, mode uint32) (errno int)
//sys Mknod(path string, mode uint32, dev int) (errno int)
//sys Nanosleep(time *Timespec, leftover *Timespec) (errno int)
//sys Open(path string, mode int, perm uint32) (fd int, errno int)
//sys Pathconf(path string, name int) (val int, errno int)
//sys Pread(fd int, p []byte, offset int64) (n int, errno int)
//sys Pwrite(fd int, p []byte, offset int64) (n int, errno int)
//sys Read(fd int, p []byte) (n int, errno int)
//sys Readlink(path string, buf []byte) (n int, errno int)
//sys Rename(from string, to string) (errno int)
//sys Revoke(path string) (errno int)
//sys Rmdir(path string) (errno int)
//sys Seek(fd int, offset int64, whence int) (newoffset int64, errno int) = SYS_LSEEK
//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (errno int)
//sysnb Setegid(egid int) (errno int)
//sysnb Seteuid(euid int) (errno int)
//sysnb Setgid(gid int) (errno int)
//sys Setlogin(name string) (errno int)
//sysnb Setpgid(pid int, pgid int) (errno int)
//sys Setpriority(which int, who int, prio int) (errno int)
//sysnb Setregid(rgid int, egid int) (errno int)
//sysnb Setreuid(ruid int, euid int) (errno int)
//sysnb Setrlimit(which int, lim *Rlimit) (errno int)
//sysnb Setsid() (pid int, errno int)
//sysnb Settimeofday(tp *Timeval) (errno int)
//sysnb Setuid(uid int) (errno int)
//sys Stat(path string, stat *Stat_t) (errno int)
//sys Statfs(path string, stat *Statfs_t) (errno int)
//sys Symlink(path string, link string) (errno int)
//sys Sync() (errno int)
//sys Truncate(path string, length int64) (errno int)
//sys Kill(pid int, signum int) (err error)
//sys Kqueue() (fd int, err error)
//sys Lchown(path string, uid int, gid int) (err error)
//sys Link(path string, link string) (err error)
//sys Listen(s int, backlog int) (err error)
//sys Lstat(path string, stat *Stat_t) (err error)
//sys Mkdir(path string, mode uint32) (err error)
//sys Mkfifo(path string, mode uint32) (err error)
//sys Mknod(path string, mode uint32, dev int) (err error)
//sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
//sys Open(path string, mode int, perm uint32) (fd int, err error)
//sys Pathconf(path string, name int) (val int, err error)
//sys Pread(fd int, p []byte, offset int64) (n int, err error)
//sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
//sys Read(fd int, p []byte) (n int, err error)
//sys Readlink(path string, buf []byte) (n int, err error)
//sys Rename(from string, to string) (err error)
//sys Revoke(path string) (err error)
//sys Rmdir(path string) (err error)
//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
//sysnb Setegid(egid int) (err error)
//sysnb Seteuid(euid int) (err error)
//sysnb Setgid(gid int) (err error)
//sys Setlogin(name string) (err error)
//sysnb Setpgid(pid int, pgid int) (err error)
//sys Setpriority(which int, who int, prio int) (err error)
//sysnb Setregid(rgid int, egid int) (err error)
//sysnb Setreuid(ruid int, euid int) (err error)
//sysnb Setrlimit(which int, lim *Rlimit) (err error)
//sysnb Setsid() (pid int, err error)
//sysnb Settimeofday(tp *Timeval) (err error)
//sysnb Setuid(uid int) (err error)
//sys Stat(path string, stat *Stat_t) (err error)
//sys Statfs(path string, stat *Statfs_t) (err error)
//sys Symlink(path string, link string) (err error)
//sys Sync() (err error)
//sys Truncate(path string, length int64) (err error)
//sys Umask(newmask int) (oldmask int)
//sys Undelete(path string) (errno int)
//sys Unlink(path string) (errno int)
//sys Unmount(path string, flags int) (errno int)
//sys Write(fd int, p []byte) (n int, errno int)
//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, errno int)
//sys munmap(addr uintptr, length uintptr) (errno int)
//sys read(fd int, buf *byte, nbuf int) (n int, errno int)
//sys write(fd int, buf *byte, nbuf int) (n int, errno int)
//sys Undelete(path string) (err error)
//sys Unlink(path string) (err error)
//sys Unmount(path string, flags int) (err error)
//sys Write(fd int, p []byte) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
//sys munmap(addr uintptr, length uintptr) (err error)
//sys read(fd int, buf *byte, nbuf int) (n int, err error)
//sys write(fd int, buf *byte, nbuf int) (n int, err error)
/*
* Unimplemented
......
......@@ -41,4 +41,4 @@ func (cmsg *Cmsghdr) SetLen(length int) {
cmsg.Len = uint32(length)
}
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, err uintptr) // sic
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) // sic
This diff is collapsed.
This diff is collapsed.
......@@ -4,59 +4,59 @@
package syscall
//sys Chown(path string, uid int, gid int) (errno int)
//sys Fchown(fd int, uid int, gid int) (errno int)
//sys Fstat(fd int, stat *Stat_t) (errno int)
//sys Fstatfs(fd int, buf *Statfs_t) (errno int)
//sys Ftruncate(fd int, length int64) (errno int)
//sys Chown(path string, uid int, gid int) (err error)
//sys Fchown(fd int, uid int, gid int) (err error)
//sys Fstat(fd int, stat *Stat_t) (err error)
//sys Fstatfs(fd int, buf *Statfs_t) (err error)
//sys Ftruncate(fd int, length int64) (err error)
//sysnb Getegid() (egid int)
//sysnb Geteuid() (euid int)
//sysnb Getgid() (gid int)
//sysnb Getuid() (uid int)
//sys Ioperm(from int, num int, on int) (errno int)
//sys Iopl(level int) (errno int)
//sys Lchown(path string, uid int, gid int) (errno int)
//sys Listen(s int, n int) (errno int)
//sys Lstat(path string, stat *Stat_t) (errno int)
//sys Pread(fd int, p []byte, offset int64) (n int, errno int) = SYS_PREAD64
//sys Pwrite(fd int, p []byte, offset int64) (n int, errno int) = SYS_PWRITE64
//sys Seek(fd int, offset int64, whence int) (off int64, errno int) = SYS_LSEEK
//sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, errno int)
//sys Sendfile(outfd int, infd int, offset *int64, count int) (written int, errno int)
//sys Setfsgid(gid int) (errno int)
//sys Setfsuid(uid int) (errno int)
//sysnb Setgid(gid int) (errno int)
//sysnb Setregid(rgid int, egid int) (errno int)
//sysnb Setresgid(rgid int, egid int, sgid int) (errno int)
//sysnb Setresuid(ruid int, euid int, suid int) (errno int)
//sysnb Setreuid(ruid int, euid int) (errno int)
//sys Shutdown(fd int, how int) (errno int)
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, errno int)
//sys Stat(path string, stat *Stat_t) (errno int)
//sys Statfs(path string, buf *Statfs_t) (errno int)
//sys SyncFileRange(fd int, off int64, n int64, flags int) (errno int)
//sys Truncate(path string, length int64) (errno int)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, errno int)
//sys bind(s int, addr uintptr, addrlen _Socklen) (errno int)
//sys connect(s int, addr uintptr, addrlen _Socklen) (errno int)
//sysnb getgroups(n int, list *_Gid_t) (nn int, errno int)
//sysnb setgroups(n int, list *_Gid_t) (errno int)
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errno int)
//sys setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int)
//sysnb socket(domain int, typ int, proto int) (fd int, errno int)
//sysnb socketpair(domain int, typ int, proto int, fd *[2]int) (errno int)
//sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
//sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, errno int)
//sys sendto(s int, buf []byte, flags int, to uintptr, addrlen _Socklen) (errno int)
//sys recvmsg(s int, msg *Msghdr, flags int) (n int, errno int)
//sys sendmsg(s int, msg *Msghdr, flags int) (errno int)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, errno int)
//sys Ioperm(from int, num int, on int) (err error)
//sys Iopl(level int) (err error)
//sys Lchown(path string, uid int, gid int) (err error)
//sys Listen(s int, n int) (err error)
//sys Lstat(path string, stat *Stat_t) (err error)
//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
//sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
//sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error)
//sys Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
//sys Setfsgid(gid int) (err error)
//sys Setfsuid(uid int) (err error)
//sysnb Setgid(gid int) (err error)
//sysnb Setregid(rgid int, egid int) (err error)
//sysnb Setresgid(rgid int, egid int, sgid int) (err error)
//sysnb Setresuid(ruid int, euid int, suid int) (err error)
//sysnb Setreuid(ruid int, euid int) (err error)
//sys Shutdown(fd int, how int) (err error)
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
//sys Stat(path string, stat *Stat_t) (err error)
//sys Statfs(path string, buf *Statfs_t) (err error)
//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
//sys Truncate(path string, length int64) (err error)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys bind(s int, addr uintptr, addrlen _Socklen) (err error)
//sys connect(s int, addr uintptr, addrlen _Socklen) (err error)
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
//sysnb setgroups(n int, list *_Gid_t) (err error)
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error)
//sys setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (err error)
//sysnb socket(domain int, typ int, proto int) (fd int, err error)
//sysnb socketpair(domain int, typ int, proto int, fd *[2]int) (err error)
//sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
//sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
//sys sendto(s int, buf []byte, flags int, to uintptr, addrlen _Socklen) (err error)
//sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys sendmsg(s int, msg *Msghdr, flags int) (err error)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
func Getpagesize() int { return 4096 }
func Gettimeofday(tv *Timeval) (errno int)
func Time(t *Time_t) (tt Time_t, errno int)
func Gettimeofday(tv *Timeval) (err error)
func Time(t *Time_t) (tt Time_t, err error)
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
......
......@@ -25,7 +25,7 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
// Pread and Pwrite are special: they insert padding before the int64.
func Pread(fd int, p []byte, offset int64) (n int, errno int) {
func Pread(fd int, p []byte, offset int64) (n int, err error) {
var _p0 unsafe.Pointer
if len(p) > 0 {
_p0 = unsafe.Pointer(&p[0])
......@@ -36,7 +36,7 @@ func Pread(fd int, p []byte, offset int64) (n int, errno int) {
return
}
func Pwrite(fd int, p []byte, offset int64) (n int, errno int) {
func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
var _p0 unsafe.Pointer
if len(p) > 0 {
_p0 = unsafe.Pointer(&p[0])
......@@ -47,7 +47,7 @@ func Pwrite(fd int, p []byte, offset int64) (n int, errno int) {
return
}
func Ftruncate(fd int, length int64) (errno int) {
func Ftruncate(fd int, length int64) (err error) {
// ARM EABI requires 64-bit arguments should be put in a pair
// of registers from an even register number.
_, _, e1 := Syscall6(SYS_FTRUNCATE64, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0)
......@@ -55,7 +55,7 @@ func Ftruncate(fd int, length int64) (errno int) {
return
}
func Truncate(path string, length int64) (errno int) {
func Truncate(path string, length int64) (err error) {
_, _, e1 := Syscall6(SYS_TRUNCATE64, uintptr(unsafe.Pointer(StringBytePtr(path))), 0, uintptr(length), uintptr(length>>32), 0, 0)
errno = int(e1)
return
......@@ -63,56 +63,56 @@ func Truncate(path string, length int64) (errno int) {
// Seek is defined in assembly.
func Seek(fd int, offset int64, whence int) (newoffset int64, errno int)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, errno int)
//sys bind(s int, addr uintptr, addrlen _Socklen) (errno int)
//sys connect(s int, addr uintptr, addrlen _Socklen) (errno int)
//sysnb getgroups(n int, list *_Gid_t) (nn int, errno int) = SYS_GETGROUPS32
//sysnb setgroups(n int, list *_Gid_t) (errno int) = SYS_SETGROUPS32
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errno int)
//sys setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int)
//sysnb socket(domain int, typ int, proto int) (fd int, errno int)
//sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
//sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, errno int)
//sys sendto(s int, buf []byte, flags int, to uintptr, addrlen _Socklen) (errno int)
//sysnb socketpair(domain int, typ int, flags int, fd *[2]int) (errno int)
//sys recvmsg(s int, msg *Msghdr, flags int) (n int, errno int)
//sys sendmsg(s int, msg *Msghdr, flags int) (errno int)
//sys Chown(path string, uid int, gid int) (errno int)
//sys Fchown(fd int, uid int, gid int) (errno int)
//sys Fstat(fd int, stat *Stat_t) (errno int) = SYS_FSTAT64
//sys Fstatfs(fd int, buf *Statfs_t) (errno int) = SYS_FSTATFS64
func Seek(fd int, offset int64, whence int) (newoffset int64, err error)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys bind(s int, addr uintptr, addrlen _Socklen) (err error)
//sys connect(s int, addr uintptr, addrlen _Socklen) (err error)
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error) = SYS_GETGROUPS32
//sysnb setgroups(n int, list *_Gid_t) (err error) = SYS_SETGROUPS32
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error)
//sys setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (err error)
//sysnb socket(domain int, typ int, proto int) (fd int, err error)
//sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
//sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
//sys sendto(s int, buf []byte, flags int, to uintptr, addrlen _Socklen) (err error)
//sysnb socketpair(domain int, typ int, flags int, fd *[2]int) (err error)
//sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys sendmsg(s int, msg *Msghdr, flags int) (err error)
//sys Chown(path string, uid int, gid int) (err error)
//sys Fchown(fd int, uid int, gid int) (err error)
//sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64
//sys Fstatfs(fd int, buf *Statfs_t) (err error) = SYS_FSTATFS64
//sysnb Getegid() (egid int)
//sysnb Geteuid() (euid int)
//sysnb Getgid() (gid int)
//sysnb Getuid() (uid int)
//sys Lchown(path string, uid int, gid int) (errno int)
//sys Listen(s int, n int) (errno int)
//sys Lstat(path string, stat *Stat_t) (errno int) = SYS_LSTAT64
//sys Sendfile(outfd int, infd int, offset *int64, count int) (written int, errno int) = SYS_SENDFILE64
//sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, errno int) = SYS__NEWSELECT
//sys Setfsgid(gid int) (errno int)
//sys Setfsuid(uid int) (errno int)
//sysnb Setgid(gid int) (errno int)
//sysnb Setregid(rgid int, egid int) (errno int)
//sysnb Setresgid(rgid int, egid int, sgid int) (errno int)
//sysnb Setresuid(ruid int, euid int, suid int) (errno int)
//sysnb Setreuid(ruid int, euid int) (errno int)
//sys Shutdown(fd int, how int) (errno int)
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, errno int)
//sys Stat(path string, stat *Stat_t) (errno int) = SYS_STAT64
//sys Statfs(path string, buf *Statfs_t) (errno int) = SYS_STATFS64
//sys Lchown(path string, uid int, gid int) (err error)
//sys Listen(s int, n int) (err error)
//sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64
//sys Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64
//sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT
//sys Setfsgid(gid int) (err error)
//sys Setfsuid(uid int) (err error)
//sysnb Setgid(gid int) (err error)
//sysnb Setregid(rgid int, egid int) (err error)
//sysnb Setresgid(rgid int, egid int, sgid int) (err error)
//sysnb Setresuid(ruid int, euid int, suid int) (err error)
//sysnb Setreuid(ruid int, euid int) (err error)
//sys Shutdown(fd int, how int) (err error)
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
//sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64
//sys Statfs(path string, buf *Statfs_t) (err error) = SYS_STATFS64
// Vsyscalls on amd64.
//sysnb Gettimeofday(tv *Timeval) (errno int)
//sysnb Time(t *Time_t) (tt Time_t, errno int)
//sysnb Gettimeofday(tv *Timeval) (err error)
//sysnb Time(t *Time_t) (tt Time_t, err error)
//sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, errno int)
//sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, errno int) {
func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
page := uintptr(offset / 4096)
if offset != int64(page)*4096 {
return 0, EINVAL
......
This diff is collapsed.
......@@ -17,11 +17,6 @@ const OS = "plan9"
const ImplementsGetwd = true
// An Error can represent any printable error condition.
type Error interface {
error
}
// ErrorString implements Error's String method by returning itself.
type ErrorString string
......
This diff is collapsed.
This diff is collapsed.
......@@ -103,10 +103,6 @@ type _Gid_t C.gid_t
// Files
const (
O_CLOEXEC = 0 // not supported
)
type Stat_t C.struct_stat64
type Statfs_t C.struct_statfs64
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -5,8 +5,8 @@ package syscall
// Go names for Windows errors.
const (
ENOENT = ERROR_FILE_NOT_FOUND
ENOTDIR = ERROR_PATH_NOT_FOUND
ENOENT Errno = ERROR_FILE_NOT_FOUND
ENOTDIR Errno = ERROR_PATH_NOT_FOUND
)
// Windows reserves errors >= 1<<29 for application use.
......@@ -14,7 +14,7 @@ const APPLICATION_ERROR = 1 << 29
// Invented values to support what package os and others expects.
const (
E2BIG = APPLICATION_ERROR + iota
E2BIG Errno = APPLICATION_ERROR + iota
EACCES
EADDRINUSE
EADDRNOTAVAIL
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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