devela::_dep::nc::call

Function lsetxattr

pub unsafe fn lsetxattr<P>(
    filename: P,
    name: P,
    value: &[u8],
    flags: i32,
) -> Result<(), i32> 
where P: AsRef<Path>,
Available on crate feature dep_nc only.
Expand description

Set extended attribute value.

§Examples

let path = "/tmp/nc-lsetxattr";
let ret = unsafe { nc::openat(nc::AT_FDCWD, path, nc::O_WRONLY | nc::O_CREAT, 0o644) };
assert!(ret.is_ok());
let fd = ret.unwrap();
let ret = unsafe { nc::close(fd) };
assert!(ret.is_ok());
let attr_name = "user.creator";
let attr_value = "nc-0.0.1";
//let flags = 0;
let flags = nc::XATTR_CREATE;
let ret = unsafe {
    nc::lsetxattr(
        path,
        &attr_name,
        attr_value.as_bytes(),
        flags,
    )
};
assert!(ret.is_ok());
let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, path, 0) };
assert!(ret.is_ok());