rustix/fs/fcopyfile.rs
1use crate::fs::CopyfileFlags;
2use crate::{backend, io};
3use backend::fd::AsFd;
4use backend::fs::types::copyfile_state_t;
5
6/// `fcopyfile(from, to, state, flags)`
7///
8/// # Safety
9///
10/// The `state` operand must be allocated with `copyfile_state_alloc` and not
11/// yet freed with `copyfile_state_free`.
12///
13/// # References
14/// - [Apple]
15///
16/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html
17#[inline]
18pub unsafe fn fcopyfile<FromFd: AsFd, ToFd: AsFd>(
19 from: FromFd,
20 to: ToFd,
21 state: copyfile_state_t,
22 flags: CopyfileFlags,
23) -> io::Result<()> {
24 backend::fs::syscalls::fcopyfile(from.as_fd(), to.as_fd(), state, flags)
25}
26
27/// `copyfile_state_alloc()`
28///
29/// # References
30/// - [Apple]
31///
32/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html
33#[inline]
34pub fn copyfile_state_alloc() -> io::Result<copyfile_state_t> {
35 backend::fs::syscalls::copyfile_state_alloc()
36}
37
38/// `copyfile_state_free(state)`
39///
40/// # Safety
41///
42/// The `state` operand must be allocated with `copyfile_state_alloc` and not
43/// yet freed with `copyfile_state_free`.
44///
45/// # References
46/// - [Apple]
47///
48/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html
49#[inline]
50pub unsafe fn copyfile_state_free(state: copyfile_state_t) -> io::Result<()> {
51 backend::fs::syscalls::copyfile_state_free(state)
52}
53
54/// `copyfile_state_get(state, COPYFILE_STATE_COPIED)`
55///
56/// # Safety
57///
58/// The `state` operand must be allocated with `copyfile_state_alloc` and not
59/// yet freed with `copyfile_state_free`.
60///
61/// # References
62/// - [Apple]
63///
64/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html
65#[inline]
66pub unsafe fn copyfile_state_get_copied(state: copyfile_state_t) -> io::Result<u64> {
67 backend::fs::syscalls::copyfile_state_get_copied(state)
68}
69
70/// `copyfile_state_get(state, flags, dst)`
71///
72/// # Safety
73///
74/// The `state` operand must be allocated with `copyfile_state_alloc` and not
75/// yet freed with `copyfile_state_free`.
76///
77/// # References
78/// - [Apple]
79///
80/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html
81#[inline]
82pub unsafe fn copyfile_state_get(
83 state: copyfile_state_t,
84 flag: u32,
85 dst: *mut core::ffi::c_void,
86) -> io::Result<()> {
87 backend::fs::syscalls::copyfile_state_get(state, flag, dst)
88}