xattr/sys/linux_macos/
linux.rs

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
use libc::{c_char, c_int, c_void, size_t, ssize_t};

extern "C" {
    pub fn flistxattr(fd: c_int, buf: *mut c_char, size: size_t) -> ssize_t;
    pub fn fgetxattr(fd: c_int, name: *const c_char, value: *mut c_void, size: size_t) -> ssize_t;
    pub fn fremovexattr(fd: c_int, name: *const c_char) -> c_int;

    pub fn llistxattr(path: *const c_char, buf: *mut c_char, size: size_t) -> ssize_t;
    pub fn lgetxattr(
        path: *const c_char,
        name: *const c_char,
        value: *mut c_void,
        size: size_t,
    ) -> ssize_t;
    pub fn lremovexattr(path: *const c_char, name: *const c_char) -> c_int;
}

pub unsafe fn fsetxattr(
    fd: c_int,
    name: *const c_char,
    value: *const c_void,
    size: size_t,
) -> ssize_t {
    extern "C" {
        fn fsetxattr(
            fd: c_int,
            name: *const c_char,
            value: *const c_void,
            size: size_t,
            flags: c_int,
        ) -> ssize_t;
    }
    fsetxattr(fd, name, value, size, 0)
}

pub unsafe fn lsetxattr(
    path: *const c_char,
    name: *const c_char,
    value: *const c_void,
    size: size_t,
) -> ssize_t {
    extern "C" {
        fn lsetxattr(
            path: *const c_char,
            name: *const c_char,
            value: *const c_void,
            size: size_t,
            flags: c_int,
        ) -> ssize_t;
    }
    lsetxattr(path, name, value, size, 0)
}