Skip to content

Commit e2217df

Browse files
committed
os: add FileHandle.SysHandle()
1 parent fcd8835 commit e2217df

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

src/os/file.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ func (f *File) Truncate(size int64) error {
180180
return &PathError{"truncate", f.name, ErrNotImplemented}
181181
}
182182

183+
// SysHandle returns the underlying system filehandle, if any.
184+
// (Upstream doesn't need this, as it indirects File to system-specific file.)
185+
// return value should be syscallFd, but that's private.
186+
func (f *File) SysHandle() uintptr {
187+
return f.handle.SysHandle()
188+
}
189+
183190
// PathError records an error and the operation and file path that caused it.
184191
// TODO: PathError moved to io/fs in go 1.16 and left an alias in os/errors.go.
185192
// Do the same once we drop support for go 1.15.

src/os/file_other.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ func (f stdioFileHandle) Close() error {
5050
return ErrUnsupported
5151
}
5252

53+
// SysHandle returns the underlying system filehandle, if any.
54+
func (f stdioFileHandle) SysHandle() uintptr {
55+
return uintptr(f)
56+
}
57+
5358
//go:linkname putchar runtime.putchar
5459
func putchar(c byte)
5560

src/os/file_unix.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,8 @@ func (f unixFileHandle) ReadAt(b []byte, offset int64) (n int, err error) {
5555
}
5656
return
5757
}
58+
59+
// SysHandle returns the underlying system filehandle, if any.
60+
func (f unixFileHandle) SysHandle() uintptr {
61+
return uintptr(f)
62+
}

src/os/file_windows.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func (f unixFileHandle) ReadAt(b []byte, offset int64) (n int, err error) {
5757
return -1, ErrNotImplemented
5858
}
5959

60+
// SysHandle returns the underlying system filehandle, if any.
61+
func (f unixFileHandle) SysHandle() uintptr {
62+
return uintptr(f)
63+
}
64+
6065
// isWindowsNulName reports whether name is os.DevNull ('NUL') on Windows.
6166
// True is returned if name is 'NUL' whatever the case.
6267
func isWindowsNulName(name string) bool {

src/os/filesystem.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ type FileHandle interface {
5454

5555
// Close closes the file, making it unusable for further writes.
5656
Close() (err error)
57+
58+
// SysHandle returns the underlying system filehandle, if any.
59+
SysHandle() uintptr
5760
}
5861

5962
// findMount returns the appropriate (mounted) filesystem to use for a given

0 commit comments

Comments
 (0)