forked from davecheney/xattr
/
syscall_darwin.go
60 lines (54 loc) · 1.7 KB
/
syscall_darwin.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package xattr
import (
"syscall"
"unsafe"
)
var noError = syscall.Errno(0)
// ssize_t getxattr(const char *path, const char *name, void *value, size_t size, u_int32_t position, int options);
func getxattr(path string, name string, value *byte, size int) (resSize int, e error) {
r0, _, e1 := syscall.Syscall6(syscall.SYS_GETXATTR,
uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
uintptr(unsafe.Pointer(value)),
uintptr(size), 0, 0)
resSize = int(r0)
if e1 != noError {
e = e1
}
return
}
// ssize_t listxattr(const char *path, char *namebuf, size_t size, int options);
func listxattr(path string, namebuf *byte, size int) (resSize int, e error) {
r0, _, e1 := syscall.Syscall(syscall.SYS_LISTXATTR,
uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
uintptr(unsafe.Pointer(namebuf)),
uintptr(size))
resSize = int(r0)
if e1 != noError {
e = e1
}
return
}
// int setxattr(const char *path, const char *name, void *value, size_t size, u_int32_t position, int options);
func setxattr(path string, name string, value *byte, size int) (e error) {
_, _, e1 := syscall.Syscall6(syscall.SYS_SETXATTR,
uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
uintptr(unsafe.Pointer(value)),
uintptr(size), 0, 0)
if e1 != noError {
e = e1
}
return
}
// int removexattr(const char *path, const char *name, int options);
func removexattr(path string, name string) (e error) {
_, _, e1 := syscall.Syscall(syscall.SYS_REMOVEXATTR,
uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
0)
if e1 != noError {
e = e1
}
return
}