go/src/internal/syscall/unix/fallocate_bsd_64bit.go
Tobias Klauser ce3f3e2ae7 cmd/link/internal/ld, internal/syscall/unix: use posix_fallocate on netbsd
The posix_fallocate system call is available since NetBSD 7.0, see
https://man.netbsd.org/posix_fallocate.2

Re-use the syscall wrappers already in place for freebsd. Note that
posix_fallocate on netbsd also returns the result in r1 rather than in
errno:

> If successful, posix_fallocate() returns zero. It returns an error on failure, without
> setting errno.

Source: https://man.netbsd.org/posix_fallocate.2#RETURN%20VALUES

Cq-Include-Trybots: luci.golang.try:gotip-netbsd-arm64
Change-Id: Iaa1f6a805d511645da7f1d2737235bfd42da3407
Reviewed-on: https://go-review.googlesource.com/c/go/+/480475
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-11 15:25:38 -07:00

20 lines
714 B
Go

// 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 (freebsd || netbsd) && (amd64 || arm64 || riscv64)
package unix
import "syscall"
func PosixFallocate(fd int, off int64, size int64) error {
// If successful, posix_fallocate() returns zero. It returns an error on failure, without
// setting errno. See https://man.freebsd.org/cgi/man.cgi?query=posix_fallocate&sektion=2&n=1
// and https://man.netbsd.org/posix_fallocate.2#RETURN%20VALUES
r1, _, _ := syscall.Syscall(posixFallocateTrap, uintptr(fd), uintptr(off), uintptr(size))
if r1 != 0 {
return syscall.Errno(r1)
}
return nil
}