Daily bump.
[official-gcc.git] / libgo / go / time / sys_unix.go
blob60a3ce08f906f0587c6f41e91bc6d696d1b1aab1
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.
5 // +build darwin dragonfly freebsd linux netbsd openbsd
7 package time
9 import (
10 "errors"
11 "syscall"
14 // for testing: whatever interrupts a sleep
15 func interrupt() {
16 syscall.Kill(syscall.Getpid(), syscall.SIGCHLD)
19 // readFile reads and returns the content of the named file.
20 // It is a trivial implementation of ioutil.ReadFile, reimplemented
21 // here to avoid depending on io/ioutil or os.
22 func readFile(name string) ([]byte, error) {
23 f, err := syscall.Open(name, syscall.O_RDONLY, 0)
24 if err != nil {
25 return nil, err
27 defer syscall.Close(f)
28 var (
29 buf [4096]byte
30 ret []byte
31 n int
33 for {
34 n, err = syscall.Read(f, buf[:])
35 if n > 0 {
36 ret = append(ret, buf[:n]...)
38 if n == 0 || err != nil {
39 break
42 return ret, err
45 func open(name string) (uintptr, error) {
46 fd, err := syscall.Open(name, syscall.O_RDONLY, 0)
47 if err != nil {
48 return 0, err
50 return uintptr(fd), nil
53 func closefd(fd uintptr) {
54 syscall.Close(int(fd))
57 func preadn(fd uintptr, buf []byte, off int) error {
58 whence := 0
59 if off < 0 {
60 whence = 2
62 if _, err := syscall.Seek(int(fd), int64(off), whence); err != nil {
63 return err
65 for len(buf) > 0 {
66 m, err := syscall.Read(int(fd), buf)
67 if m <= 0 {
68 if err == nil {
69 return errors.New("short read")
71 return err
73 buf = buf[m:]
75 return nil