Codebase list golang-github-cloudflare-tableflip / 724e2184-6ad7-4e39-91db-eea6f8ca0719/upstream/1.2.3 dup_fd.go
724e2184-6ad7-4e39-91db-eea6f8ca0719/upstream/1.2.3

Tree @724e2184-6ad7-4e39-91db-eea6f8ca0719/upstream/1.2.3 (Download .tar.gz)

dup_fd.go @724e2184-6ad7-4e39-91db-eea6f8ca0719/upstream/1.2.3raw · history · blame

//go:build !windows
// +build !windows

package tableflip

import (
	"fmt"
	"syscall"
)

func dupFd(fd uintptr, name fileName) (*file, error) {
	dupfd, _, errno := syscall.Syscall(syscall.SYS_FCNTL, fd, syscall.F_DUPFD_CLOEXEC, 0)
	if errno != 0 {
		return nil, fmt.Errorf("can't dup fd using fcntl: %s", errno)
	}

	return newFile(dupfd, name), nil
}