aboutsummaryrefslogtreecommitdiff
path: root/misc/open_file.go
diff options
context:
space:
mode:
Diffstat (limited to 'misc/open_file.go')
-rw-r--r--misc/open_file.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/misc/open_file.go b/misc/open_file.go
index 945d78b..07ac1b8 100644
--- a/misc/open_file.go
+++ b/misc/open_file.go
@@ -8,26 +8,26 @@ import (
"syscall"
)
-type Dir_t struct {
+type Dir struct {
fd int
name string
}
var (
- Err_illegal_filename = errors.New("illegal filename")
- Err_invalid_file_descriptor = errors.New("invalid file descriptor")
+ ErrIllegalFilename = errors.New("illegal filename")
+ ErrInvalidFD = errors.New("invalid file descriptor")
)
// Open a file at exactly the given directory.
-func Open_file_at(dir Dir_t, filename string, flags int, perms os.FileMode) (*os.File, error) {
+func OpenFileAt(dir Dir, filename string, flags int, perms os.FileMode) (*os.File, error) {
if strings.IndexByte(filename, '/') != -1 {
- return nil, Err_illegal_filename
+ return nil, ErrIllegalFilename
}
- return Open_file_beneath(dir, filename, flags, perms)
+ return OpenFileBeneath(dir, filename, flags, perms)
}
// Open a file at or beneath the given directory.
-func Open_file_beneath(dir Dir_t, filename string, flags int, perms os.FileMode) (*os.File, error) {
+func OpenFileBeneath(dir Dir, filename string, flags int, perms os.FileMode) (*os.File, error) {
fd, err := Openat2(dir.fd, filename, &Open_how_t{
Flags: uint64(flags) | syscall.O_CLOEXEC,
Mode: uint64(syscallMode(perms)),
@@ -38,7 +38,7 @@ func Open_file_beneath(dir Dir_t, filename string, flags int, perms os.FileMode)
}
file := os.NewFile(uintptr(fd), path.Join(dir.name, filename))
if file == nil {
- return nil, Err_invalid_file_descriptor
+ return nil, ErrInvalidFD
} else {
return file, nil
}
@@ -46,13 +46,13 @@ func Open_file_beneath(dir Dir_t, filename string, flags int, perms os.FileMode)
// Open a directory as read-only and return a Dir_t to it. The caller is
// responsible for closing the directory with [Close_directory].
-func Open_directory_readonly(path string) (Dir_t, error) {
+func Open_directory_readonly(path string) (Dir, error) {
_fd, err := syscall.Open(path, syscall.O_RDONLY|syscall.O_DIRECTORY|syscall.O_CLOEXEC, 0)
- return Dir_t{fd: _fd, name: path}, err
+ return Dir{fd: _fd, name: path}, err
}
// Close a directory returned by [Open_directory_readonly].
-func (dir *Dir_t) Close() error {
+func (dir *Dir) Close() error {
return syscall.Close(dir.fd)
}