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
14 // for testing: whatever interrupts a sleep
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)
27 defer syscall
.Close(f
)
34 n
, err
= syscall
.Read(f
, buf
[:])
36 ret
= append(ret
, buf
[:n
]...)
38 if n
== 0 || err
!= nil {
45 func open(name
string) (uintptr, error
) {
46 fd
, err
:= syscall
.Open(name
, syscall
.O_RDONLY
, 0)
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
{
62 if _
, err
:= syscall
.Seek(int(fd
), int64(off
), whence
); err
!= nil {
66 m
, err
:= syscall
.Read(int(fd
), buf
)
69 return errors
.New("short read")