internal/poll, internal/syscall/unix, net: move and export fcntl syscall wrapper

This will allow to use the fcntl syscall in packages other than
internal/poll.

For #60181

Change-Id: I76703766a655f2343c61dad95faf81aad58e007f
Reviewed-on: https://go-review.googlesource.com/c/go/+/494916
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Tobias Klauser 2023-05-17 09:57:34 +02:00 committed by Gopher Robot
parent 6ed8474317
commit 27906bb74a
14 changed files with 52 additions and 142 deletions

View file

@ -0,0 +1,25 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build unix
package unix
import (
"syscall"
_ "unsafe" // for go:linkname
)
// Implemented in the runtime package.
//
//go:linkname fcntl runtime.fcntl
func fcntl(fd int32, cmd int32, arg int32) int32
func Fcntl(fd int, cmd int, arg int) (int, error) {
val := fcntl(int32(fd), int32(cmd), int32(arg))
if val < 0 {
return 0, syscall.Errno(-val)
}
return int(val), nil
}