who: remove unsafe

This commit is contained in:
oech3
2026-04-29 09:48:48 +09:00
committed by Daniel Hofstetter
parent 4a862fc502
commit 49a5dad39a
3 changed files with 6 additions and 12 deletions
Generated
+1
View File
@@ -4469,6 +4469,7 @@ version = "0.8.0"
dependencies = [
"clap",
"fluent",
"rustix",
"uucore",
]
+1
View File
@@ -27,6 +27,7 @@ doctest = false
[dependencies]
clap = { workspace = true }
rustix = { workspace = true }
uucore = { workspace = true, features = ["utmpx"] }
fluent = { workspace = true }
+4 -12
View File
@@ -10,13 +10,12 @@ use crate::uu_app;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult};
use uucore::libc::{S_IWGRP, STDIN_FILENO, ttyname};
use uucore::libc::S_IWGRP;
use uucore::translate;
use uucore::utmpx::{self, UtmpxRecord, time};
use std::borrow::Cow;
use std::ffi::CStr;
use std::fmt::Write;
use std::io::{Write as _, stdout};
use std::os::unix::fs::MetadataExt;
@@ -179,17 +178,10 @@ fn time_string(ut: &UtmpxRecord) -> String {
ut.login_time().format(&time_format).unwrap()
}
#[inline]
fn current_tty() -> String {
let p = unsafe { ttyname(STDIN_FILENO) };
if p.is_null() {
String::new()
} else {
unsafe { CStr::from_ptr(p) }
.to_string_lossy()
.trim_start_matches("/dev/")
.to_owned()
}
rustix::termios::ttyname(std::io::stdin(), Vec::with_capacity(16))
.map(|s| s.to_string_lossy().trim_start_matches("/dev/").to_owned())
.unwrap_or_default()
}
impl Who {