1 // Copyright 2023 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 //go:build unix || (js && wasm)
13 iovecs *[]syscall.Iovec
16 func (s *SysFile) init() {}
18 func (s *SysFile) destroy(fd int) error {
19 // We don't use ignoringEINTR here because POSIX does not define
20 // whether the descriptor is closed if close returns EINTR.
21 // If the descriptor is indeed closed, using a loop would race
22 // with some other goroutine opening a new descriptor.
23 // (The Linux kernel guarantees that it is closed on an EINTR error.)
27 // dupCloseOnExecOld is the traditional way to dup an fd and
28 // set its O_CLOEXEC bit, using two system calls.
29 func dupCloseOnExecOld(fd int) (int, string, error) {
30 syscall.ForkLock.RLock()
31 defer syscall.ForkLock.RUnlock()
32 newfd, err := syscall.Dup(fd)
36 syscall.CloseOnExec(newfd)
40 // Fchdir wraps syscall.Fchdir.
41 func (fd *FD) Fchdir() error {
42 if err := fd.incref(); err != nil {
46 return syscall.Fchdir(fd.Sysfd)
49 // ReadDirent wraps syscall.ReadDirent.
50 // We treat this like an ordinary system call rather than a call
51 // that tries to fill the buffer.
52 func (fd *FD) ReadDirent(buf []byte) (int, error) {
53 if err := fd.incref(); err != nil {
58 n, err := ignoringEINTRIO(syscall.ReadDirent, fd.Sysfd, buf)
61 if err == syscall.EAGAIN && fd.pd.pollable() {
62 if err = fd.pd.waitRead(fd.isFile); err == nil {
67 // Do not call eofError; caller does not expect to see io.EOF.
72 // Seek wraps syscall.Seek.
73 func (fd *FD) Seek(offset int64, whence int) (int64, error) {
74 if err := fd.incref(); err != nil {
78 return syscall.Seek(fd.Sysfd, offset, whence)