summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/termios/tty.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/termios/tty.rs')
-rw-r--r--vendor/rustix/src/termios/tty.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/vendor/rustix/src/termios/tty.rs b/vendor/rustix/src/termios/tty.rs
index 00787a568..56aab9fcf 100644
--- a/vendor/rustix/src/termios/tty.rs
+++ b/vendor/rustix/src/termios/tty.rs
@@ -2,7 +2,7 @@
use crate::backend;
use backend::fd::AsFd;
-#[cfg(feature = "procfs")]
+#[cfg(all(feature = "alloc", feature = "procfs"))]
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
use {
crate::ffi::CString, crate::io, crate::path::SMALL_PATH_BUFFER_SIZE, alloc::vec::Vec,
@@ -33,7 +33,7 @@ pub fn isatty<Fd: AsFd>(fd: Fd) -> bool {
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/ttyname.html
/// [Linux]: https://man7.org/linux/man-pages/man3/ttyname.3.html
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
-#[cfg(feature = "procfs")]
+#[cfg(all(feature = "alloc", feature = "procfs"))]
#[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))]
#[doc(alias = "ttyname_r")]
#[inline]
@@ -42,7 +42,7 @@ pub fn ttyname<Fd: AsFd, B: Into<Vec<u8>>>(dirfd: Fd, reuse: B) -> io::Result<CS
}
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
-#[cfg(feature = "procfs")]
+#[cfg(all(feature = "alloc", feature = "procfs"))]
#[allow(unsafe_code)]
fn _ttyname(dirfd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CString> {
buffer.clear();
@@ -54,9 +54,10 @@ fn _ttyname(dirfd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CString> {
buffer.reserve(buffer.capacity() + 1); // use `Vec` reallocation strategy to grow capacity exponentially
}
Ok(len) => {
- // SAFETY: assume the backend returns the length of the string
+ // SAFETY: assume the backend returns the length of the string excluding the
+ // NUL.
unsafe {
- buffer.set_len(len);
+ buffer.set_len(len + 1);
}
// SAFETY: