diff --git a/src/backend/libc/pipe/syscalls.rs b/src/backend/libc/pipe/syscalls.rs index b36a18141..54cd2e080 100644 --- a/src/backend/libc/pipe/syscalls.rs +++ b/src/backend/libc/pipe/syscalls.rs @@ -118,8 +118,8 @@ pub(crate) fn fcntl_getpipe_sz(fd: BorrowedFd<'_>) -> io::Result { #[cfg(linux_kernel)] #[inline] -pub(crate) fn fcntl_setpipe_sz(fd: BorrowedFd<'_>, size: usize) -> io::Result<()> { +pub(crate) fn fcntl_setpipe_sz(fd: BorrowedFd<'_>, size: usize) -> io::Result { let size: c::c_int = size.try_into().map_err(|_| io::Errno::PERM)?; - unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_SETPIPE_SZ, size)) } + unsafe { ret_c_int(c::fcntl(borrowed_fd(fd), c::F_SETPIPE_SZ, size)).map(|size| size as usize) } } diff --git a/src/backend/linux_raw/pipe/syscalls.rs b/src/backend/linux_raw/pipe/syscalls.rs index 19039b42f..367c68bb0 100644 --- a/src/backend/linux_raw/pipe/syscalls.rs +++ b/src/backend/linux_raw/pipe/syscalls.rs @@ -111,12 +111,12 @@ pub(crate) fn fcntl_getpipe_sz(fd: BorrowedFd<'_>) -> io::Result { } #[inline] -pub(crate) fn fcntl_setpipe_sz(fd: BorrowedFd<'_>, size: usize) -> io::Result<()> { +pub(crate) fn fcntl_setpipe_sz(fd: BorrowedFd<'_>, size: usize) -> io::Result { let size: c::c_int = size.try_into().map_err(|_| io::Errno::PERM)?; #[cfg(target_pointer_width = "32")] unsafe { - ret(syscall_readonly!( + ret_usize(syscall_readonly!( __NR_fcntl64, fd, c_uint(F_SETPIPE_SZ), @@ -125,7 +125,7 @@ pub(crate) fn fcntl_setpipe_sz(fd: BorrowedFd<'_>, size: usize) -> io::Result<() } #[cfg(target_pointer_width = "64")] unsafe { - ret(syscall_readonly!( + ret_usize(syscall_readonly!( __NR_fcntl, fd, c_uint(F_SETPIPE_SZ), diff --git a/src/pipe.rs b/src/pipe.rs index 2e714c763..e52f1f9a4 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -215,6 +215,6 @@ pub fn fcntl_getpipe_size(fd: Fd) -> io::Result { /// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html #[cfg(linux_kernel)] #[inline] -pub fn fcntl_setpipe_size(fd: Fd, size: usize) -> io::Result<()> { +pub fn fcntl_setpipe_size(fd: Fd, size: usize) -> io::Result { backend::pipe::syscalls::fcntl_setpipe_sz(fd.as_fd(), size) } diff --git a/tests/pipe/fcntl.rs b/tests/pipe/fcntl.rs new file mode 100644 index 000000000..2d489e12b --- /dev/null +++ b/tests/pipe/fcntl.rs @@ -0,0 +1,31 @@ +#[cfg(linux_kernel)] +#[test] +fn test_fcntl_getpipe_size() { + use rustix::pipe::fcntl_getpipe_size; + + let (reader, writer) = rustix::pipe::pipe().unwrap(); + + let reader_size = fcntl_getpipe_size(&reader).unwrap(); + let writer_size = fcntl_getpipe_size(&writer).unwrap(); + assert_eq!(reader_size, writer_size); +} + +#[cfg(linux_kernel)] +#[test] +fn test_fcntl_setpipe_size() { + use rustix::pipe::{fcntl_getpipe_size, fcntl_setpipe_size}; + + let (reader, writer) = rustix::pipe::pipe().unwrap(); + + let new_size = 4096 * 2; + let reader_size = fcntl_setpipe_size(&reader, new_size).unwrap(); + let writer_size = fcntl_getpipe_size(&writer).unwrap(); + assert_eq!(reader_size, new_size); + assert_eq!(reader_size, writer_size); + + let new_size = 4096 * 16; + let reader_size = fcntl_setpipe_size(&reader, new_size).unwrap(); + let writer_size = fcntl_getpipe_size(&writer).unwrap(); + assert_eq!(reader_size, new_size); + assert_eq!(reader_size, writer_size); +} diff --git a/tests/pipe/main.rs b/tests/pipe/main.rs index e4427cdad..7f95076c5 100644 --- a/tests/pipe/main.rs +++ b/tests/pipe/main.rs @@ -4,5 +4,6 @@ #![cfg(not(windows))] mod basic; +mod fcntl; mod splice; mod tee;