diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-06 16:49:36 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-06 16:49:36 +0200 |
| commit | 765f4cc72c99b821f68c0108bb65aa26696b7849 (patch) | |
| tree | 9fcafc0a766363bb45cc0c2eaf990cb75d4135f4 /internal/file | |
| parent | 675f6d544e62a656581408b7dbefa2e7a4d5c92a (diff) | |
refactor: use pointer receivers for FdFile consistently (task 382)
Diffstat (limited to 'internal/file')
| -rw-r--r-- | internal/file/file.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/internal/file/file.go b/internal/file/file.go index 08e0bee..83c690a 100644 --- a/internal/file/file.go +++ b/internal/file/file.go @@ -25,8 +25,8 @@ type FdFile struct { flagsFromProcFS bool } -func NewFd(fd int32, name string, flags int32) FdFile { - f := FdFile{ +func NewFd(fd int32, name string, flags int32) *FdFile { + f := &FdFile{ fd: fd, name: name, flags: Flags(flags), @@ -37,10 +37,12 @@ func NewFd(fd int32, name string, flags int32) FdFile { return f } -func NewFdWithPid(fd int32, pid uint32) (f FdFile) { +func NewFdWithPid(fd int32, pid uint32) *FdFile { + f := &FdFile{ + fd: fd, + } var err error - f.fd = fd procPath := fmt.Sprintf("/proc/%d/fd/%d", pid, fd) f.name, err = os.Readlink(procPath) if err != nil { @@ -56,10 +58,10 @@ func NewFdWithPid(fd int32, pid uint32) (f FdFile) { return f } -func (f FdFile) Dup(fd int32) FdFile { - dupFd := f +func (f *FdFile) Dup(fd int32) *FdFile { + dupFd := *f dupFd.fd = fd - return dupFd + return &dupFd } func readFlagsFromFdInfo(fd int32, pid uint32) (Flags, error) { @@ -79,11 +81,11 @@ func readFlagsFromFdInfo(fd int32, pid uint32) (Flags, error) { return unknownFlag, scanner.Err() } -func (f FdFile) Name() string { +func (f *FdFile) Name() string { return f.name } -func (f FdFile) String() string { +func (f *FdFile) String() string { var sb strings.Builder if len(f.name) == 0 { @@ -100,11 +102,11 @@ func (f FdFile) String() string { return sb.String() } -func (f FdFile) Flags() Flags { +func (f *FdFile) Flags() Flags { return f.flags } -func (f FdFile) FD() int32 { +func (f *FdFile) FD() int32 { return f.fd } |
