#![unstable(feature = "yggdrasil_os", issue = "none")]

use yggdrasil_rt::sys as syscall;

use crate::mem::MaybeUninit;
use crate::os::fd::{FromRawFd, OwnedFd};
use crate::sys::cvt_io;

#[unstable(feature = "yggdrasil_os", issue = "none")]
pub fn create_pipe_pair() -> crate::io::Result<(OwnedFd, OwnedFd)> {
    let mut buffer = MaybeUninit::uninit_array();
    cvt_io(unsafe { syscall::create_pipe(&mut buffer) })?;
    let read = unsafe { OwnedFd::from_raw_fd(buffer[0].assume_init()) };
    let write = unsafe { OwnedFd::from_raw_fd(buffer[1].assume_init()) };
    Ok((read, write))
}
