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