Merge branch 'unlinkat-symlinkat-linkat' into 'master'

add unlinkat(2), symlinkat(2), linkat(2) and expose openat(2)

See merge request redox-os/relibc!1212
This commit is contained in:
Jeremy Soller
2026-04-20 11:31:10 -06:00
6 changed files with 116 additions and 18 deletions
+12 -1
View File
@@ -80,6 +80,17 @@ pub unsafe extern "C" fn fcntl(fildes: c_int, cmd: c_int, mut __valist: ...) ->
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/open.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn open(path: *const c_char, oflag: c_int, mut __valist: ...) -> c_int {
unsafe { openat(AT_FDCWD, path, oflag, __valist) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/openat.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn openat(
fd: c_int,
path: *const c_char,
oflag: c_int,
mut __valist: ...
) -> c_int {
let mode = if oflag & O_CREAT == O_CREAT
/* || oflag & O_TMPFILE == O_TMPFILE */
{
@@ -89,7 +100,7 @@ pub unsafe extern "C" fn open(path: *const c_char, oflag: c_int, mut __valist: .
};
let path = unsafe { CStr::from_ptr(path) };
Sys::open(path, oflag, mode).or_minus_one_errno()
Sys::openat(fd, path, oflag, mode).or_minus_one_errno()
}
#[unsafe(no_mangle)]
+1
View File
@@ -31,5 +31,6 @@ pub const O_NDELAY: c_int = O_NONBLOCK;
// Flags for capability based "at" functions
pub const AT_FDCWD: c_int = -100;
pub const AT_SYMLINK_NOFOLLOW: c_int = 0x0200;
pub const AT_SYMLINK_FOLLOW: c_int = 0x2000;
pub const AT_EMPTY_PATH: c_int = 0x4000;
pub const AT_REMOVEDIR: c_int = 0x200;
+36 -1
View File
@@ -577,7 +577,7 @@ pub unsafe extern "C" fn gethostname(mut name: *mut c_char, mut len: size_t) ->
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getlogin.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn getlogin() -> *mut c_char {
const LOGIN_LEN: usize = 256;
const LOGIN_LEN: usize = limits::LOGIN_NAME_MAX as usize;
static mut LOGIN: [c_char; LOGIN_LEN] = [0; LOGIN_LEN];
if getlogin_r((&raw mut LOGIN).cast(), LOGIN_LEN) == 0 {
(&raw mut LOGIN).cast()
@@ -707,6 +707,22 @@ pub unsafe extern "C" fn link(path1: *const c_char, path2: *const c_char) -> c_i
Sys::link(path1, path2).map(|()| 0).or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/linkat.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn linkat(
fd1: c_int,
path1: *const c_char,
fd2: c_int,
path2: *const c_char,
flags: c_int,
) -> c_int {
let path1 = unsafe { CStr::from_ptr(path1) };
let path2 = unsafe { CStr::from_ptr(path2) };
Sys::linkat(fd1, path1, fd2, path2, flags)
.map(|()| 0)
.or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/lockf.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lockf(fildes: c_int, function: c_int, size: off_t) -> c_int {
@@ -1010,6 +1026,16 @@ pub unsafe extern "C" fn symlink(path1: *const c_char, path2: *const c_char) ->
Sys::symlink(path1, path2).map(|()| 0).or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/symlinkat.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn symlinkat(path1: *const c_char, fd: c_int, path2: *const c_char) -> c_int {
let path1 = unsafe { CStr::from_ptr(path1) };
let path2 = unsafe { CStr::from_ptr(path2) };
Sys::symlinkat(path1, fd, path2)
.map(|()| 0)
.or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sync.html>.
#[unsafe(no_mangle)]
pub extern "C" fn sync() {
@@ -1123,6 +1149,15 @@ pub unsafe extern "C" fn unlink(path: *const c_char) -> c_int {
Sys::unlink(path).map(|()| 0).or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/unlinkat.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn unlinkat(fd: c_int, path: *const c_char, flags: c_int) -> c_int {
let path = unsafe { CStr::from_ptr(path) };
Sys::unlinkat(fd, path, flags)
.map(|()| 0)
.or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html>.
///
/// # Deprecation