aboutsummaryrefslogtreecommitdiff
path: root/misc/openat2.go
blob: ab9f32d7202899cad2ae58d2ffbfad5b98470149 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
}