Skip to content

Commit 1cdd9b4

Browse files
committed
os: document that users of Fd should keep f alive
Fixes #9046. LGTM=r R=r CC=golang-codereviews https://golang.org/cl/162680043
1 parent 23ecad0 commit 1cdd9b4

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

src/os/file_plan9.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ type file struct {
2525
dirinfo *dirInfo // nil unless directory being read
2626
}
2727

28-
// Fd returns the integer Unix file descriptor referencing the open file.
28+
// Fd returns the integer Plan 9 file descriptor referencing the open file.
29+
// The file descriptor is valid only until f.Close is called or f is garbage collected.
2930
func (f *File) Fd() uintptr {
3031
if f == nil {
3132
return ^(uintptr(0))

src/os/file_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type file struct {
2929
}
3030

3131
// Fd returns the integer Unix file descriptor referencing the open file.
32+
// The file descriptor is valid only until f.Close is called or f is garbage collected.
3233
func (f *File) Fd() uintptr {
3334
if f == nil {
3435
return ^(uintptr(0))

src/os/file_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type file struct {
3636
}
3737

3838
// Fd returns the Windows handle referencing the open file.
39+
// The handle is valid only until f.Close is called or f is garbage collected.
3940
func (file *File) Fd() uintptr {
4041
if file == nil {
4142
return uintptr(syscall.InvalidHandle)

0 commit comments

Comments
 (0)