src/os: implement os.File.Fd() method

This commits adds a OS-specific `Fd()` function for `file_anyos.go` and
`file_other.go`, which returns a uintptr to the underlying file
descriptor.
This commit is contained in:
ZauberNerd
2022-03-04 15:44:55 +00:00
committed by Ron Evans
parent 4a98db4c86
commit 486b99961d
3 changed files with 19 additions and 1 deletions
+11 -1
View File
@@ -179,9 +179,19 @@ func (f *File) SyscallConn() (syscall.RawConn, error) {
return nil, ErrNotImplemented
}
// fd is an internal interface that is used to try a type assertion in order to
// call the Fd() method of the underlying file handle if it is implemented.
type fd interface {
Fd() uintptr
}
// Fd returns the file handle referencing the open file.
func (f *File) Fd() uintptr {
panic("unimplemented: os.file.Fd()")
handle, ok := f.handle.(fd)
if ok {
return handle.Fd()
}
return 0
}
// Truncate is a stub, not yet implemented