refactor: replace nix::libc re-exports with direct libc imports

Replace all `nix::libc::*` usages with direct `libc::*` imports
to decouple libc access from the nix crate, as preparation for
migrating from nix to rustix.

Add direct libc dependency to crates that previously relied on
nix's libc re-export: stty, env, sort, date, mknod, touch.
This commit is contained in:
Sylvestre Ledru
2026-03-27 12:25:52 +01:00
parent f1681b0a42
commit 7ef9641eeb
13 changed files with 14 additions and 19 deletions
Generated
+4
View File
@@ -3543,6 +3543,7 @@ version = "0.8.0"
dependencies = [
"clap",
"fluent",
"libc",
"nix",
"rust-ini",
"thiserror 2.0.18",
@@ -3797,6 +3798,7 @@ version = "0.8.0"
dependencies = [
"clap",
"fluent",
"libc",
"nix",
"uucore",
]
@@ -4155,6 +4157,7 @@ dependencies = [
"fluent",
"foldhash 0.2.0",
"itertools 0.14.0",
"libc",
"memchr",
"nix",
"rand 0.10.1",
@@ -4215,6 +4218,7 @@ dependencies = [
"cfg_aliases",
"clap",
"fluent",
"libc",
"nix",
"uucore",
]
+1
View File
@@ -26,6 +26,7 @@ uucore = { workspace = true, features = ["signals"] }
fluent = { workspace = true }
[target.'cfg(unix)'.dependencies]
libc = { workspace = true }
nix = { workspace = true, features = ["signal"] }
[[bin]]
-2
View File
@@ -18,8 +18,6 @@ use native_int_str::{
Convert, NCvt, NativeIntStr, NativeIntString, NativeStr, from_native_int_representation_owned,
};
#[cfg(unix)]
use nix::libc;
#[cfg(unix)]
use nix::sys::signal::{
SigHandler::{SigDfl, SigIgn},
SigSet, SigmaskHow, Signal, signal, sigprocmask,
+1
View File
@@ -24,6 +24,7 @@ doctest = false
clap = { workspace = true }
uucore = { workspace = true, features = ["mode", "fs"] }
fluent = { workspace = true }
libc = { workspace = true }
nix = { workspace = true }
[features]
+1 -1
View File
@@ -6,7 +6,7 @@
// spell-checker:ignore (ToDO) parsemode makedev sysmacros perror IFBLK IFCHR IFIFO sflag
use clap::{Arg, ArgAction, Command, value_parser};
use nix::libc::{S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, mode_t};
use libc::{S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, mode_t};
use nix::sys::stat::{Mode, SFlag, mknod as nix_mknod, umask as nix_umask};
use uucore::display::Quotable;
+1
View File
@@ -51,6 +51,7 @@ foldhash = { workspace = true }
ctrlc = { workspace = true }
[target.'cfg(unix)'.dependencies]
libc = { workspace = true }
nix = { workspace = true, features = ["resource"] }
[dev-dependencies]
-3
View File
@@ -1410,8 +1410,6 @@ pub(crate) fn fd_soft_limit() -> Option<usize> {
#[cfg(unix)]
pub(crate) fn current_open_fd_count() -> Option<usize> {
use nix::libc;
fn count_dir(path: &str) -> Option<usize> {
let entries = std::fs::read_dir(path).ok()?;
let mut count = 0usize;
@@ -1770,7 +1768,6 @@ fn locale_failed_to_set() -> bool {
#[cfg(unix)]
fn locale_failed_to_set() -> bool {
use nix::libc;
unsafe { libc::setlocale(libc::LC_COLLATE, c"".as_ptr()).is_null() }
}
+1
View File
@@ -24,6 +24,7 @@ uucore = { workspace = true, features = ["parser"] }
fluent = { workspace = true }
[target.'cfg(unix)'.dependencies]
libc = { workspace = true }
nix = { workspace = true, features = ["ioctl", "term"] }
[[bin]]
+5 -5
View File
@@ -19,14 +19,14 @@ mod flags;
use crate::flags::AllFlags;
use crate::flags::COMBINATION_SETTINGS;
use clap::{Arg, ArgAction, ArgMatches, Command};
use nix::libc::{O_NONBLOCK, TIOCGWINSZ, TIOCSWINSZ, c_ushort};
use libc::{O_NONBLOCK, TIOCGWINSZ, TIOCSWINSZ, c_ushort};
#[cfg(all(
target_os = "linux",
not(target_arch = "powerpc"),
not(target_arch = "powerpc64")
))]
use nix::libc::{TCGETS2, termios2};
use libc::{TCGETS2, termios2};
use nix::sys::termios::{
ControlFlags, InputFlags, LocalFlags, OutputFlags, SetArg, SpecialCharacterIndices as S,
@@ -520,7 +520,7 @@ fn parse_rows_cols(arg: &str) -> Option<u16> {
/// - Returns `None` if format is invalid
fn parse_saved_state(arg: &str) -> Option<Vec<u32>> {
let parts: Vec<&str> = arg.split(':').collect();
let expected_parts = 4 + nix::libc::NCCS;
let expected_parts = 4 + libc::NCCS;
// GNU requires exactly the right number of parts for this platform
if parts.len() != expected_parts {
@@ -692,7 +692,7 @@ fn print_terminal_size(
{
// For some reason the normal nix Termios struct does not expose the line,
// so we get the underlying libc::termios struct to get that information.
let libc_termios: nix::libc::termios = termios.clone().into();
let libc_termios: libc::termios = termios.clone().into();
let line = libc_termios.c_line;
printer.print(&translate!("stty-output-line", "line" => line));
}
@@ -824,7 +824,7 @@ fn string_to_flag(option: &str) -> Option<AllFlags<'_>> {
None
}
fn control_char_to_string(cc: nix::libc::cc_t) -> nix::Result<String> {
fn control_char_to_string(cc: libc::cc_t) -> nix::Result<String> {
if cc == 0 {
return Ok(translate!("stty-output-undef"));
}
@@ -24,7 +24,6 @@ use std::path::{Path, PathBuf};
use nix::dir::Dir;
use nix::fcntl::{OFlag, openat};
use nix::libc;
use nix::sys::stat::{FchmodatFlags, FileStat, Mode, fchmodat, fstatat, mkdirat};
use nix::unistd::{Gid, Uid, UnlinkatFlags, fchown, fchownat, unlinkat};
use os_display::Quotable;
-3
View File
@@ -12,8 +12,6 @@
#[cfg(unix)]
use nix::errno::Errno;
#[cfg(any(target_os = "linux", target_os = "android"))]
use nix::libc;
#[cfg(unix)]
use nix::sys::signal::{
SaFlags, SigAction, SigHandler, SigHandler::SigDfl, SigHandler::SigIgn, SigSet, Signal,
@@ -548,7 +546,6 @@ static STARTUP_STATE_WAS_CAPTURED: AtomicBool = AtomicBool::new(false);
#[cfg(unix)]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn capture_startup_state() {
use nix::libc;
use std::mem::MaybeUninit;
use std::ptr;
-2
View File
@@ -49,8 +49,6 @@ pub fn mute_sigpipe_panic() {
/// variable. If set to "default", it restores SIGPIPE to SIG_DFL.
#[cfg(unix)]
pub fn preserve_inherited_sigpipe() {
use nix::libc;
// Check if parent specified that SIGPIPE should be default
if std::env::var_os("RUST_SIGPIPE").is_some_and(|v| v == "default") {
unsafe { libc::signal(libc::SIGPIPE, libc::SIG_DFL) };
-2
View File
@@ -5,8 +5,6 @@
// spell-checker:ignore (words) bamf chdir rlimit prlimit COMSPEC cout cerr FFFD winsize xpixel ypixel Secho sighandler
#![allow(clippy::missing_errors_doc)]
#[cfg(unix)]
use nix::libc;
#[cfg(unix)]
use nix::sys::signal::Signal;
#[cfg(feature = "echo")]