Merge branch 'add-mkdirat' into 'master'

Implement mkfifoat(2)

See merge request redox-os/relibc!881
This commit is contained in:
Jeremy Soller
2026-01-12 19:25:27 -07:00
4 changed files with 34 additions and 2 deletions
+9
View File
@@ -176,6 +176,15 @@ pub unsafe extern "C" fn mkdir(path: *const c_char, mode: mode_t) -> c_int {
Sys::mkdir(path, mode).map(|()| 0).or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkfifoat.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mkfifoat(dirfd: c_int, path: *const c_char, mode: mode_t) -> c_int {
let path = CStr::from_ptr(path);
Sys::mkfifoat(dirfd, path, mode)
.map(|()| 0)
.or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkfifo.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mkfifo(path: *const c_char, mode: mode_t) -> c_int {
+4
View File
@@ -527,6 +527,10 @@ impl Pal for Sys {
Sys::mknodat(AT_FDCWD, path, mode, dev)
}
fn mkfifoat(dir_fd: c_int, path: CStr, mode: mode_t) -> Result<()> {
Sys::mknodat(dir_fd, path, mode | S_IFIFO, 0)
}
fn mkfifo(path: CStr, mode: mode_t) -> Result<()> {
Sys::mknod(path, mode | S_IFIFO, 0)
}
+2
View File
@@ -175,6 +175,8 @@ pub trait Pal {
fn mkdir(path: CStr, mode: mode_t) -> Result<()>;
fn mkfifoat(dir_fd: c_int, path: CStr, mode: mode_t) -> Result<()>;
fn mkfifo(path: CStr, mode: mode_t) -> Result<()>;
fn mknodat(fildes: c_int, path: CStr, mode: mode_t, dev: dev_t) -> Result<()>;
+19 -2
View File
@@ -708,6 +708,23 @@ impl Pal for Sys {
Ok(())
}
fn mkfifoat(dir_fd: c_int, path_name: CStr, mode: mode_t) -> Result<()> {
let mut dir_path_buf = [0; 4096];
let res = Sys::fpath(dir_fd, &mut dir_path_buf)?;
let dir_path = str::from_utf8(&dir_path_buf[..res as usize]).map_err(|_| Errno(EBADR))?;
let resource_path =
path::canonicalize_using_cwd(Some(&dir_path), &path_name.to_string_lossy())
// Since parent_dir_path is resolved by fpath, it is more likely that
// the problem was with path.
.ok_or(Errno(ENOENT))?;
Sys::mkfifo(
CStr::borrow(&CString::new(resource_path.as_bytes()).unwrap()),
mode,
)
}
fn mkfifo(path: CStr, mode: mode_t) -> Result<()> {
Sys::mknod(path, syscall::MODE_FIFO as mode_t | (mode & 0o777), 0)
}
@@ -874,8 +891,8 @@ impl Pal for Sys {
// POSIX states that umask should affect the following:
//
// open, openat (TODO), creat, mkdir, mkdirat (TODO),
// mkfifo, mkfifoat (TODO), mknod, mknodat (TODO),
// open, openat, creat, mkdir, mkdirat,
// mkfifo, mkfifoat, mknod, mknodat,
// mq_open, and sem_open,
//
// all of which (the ones that exist thus far) currently call this function.