summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/backend/libc/termios/syscalls.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/backend/libc/termios/syscalls.rs')
-rw-r--r--vendor/rustix/src/backend/libc/termios/syscalls.rs47
1 files changed, 26 insertions, 21 deletions
diff --git a/vendor/rustix/src/backend/libc/termios/syscalls.rs b/vendor/rustix/src/backend/libc/termios/syscalls.rs
index e0ab7a016..f54e9a6f3 100644
--- a/vendor/rustix/src/backend/libc/termios/syscalls.rs
+++ b/vendor/rustix/src/backend/libc/termios/syscalls.rs
@@ -10,12 +10,15 @@ use crate::fd::BorrowedFd;
#[cfg(feature = "procfs")]
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
use crate::ffi::CStr;
+#[cfg(not(target_os = "wasi"))]
use crate::io;
+#[cfg(not(target_os = "wasi"))]
use crate::process::{Pid, RawNonZeroPid};
+#[cfg(not(target_os = "wasi"))]
use crate::termios::{Action, OptionalActions, QueueSelector, Speed, Termios, Winsize};
use core::mem::MaybeUninit;
-use libc_errno::errno;
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> {
let mut result = MaybeUninit::<Termios>::uninit();
unsafe {
@@ -24,6 +27,7 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> {
}
}
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcgetpgrp(fd: BorrowedFd<'_>) -> io::Result<Pid> {
unsafe {
let pid = ret_pid_t(c::tcgetpgrp(borrowed_fd(fd)))?;
@@ -32,10 +36,12 @@ pub(crate) fn tcgetpgrp(fd: BorrowedFd<'_>) -> io::Result<Pid> {
}
}
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcsetpgrp(fd: BorrowedFd<'_>, pid: Pid) -> io::Result<()> {
unsafe { ret(c::tcsetpgrp(borrowed_fd(fd), pid.as_raw_nonzero().get())) }
}
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcsetattr(
fd: BorrowedFd,
optional_actions: OptionalActions,
@@ -50,22 +56,27 @@ pub(crate) fn tcsetattr(
}
}
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcsendbreak(fd: BorrowedFd) -> io::Result<()> {
unsafe { ret(c::tcsendbreak(borrowed_fd(fd), 0)) }
}
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcdrain(fd: BorrowedFd) -> io::Result<()> {
unsafe { ret(c::tcdrain(borrowed_fd(fd))) }
}
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcflush(fd: BorrowedFd, queue_selector: QueueSelector) -> io::Result<()> {
unsafe { ret(c::tcflush(borrowed_fd(fd), queue_selector as _)) }
}
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcflow(fd: BorrowedFd, action: Action) -> io::Result<()> {
unsafe { ret(c::tcflow(borrowed_fd(fd), action as _)) }
}
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> {
unsafe {
let pid = ret_pid_t(c::tcgetsid(borrowed_fd(fd)))?;
@@ -74,10 +85,12 @@ pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> {
}
}
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcsetwinsize(fd: BorrowedFd, winsize: Winsize) -> io::Result<()> {
unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCSWINSZ, &winsize)) }
}
+#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcgetwinsize(fd: BorrowedFd) -> io::Result<Winsize> {
unsafe {
let mut buf = MaybeUninit::<Winsize>::uninit();
@@ -90,59 +103,51 @@ pub(crate) fn tcgetwinsize(fd: BorrowedFd) -> io::Result<Winsize> {
}
}
+#[cfg(not(target_os = "wasi"))]
#[inline]
#[must_use]
pub(crate) fn cfgetospeed(termios: &Termios) -> Speed {
unsafe { c::cfgetospeed(termios) }
}
+#[cfg(not(target_os = "wasi"))]
#[inline]
#[must_use]
pub(crate) fn cfgetispeed(termios: &Termios) -> Speed {
unsafe { c::cfgetispeed(termios) }
}
+#[cfg(not(target_os = "wasi"))]
#[inline]
pub(crate) fn cfmakeraw(termios: &mut Termios) {
unsafe { c::cfmakeraw(termios) }
}
+#[cfg(not(target_os = "wasi"))]
#[inline]
pub(crate) fn cfsetospeed(termios: &mut Termios, speed: Speed) -> io::Result<()> {
unsafe { ret(c::cfsetospeed(termios, speed)) }
}
+#[cfg(not(target_os = "wasi"))]
#[inline]
pub(crate) fn cfsetispeed(termios: &mut Termios, speed: Speed) -> io::Result<()> {
unsafe { ret(c::cfsetispeed(termios, speed)) }
}
+#[cfg(not(target_os = "wasi"))]
#[inline]
pub(crate) fn cfsetspeed(termios: &mut Termios, speed: Speed) -> io::Result<()> {
unsafe { ret(c::cfsetspeed(termios, speed)) }
}
pub(crate) fn isatty(fd: BorrowedFd<'_>) -> bool {
- let res = unsafe { c::isatty(borrowed_fd(fd)) };
- if res == 0 {
- match errno().0 {
- #[cfg(not(any(target_os = "android", target_os = "linux")))]
- c::ENOTTY => false,
-
- // Old Linux versions reportedly return `EINVAL`.
- // <https://man7.org/linux/man-pages/man3/isatty.3.html#ERRORS>
- #[cfg(any(target_os = "android", target_os = "linux"))]
- c::ENOTTY | c::EINVAL => false,
-
- // Darwin mysteriously returns `EOPNOTSUPP` sometimes.
- #[cfg(any(target_os = "ios", target_os = "macos"))]
- c::EOPNOTSUPP => false,
-
- err => panic!("unexpected error from isatty: {:?}", err),
- }
- } else {
- true
- }
+ // Use the return value of `isatty` alone. We don't check `errno` because
+ // we return `bool` rather than `io::Result<bool>`, because we assume
+ // `BorrrowedFd` protects us from `EBADF`, and any other reasonably
+ // anticipated errno value would end up interpreted as "assume it's not a
+ // terminal" anyway.
+ unsafe { c::isatty(borrowed_fd(fd)) != 0 }
}
#[cfg(feature = "procfs")]