github.com/comwrg/go/src@v0.0.0-20220319063731-c238d0440370/time/sys_plan9.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build plan9 6 // +build plan9 7 8 package time 9 10 import ( 11 "errors" 12 "syscall" 13 ) 14 15 // for testing: whatever interrupts a sleep 16 func interrupt() { 17 // cannot predict pid, don't want to kill group 18 } 19 20 func open(name string) (uintptr, error) { 21 fd, err := syscall.Open(name, syscall.O_RDONLY) 22 if err != nil { 23 return 0, err 24 } 25 return uintptr(fd), nil 26 } 27 28 func read(fd uintptr, buf []byte) (int, error) { 29 return syscall.Read(int(fd), buf) 30 } 31 32 func closefd(fd uintptr) { 33 syscall.Close(int(fd)) 34 } 35 36 func preadn(fd uintptr, buf []byte, off int) error { 37 whence := seekStart 38 if off < 0 { 39 whence = seekEnd 40 } 41 if _, err := syscall.Seek(int(fd), int64(off), whence); err != nil { 42 return err 43 } 44 for len(buf) > 0 { 45 m, err := syscall.Read(int(fd), buf) 46 if m <= 0 { 47 if err == nil { 48 return errors.New("short read") 49 } 50 return err 51 } 52 buf = buf[m:] 53 } 54 return nil 55 }