mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
syscall: fix a few Linux system calls
These functions claimed to return error (an interface) and be implemented entirely in assembly, but it's not possible to create an interface from assembly (at least not easily). In reality the functions were written to return an errno uintptr despite the Go prototype saying error. When the errno was 0, they coincidentally filled out a nil error by writing the 0 to the type word of the interface. If the errno was ever non-zero, the functions would create a non-nil error that would crash when trying to call err.Error(). Luckily these functions (Seek, Time, Gettimeofday) pretty much never fail, so it was all kind of working. Found by go vet. LGTM=bradfitz, r R=golang-codereviews, bradfitz, r CC=golang-codereviews https://golang.org/cl/99320043
This commit is contained in:
parent
d1f627f2f3
commit
bf68f6623a
7 changed files with 56 additions and 16 deletions
|
|
@ -135,7 +135,15 @@ func Setrlimit(resource int, rlim *Rlimit) (err error) {
|
|||
|
||||
// Underlying system call writes to newoffset via pointer.
|
||||
// Implemented in assembly to avoid allocation.
|
||||
func Seek(fd int, offset int64, whence int) (newoffset int64, err error)
|
||||
func seek(fd int, offset int64, whence int) (newoffset int64, err Errno)
|
||||
|
||||
func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
|
||||
newoffset, errno := seek(fd, offset, whence)
|
||||
if errno != 0 {
|
||||
return 0, errno
|
||||
}
|
||||
return newoffset, nil
|
||||
}
|
||||
|
||||
// Vsyscalls on amd64.
|
||||
//sysnb Gettimeofday(tv *Timeval) (err error)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue