aboutsummaryrefslogtreecommitdiff
path: root/misc/openat2.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-01-04 19:54:43 +0800
committerRunxi Yu <me@runxiyu.org>2025-01-04 19:54:43 +0800
commite140786e35c5d64d5fa0d4bd64df1a44940b6be3 (patch)
treeeca891334dd7b00a2e260d6dfbc7f29203629fae /misc/openat2.go
parentFix the README (diff)
downloadgo-lindenii-common-e140786e35c5d64d5fa0d4bd64df1a44940b6be3.tar.gz
go-lindenii-common-e140786e35c5d64d5fa0d4bd64df1a44940b6be3.tar.zst
go-lindenii-common-e140786e35c5d64d5fa0d4bd64df1a44940b6be3.zip
misc: Add Openat2
Diffstat (limited to '')
-rw-r--r--misc/openat2.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/misc/openat2.go b/misc/openat2.go
new file mode 100644
index 0000000..ab9f32d
--- /dev/null
+++ b/misc/openat2.go
@@ -0,0 +1,36 @@
+package misc
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+const SYS_OPENAT2 = 437
+
+type Open_how_t struct {
+ Flags uint64
+ Mode uint64
+ Resolve uint64
+}
+
+const (
+ RESOLVE_BENEATH = 0x8
+ RESOLVE_IN_ROOT = 0x10
+ RESOLVE_NO_MAGICLINKS = 0x2
+ RESOLVE_NO_SYMLINKS = 0x4
+ RESOLVE_NO_XDEV = 0x1
+)
+
+// See openat2(2) on Linux
+func Openat2(dirfd int, path string, open_how *Open_how_t, size int) (fd int, err error) {
+ path_ptr, err := String_to_byte_ptr(path)
+ if err != nil {
+ return
+ }
+ _fd, _, errno := syscall.Syscall6(SYS_OPENAT2, uintptr(dirfd), uintptr(unsafe.Pointer(path_ptr)), uintptr(unsafe.Pointer(open_how)), uintptr(size), 0, 0)
+ fd = int(_fd)
+ if errno != 0 {
+ err = errno
+ }
+ return
+}