unlink/unlink.rs
1// Copyright (c) 2020 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
2// Use of this source is governed by Apache-2.0 License that can be found
3// in the LICENSE file.
4
5fn main() {
6 #[cfg(feature = "std")]
7 let path = std::path::Path::new("/tmp/nc-unlink");
8 #[cfg(not(feature = "std"))]
9 let path = "/tmp/nc.unlink";
10
11 let ret = unsafe { nc::openat(nc::AT_FDCWD, path, nc::O_WRONLY | nc::O_CREAT, 0o644) };
12 assert!(ret.is_ok());
13 let fd = ret.unwrap();
14 let ret = unsafe { nc::close(fd) };
15 assert!(ret.is_ok());
16 let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, path, 0) };
17 assert!(ret.is_ok());
18}