syscall: document Sendfile semantics
syscall.Sendfile behavior differs significantly between operating
systems.
Document the platform-specific behavior for the offset argument and
partial write reporting on Linux versus BSD-derived systems.
Fixes #64044
diff --git a/src/syscall/syscall_unix.go b/src/syscall/syscall_unix.go
index d957b77..323d438 100644
--- a/src/syscall/syscall_unix.go
+++ b/src/syscall/syscall_unix.go
@@ -522,6 +522,22 @@
return
}
+// Sendfile copies up to count bytes from file descriptor infd to file descriptor outfd.
+//
+// It wraps the sendfile system call. The behavior varies by operating system,
+// particularly regarding the offset argument and how partial writes are reported.
+//
+// On Linux, if offset is nil, Sendfile uses and updates the current file
+// position of infd. If offset is non-nil, the current file position is
+// unchanged, and the offset pointer is updated to reflect the bytes written.
+//
+// On BSD-derived systems (including macOS), the offset argument is not
+// updated by the system call; the caller must manually update the offset
+// using the number of bytes written. These systems may also return a
+// non-zero byte count together with an error (for example, EAGAIN).
+// On Linux, a non-nil error typically implies that no bytes were written.
+//
+// For precise semantics, see the system documentation (e.g., man 2 sendfile).
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
if race.Enabled {
race.ReleaseMerge(unsafe.Pointer(&ioSync))
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Note that for new programs we normally recommend using golang.org/x/sys/unix.Sendfile. Perhaps something like this should be done there.
// On BSD-derived systems (including macOS), the offset argument is notThis isn't very clear. Like the previous paragraph, it should explain what happens if offset is nil.
// using the number of bytes written. These systems may also return aThe bit starting with "These systems may also" should be in a different paragraph, or the Linux part should move into the preceding paragraph.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |