...

Source file src/time/sys_plan9.go

Documentation: time

     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  
     7  package time
     8  
     9  import (
    10  	"errors"
    11  	"syscall"
    12  )
    13  
    14  // for testing: whatever interrupts a sleep
    15  func interrupt() {
    16  	// cannot predict pid, don't want to kill group
    17  }
    18  
    19  func open(name string) (uintptr, error) {
    20  	fd, err := syscall.Open(name, syscall.O_RDONLY)
    21  	if err != nil {
    22  		return 0, err
    23  	}
    24  	return uintptr(fd), nil
    25  }
    26  
    27  func read(fd uintptr, buf []byte) (int, error) {
    28  	return syscall.Read(int(fd), buf)
    29  }
    30  
    31  func closefd(fd uintptr) {
    32  	syscall.Close(int(fd))
    33  }
    34  
    35  func preadn(fd uintptr, buf []byte, off int) error {
    36  	whence := seekStart
    37  	if off < 0 {
    38  		whence = seekEnd
    39  	}
    40  	if _, err := syscall.Seek(int(fd), int64(off), whence); err != nil {
    41  		return err
    42  	}
    43  	for len(buf) > 0 {
    44  		m, err := syscall.Read(int(fd), buf)
    45  		if m <= 0 {
    46  			if err == nil {
    47  				return errors.New("short read")
    48  			}
    49  			return err
    50  		}
    51  		buf = buf[m:]
    52  	}
    53  	return nil
    54  }
    55  

View as plain text