diff options
Diffstat (limited to 'pkg/fd')
-rw-r--r-- | pkg/fd/fd.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/fd/fd.go b/pkg/fd/fd.go index a2edf2aa6..d40758c22 100644 --- a/pkg/fd/fd.go +++ b/pkg/fd/fd.go @@ -167,6 +167,24 @@ func NewFromFile(file *os.File) (*FD, error) { return New(fd), nil } +// Open is equivallent to open(2). +func Open(path string, openmode int, perm uint32) (*FD, error) { + f, err := syscall.Open(path, openmode|syscall.O_LARGEFILE, perm) + if err != nil { + return nil, err + } + return New(f), nil +} + +// OpenAt is equivallent to openat(2). +func OpenAt(dir *FD, path string, flags int, mode uint32) (*FD, error) { + f, err := syscall.Openat(dir.FD(), path, flags, mode) + if err != nil { + return nil, err + } + return New(f), nil +} + // Close closes the file descriptor contained in the FD. // // Close is safe to call multiple times, but will return an error after the |