aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--misc/errors.go4
-rw-r--r--misc/misc.go16
-rw-r--r--misc/open_file.go22
-rw-r--r--misc/openat2.go2
-rw-r--r--misc/path.go2
5 files changed, 23 insertions, 23 deletions
diff --git a/misc/errors.go b/misc/errors.go
index 8434637..190f8ba 100644
--- a/misc/errors.go
+++ b/misc/errors.go
@@ -2,11 +2,11 @@ package misc
import "fmt"
-func Wrap_one_error(a error, b error) error {
+func WrapOneError(a error, b error) error {
return fmt.Errorf("%w: %w", a, b)
}
-func First_or_panic[T any](v T, err error) T {
+func FirstOrPanic[T any](v T, err error) T {
if err != nil {
panic(err)
}
diff --git a/misc/misc.go b/misc/misc.go
index 8eb76b9..2de1b7f 100644
--- a/misc/misc.go
+++ b/misc/misc.go
@@ -6,32 +6,32 @@ import (
"strings"
)
-// Pointerize_first returns the address of its first argument, and the value of
+// PointerizeFirst returns the address of its first argument, and the value of
// its second argument. This is useful to for taking the address of the
// non-error return value of a function that also has an error return value.
-func Pointerize_first[T1 any, T2 any](x1 T1, x2 T2) (*T1, T2) {
+func PointerizeFirst[T1 any, T2 any](x1 T1, x2 T2) (*T1, T2) {
return &x1, x2
}
-// Copy_map the map src to dst without clearing existing items in dst.
-func Copy_map[K comparable, V any](dst map[K]V, src map[K]V) {
+// CopyMap the map src to dst without clearing existing items in dst.
+func CopyMap[K comparable, V any](dst map[K]V, src map[K]V) {
for k, v := range src {
dst[k] = v
}
}
-// String_to_byte_ptr returns a pointer to the first byte of a string. It
+// StringToBytePtr returns a pointer to the first byte of a string. It
// ensures that the returned pointer is null-terminated.
-func String_to_byte_ptr(s string) (*byte, error) {
+func StringToBytePtr(s string) (*byte, error) {
// If the string already contains a null then whoever attempts to
// interpret this as a null-terminated string won't be able to see the
// whole string. This is probably not expected by the caller.
if strings.IndexByte(s, 0) != -1 {
- return nil, Err_null_byte
+ return nil, ErrNullByte
}
buf := make([]byte, len(s)+1) // Zeros them out...
copy(buf, s) // ... so the last byte would be null.
return &buf[0], nil
}
-var Err_null_byte = errors.New("string contains null byte")
+var ErrNullByte = errors.New("string contains null byte")
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)
}
diff --git a/misc/openat2.go b/misc/openat2.go
index 2b63634..e5938ca 100644
--- a/misc/openat2.go
+++ b/misc/openat2.go
@@ -23,7 +23,7 @@ const (
// See openat2(2) on Linux
func Openat2(dirfd int, path string, open_how *Open_how_t) (fd int, err error) {
- path_ptr, err := String_to_byte_ptr(path)
+ path_ptr, err := StringToBytePtr(path)
if err != nil {
return
}
diff --git a/misc/path.go b/misc/path.go
index 1b2e8a3..c7540fc 100644
--- a/misc/path.go
+++ b/misc/path.go
@@ -5,7 +5,7 @@ import (
"strings"
)
-func Sanitize_path(path string) (string, bool) {
+func SanitizePath(path string) (string, bool) {
if path == "" {
return "", false
}