1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:24:40 -07:00

syscall, os, time: fix Plan 9 build

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5371092
This commit is contained in:
Lucio De Re 2011-11-16 17:37:54 -05:00 committed by Russ Cox
parent 8fdd6c05b1
commit 087a34869a
7 changed files with 53 additions and 58 deletions

View File

@ -24,7 +24,7 @@ func (e *SyscallError) Error() string { return e.Syscall + ": " + e.Err }
// NewSyscallError returns, as an error, a new SyscallError
// with the given system call name and error details.
// As a convenience, if err is nil, NewSyscallError returns nil.
func NewSyscallError(syscall string, err syscall.Error) error {
func NewSyscallError(syscall string, err error) error {
if err == nil {
return nil
}

View File

@ -64,7 +64,7 @@ const DevNull = "/dev/null"
func OpenFile(name string, flag int, perm uint32) (file *File, err error) {
var (
fd int
e syscall.Error
e error
create bool
excl bool
trunc bool
@ -93,7 +93,7 @@ func OpenFile(name string, flag int, perm uint32) (file *File, err error) {
} else {
fd, e = syscall.Open(name, flag)
if e != nil && create {
var e1 syscall.Error
var e1 error
fd, e1 = syscall.Create(name, flag, perm)
if e1 == nil {
e = nil
@ -199,26 +199,26 @@ func (f *File) Sync() (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 syscall.Error) {
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 nil.
func (f *File) pread(b []byte, off int64) (n int, err syscall.Error) {
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 syscall.Error) {
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 syscall.Error) {
func (f *File) pwrite(b []byte, off int64) (n int, err error) {
return syscall.Pwrite(f.fd, b, off)
}
@ -226,7 +226,7 @@ func (f *File) pwrite(b []byte, off int64) (n int, err syscall.Error) {
// 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 syscall.Error) {
func (f *File) seek(offset int64, whence int) (ret int64, err error) {
return syscall.Seek(f.fd, offset, whence)
}

View File

@ -34,7 +34,7 @@ func dirstat(arg interface{}) (d *Dir, err error) {
buf := make([]byte, nd)
var n int
var e syscall.Error
var e error
switch syscallArg := arg.(type) {
case *File:

View File

@ -85,7 +85,7 @@ func gstring(b []byte) (string, []byte) {
}
// readdirnames returns the names of files inside the directory represented by dirfd.
func readdirnames(dirfd int) (names []string, err Error) {
func readdirnames(dirfd int) (names []string, err error) {
result := make([]string, 0, 100)
var buf [STATMAX]byte
@ -117,7 +117,7 @@ func readdirnames(dirfd int) (names []string, err Error) {
// readdupdevice returns a list of currently opened fds (excluding stdin, stdout, stderr) from the dup device #d.
// ForkLock should be write locked before calling, so that no new fds would be created while the fd list is being read.
func readdupdevice() (fds []int, err Error) {
func readdupdevice() (fds []int, err error) {
dupdevfd, err := Open("#d", O_RDONLY)
if err != nil {
@ -169,7 +169,7 @@ func init() {
// 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 []*byte, envv []envItem, dir *byte, attr *ProcAttr, fdsToClose []int, pipe int, rflag int) (pid int, err Error) {
func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, attr *ProcAttr, fdsToClose []int, pipe int, rflag int) (pid int, err error) {
// Declare all variables at top in case any
// declarations require heap allocation (e.g., errbuf).
var (
@ -314,7 +314,7 @@ childerror:
panic("unreached")
}
func cexecPipe(p []int) Error {
func cexecPipe(p []int) error {
e := Pipe(p)
if e != nil {
return e
@ -351,7 +351,7 @@ type SysProcAttr struct {
var zeroProcAttr ProcAttr
var zeroSysProcAttr SysProcAttr
func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err Error) {
func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) {
var (
p [2]int
n int
@ -478,18 +478,18 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err Error)
}
// Combination of fork and exec, careful to be thread safe.
func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err Error) {
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 Error) {
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 Error) {
func Exec(argv0 string, argv []string, envv []string) (err error) {
if envv != nil {
r1, _, _ := RawSyscall(SYS_RFORK, RFCENVG, 0, 0)
if int(r1) == -1 {

View File

@ -23,7 +23,7 @@ type ErrorString string
func (e ErrorString) Error() string { return string(e) }
// NewError converts s to an ErrorString, which satisfies the Error interface.
func NewError(s string) Error { return ErrorString(s) }
func NewError(s string) error { return ErrorString(s) }
var (
Stdin = 0
@ -89,7 +89,7 @@ func Exit(code int) {
Exits(&msg)
}
func readnum(path string) (uint, Error) {
func readnum(path string) (uint, error) {
var b [12]byte
fd, e := Open(path, O_RDONLY)
@ -121,15 +121,15 @@ func Getppid() (ppid int) {
return int(n)
}
func Read(fd int, p []byte) (n int, err Error) {
func Read(fd int, p []byte) (n int, err error) {
return Pread(fd, p, -1)
}
func Write(fd int, p []byte) (n int, err Error) {
func Write(fd int, p []byte) (n int, err error) {
return Pwrite(fd, p, -1)
}
func Getwd() (wd string, err Error) {
func Getwd() (wd string, err error) {
fd, e := Open(".", O_RDONLY)
if e != nil {
@ -140,8 +140,8 @@ func Getwd() (wd string, err Error) {
return Fd2path(fd)
}
//sys fd2path(fd int, buf []byte) (err Error)
func Fd2path(fd int) (path string, err Error) {
//sys fd2path(fd int, buf []byte) (err error)
func Fd2path(fd int) (path string, err error) {
var buf [512]byte
e := fd2path(fd, buf[:])
@ -151,8 +151,8 @@ func Fd2path(fd int) (path string, err Error) {
return cstring(buf[:]), nil
}
//sys pipe(p *[2]_C_int) (err Error)
func Pipe(p []int) (err Error) {
//sys pipe(p *[2]_C_int) (err error)
func Pipe(p []int) (err error) {
if len(p) != 2 {
return NewError("bad arg in system call")
}
@ -167,7 +167,7 @@ func Pipe(p []int) (err Error) {
// Implemented in assembly to avoid allocation.
func seek(placeholder uintptr, fd int, offset int64, whence int) (newoffset int64, err string)
func Seek(fd int, offset int64, whence int) (newoffset int64, err Error) {
func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
newoffset, e := seek(0, fd, offset, whence)
err = nil
@ -177,7 +177,7 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, err Error) {
return
}
func Mkdir(path string, mode uint32) (err Error) {
func Mkdir(path string, mode uint32) (err error) {
fd, err := Create(path, O_RDONLY, DMDIR|mode)
if fd != -1 {
@ -204,8 +204,8 @@ func (w Waitmsg) ExitStatus() int {
return 1
}
//sys await(s []byte) (n int, err Error)
func Await(w *Waitmsg) (err Error) {
//sys await(s []byte) (n int, err error)
func Await(w *Waitmsg) (err error) {
var buf [512]byte
var f [5][]byte
@ -242,7 +242,7 @@ func Await(w *Waitmsg) (err Error) {
return
}
func Unmount(name, old string) (err Error) {
func Unmount(name, old string) (err error) {
oldp := uintptr(unsafe.Pointer(StringBytePtr(old)))
var r0 uintptr
@ -262,7 +262,7 @@ func Unmount(name, old string) (err Error) {
return
}
func Fchdir(fd int) (err Error) {
func Fchdir(fd int) (err error) {
path, err := Fd2path(fd)
if err != nil {
@ -284,7 +284,7 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
return
}
func DecodeBintime(b []byte) (nsec int64, err Error) {
func DecodeBintime(b []byte) (nsec int64, err error) {
if len(b) != 8 {
return -1, NewError("bad /dev/bintime format")
}
@ -300,7 +300,7 @@ func DecodeBintime(b []byte) (nsec int64, err Error) {
return
}
func Gettimeofday(tv *Timeval) (err Error) {
func Gettimeofday(tv *Timeval) (err error) {
// TODO(paulzhol):
// avoid reopening a file descriptor for /dev/bintime on each call,
// use lower-level calls to avoid allocation.
@ -331,7 +331,7 @@ func Geteuid() (euid int) { return -1 }
func Getgid() (gid int) { return -1 }
func Getuid() (uid int) { return -1 }
func Getgroups() (gids []int, err Error) {
func Getgroups() (gids []int, err error) {
return make([]int, 0), nil
}

View File

@ -14,7 +14,7 @@ func exits(msg *byte) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func fd2path(fd int, buf []byte) (err Error) {
func fd2path(fd int, buf []byte) (err error) {
var _p0 unsafe.Pointer
if len(buf) > 0 {
_p0 = unsafe.Pointer(&buf[0])
@ -31,7 +31,7 @@ func fd2path(fd int, buf []byte) (err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func pipe(p *[2]_C_int) (err Error) {
func pipe(p *[2]_C_int) (err error) {
r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
err = nil
if int(r0) == -1 {
@ -42,7 +42,7 @@ func pipe(p *[2]_C_int) (err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func sleep(millisecs int32) (err Error) {
func sleep(millisecs int32) (err error) {
r0, _, e1 := Syscall(SYS_SLEEP, uintptr(millisecs), 0, 0)
err = nil
if int(r0) == -1 {
@ -53,7 +53,7 @@ func sleep(millisecs int32) (err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func await(s []byte) (n int, err Error) {
func await(s []byte) (n int, err error) {
var _p0 unsafe.Pointer
if len(s) > 0 {
_p0 = unsafe.Pointer(&s[0])
@ -71,7 +71,7 @@ func await(s []byte) (n int, err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Dup(oldfd int, newfd int) (fd int, err Error) {
func Dup(oldfd int, newfd int) (fd int, err error) {
r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
fd = int(r0)
err = nil
@ -83,7 +83,7 @@ func Dup(oldfd int, newfd int) (fd int, err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Open(path string, mode int) (fd int, err Error) {
func Open(path string, mode int) (fd int, err error) {
r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(mode), 0)
fd = int(r0)
err = nil
@ -95,7 +95,7 @@ func Open(path string, mode int) (fd int, err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Create(path string, mode int, perm uint32) (fd int, err Error) {
func Create(path string, mode int, perm uint32) (fd int, err error) {
r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(mode), uintptr(perm))
fd = int(r0)
err = nil
@ -107,7 +107,7 @@ func Create(path string, mode int, perm uint32) (fd int, err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Remove(path string) (err Error) {
func Remove(path string) (err error) {
r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(StringBytePtr(path))), 0, 0)
err = nil
if int(r0) == -1 {
@ -118,7 +118,7 @@ func Remove(path string) (err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Pread(fd int, p []byte, offset int64) (n int, err Error) {
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])
@ -136,7 +136,7 @@ func Pread(fd int, p []byte, offset int64) (n int, err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Pwrite(fd int, p []byte, offset int64) (n int, err Error) {
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])
@ -154,7 +154,7 @@ func Pwrite(fd int, p []byte, offset int64) (n int, err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Close(fd int) (err Error) {
func Close(fd int) (err error) {
r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
err = nil
if int(r0) == -1 {
@ -165,7 +165,7 @@ func Close(fd int) (err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Chdir(path string) (err Error) {
func Chdir(path string) (err error) {
r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(StringBytePtr(path))), 0, 0)
err = nil
if int(r0) == -1 {
@ -176,7 +176,7 @@ func Chdir(path string) (err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Bind(name string, old string, flag int) (err Error) {
func Bind(name string, old string, flag int) (err error) {
r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(StringBytePtr(name))), uintptr(unsafe.Pointer(StringBytePtr(old))), uintptr(flag))
err = nil
if int(r0) == -1 {
@ -187,7 +187,7 @@ func Bind(name string, old string, flag int) (err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Mount(fd int, afd int, old string, flag int, aname string) (err Error) {
func Mount(fd int, afd int, old string, flag int, aname string) (err error) {
r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(StringBytePtr(old))), uintptr(flag), uintptr(unsafe.Pointer(StringBytePtr(aname))), 0)
err = nil
if int(r0) == -1 {
@ -198,7 +198,7 @@ func Mount(fd int, afd int, old string, flag int, aname string) (err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Stat(path string, edir []byte) (n int, err Error) {
func Stat(path string, edir []byte) (n int, err error) {
var _p0 unsafe.Pointer
if len(edir) > 0 {
_p0 = unsafe.Pointer(&edir[0])
@ -216,7 +216,7 @@ func Stat(path string, edir []byte) (n int, err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Fstat(fd int, edir []byte) (n int, err Error) {
func Fstat(fd int, edir []byte) (n int, err error) {
var _p0 unsafe.Pointer
if len(edir) > 0 {
_p0 = unsafe.Pointer(&edir[0])
@ -234,7 +234,7 @@ func Fstat(fd int, edir []byte) (n int, err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Wstat(path string, edir []byte) (err Error) {
func Wstat(path string, edir []byte) (err error) {
var _p0 unsafe.Pointer
if len(edir) > 0 {
_p0 = unsafe.Pointer(&edir[0])
@ -251,7 +251,7 @@ func Wstat(path string, edir []byte) (err Error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Fwstat(fd int, edir []byte) (err Error) {
func Fwstat(fd int, edir []byte) (err error) {
var _p0 unsafe.Pointer
if len(edir) > 0 {
_p0 = unsafe.Pointer(&edir[0])

View File

@ -4,11 +4,6 @@
package time
import (
"os"
"syscall"
)
// for testing: whatever interrupts a sleep
func interrupt() {
// cannot predict pid, don't want to kill group