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 // dupCloseOnExecOld is the traditional way to dup an fd and
17 // set its O_CLOEXEC bit, using two system calls.
18 func dupCloseOnExecOld(fd int) (int, string, error) {
19 syscall.ForkLock.RLock()
20 defer syscall.ForkLock.RUnlock()
21 newfd, err := syscall.Dup(fd)
25 syscall.CloseOnExec(newfd)
29 // Fchdir wraps syscall.Fchdir.
30 func (fd *FD) Fchdir() error {
31 if err := fd.incref(); err != nil {
35 return syscall.Fchdir(fd.Sysfd)
38 // ReadDirent wraps syscall.ReadDirent.
39 // We treat this like an ordinary system call rather than a call
40 // that tries to fill the buffer.
41 func (fd *FD) ReadDirent(buf []byte) (int, error) {
42 if err := fd.incref(); err != nil {
47 n, err := ignoringEINTRIO(syscall.ReadDirent, fd.Sysfd, buf)
50 if err == syscall.EAGAIN && fd.pd.pollable() {
51 if err = fd.pd.waitRead(fd.isFile); err == nil {
56 // Do not call eofError; caller does not expect to see io.EOF.
61 // Seek wraps syscall.Seek.
62 func (fd *FD) Seek(offset int64, whence int) (int64, error) {
63 if err := fd.incref(); err != nil {
67 return syscall.Seek(fd.Sysfd, offset, whence)