starry_api/imp/fs/
pipe.rs

1use core::ffi::c_int;
2
3use axerrno::LinuxResult;
4
5use crate::{
6    file::{FileLike, Pipe, close_file_like},
7    ptr::UserPtr,
8};
9
10pub fn sys_pipe2(fds: UserPtr<[c_int; 2]>, flags: i32) -> LinuxResult<isize> {
11    if flags != 0 {
12        warn!("sys_pipe2: unsupported flags: {}", flags);
13    }
14
15    let fds = fds.get_as_mut()?;
16
17    let (read_end, write_end) = Pipe::new();
18    let read_fd = read_end.add_to_fd_table()?;
19    let write_fd = write_end
20        .add_to_fd_table()
21        .inspect_err(|_| close_file_like(read_fd).unwrap())?;
22
23    fds[0] = read_fd;
24    fds[1] = write_fd;
25
26    info!("sys_pipe2 <= fds: {:?}", fds);
27    Ok(0)
28}