Skip to content

Commit 3981b94

Browse files
authored
Merge pull request #571 from Krysztal112233/chore/remove_libc
chore: remove `libc` use `uucore::libc` instead
2 parents 070ad5e + d8c380f commit 3981b94

File tree

13 files changed

+246
-251
lines changed

13 files changed

+246
-251
lines changed

Cargo.lock

Lines changed: 222 additions & 224 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ crossterm = "0.29.0"
6161
ctor = "0.6.0"
6262
dirs = "6.0.0"
6363
jiff = "0.2.15"
64-
libc = "0.2.154"
6564
nix = { version = "0.30", default-features = false, features = ["process"] }
6665
phf = "0.13.1"
6766
phf_codegen = "0.13.0"
@@ -115,12 +114,16 @@ watch = { optional = true, version = "0.0.1", package = "uu_watch", path = "src/
115114
[dev-dependencies]
116115
chrono = { workspace = true }
117116
ctor = { workspace = true }
118-
libc = { workspace = true }
119117
pretty_assertions = "1.4.0"
120118
rand = { workspace = true }
121119
regex = { workspace = true }
122120
tempfile = { workspace = true }
123-
uucore = { workspace = true, features = ["entries", "process", "signals"] }
121+
uucore = { workspace = true, features = [
122+
"entries",
123+
"libc",
124+
"process",
125+
"signals",
126+
] }
124127
uutests = { workspace = true }
125128

126129
[target.'cfg(unix)'.dev-dependencies]

src/uu/ps/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ version.workspace = true
1414
workspace = true
1515

1616
[dependencies]
17-
uucore = { workspace = true, features = ["utmpx"] }
17+
uucore = { workspace = true, features = ["utmpx", "libc"] }
1818
clap = { workspace = true }
1919
chrono = { workspace = true, default-features = false, features = ["clock"] }
20-
libc = { workspace = true }
2120
prettytable-rs = { workspace = true }
2221
nix = { workspace = true }
2322

src/uu/ps/src/process_selection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use nix::errno::Errno;
1616
#[cfg(target_family = "unix")]
1717
fn getsid(pid: i32) -> Option<i32> {
1818
unsafe {
19-
let result = libc::getsid(pid);
19+
let result = uucore::libc::getsid(pid);
2020
if Errno::last() == Errno::UnknownErrno {
2121
Some(result)
2222
} else {

src/uu/snice/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ version.workspace = true
1414
workspace = true
1515

1616
[dependencies]
17-
uucore = { workspace = true, features = ["signals"] }
17+
uucore = { workspace = true, features = ["signals", "libc"] }
1818
clap = { workspace = true }
19-
libc = { workspace = true }
2019
nix = { workspace = true }
2120
prettytable-rs = { workspace = true }
2221
thiserror = { workspace = true }

src/uu/snice/src/action.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ impl Display for ActionResult {
113113
/// But we don't know if the process of pid are exist, if [None], the process doesn't exist
114114
#[cfg(target_os = "linux")]
115115
fn set_priority(pid: u32, prio: &Priority, take_action: bool) -> Option<ActionResult> {
116-
use libc::{getpriority, setpriority, PRIO_PROCESS};
117116
use nix::errno::Errno;
117+
use uucore::libc::{getpriority, setpriority, PRIO_PROCESS};
118118

119119
// Very dirty.
120120
let current_priority = {

src/uu/top/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ version.workspace = true
1414
workspace = true
1515

1616
[dependencies]
17-
uucore = { workspace = true, features = ["utmpx", "uptime", "signals"] }
17+
uucore = { workspace = true, features = ["utmpx", "uptime", "signals", "libc"] }
1818
clap = { workspace = true }
1919
crossterm = { workspace = true }
20-
libc = { workspace = true }
2120
nix = { workspace = true }
2221
ratatui = { workspace = true, features = ["crossterm"] }
2322
sysinfo = { workspace = true }

src/uu/top/src/action.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#[cfg(target_os = "linux")]
77
pub(crate) fn renice(pid: u32, nice_value: i32) -> uucore::error::UResult<()> {
8-
use libc::{setpriority, PRIO_PROCESS};
98
use uucore::error::USimpleError;
9+
use uucore::libc::{setpriority, PRIO_PROCESS};
1010

1111
let result = unsafe { setpriority(PRIO_PROCESS, pid, nice_value) };
1212
if result == -1 {

src/uu/top/src/picker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ fn pr(_pid: u32, _stat: Stat) -> Box<dyn Column> {
317317

318318
#[cfg(not(target_os = "windows"))]
319319
fn get_nice(pid: u32) -> i32 {
320-
use libc::{getpriority, PRIO_PROCESS};
321320
use nix::errno::Errno;
321+
use uucore::libc::{getpriority, PRIO_PROCESS};
322322

323323
// this is nice value, not priority value
324324
let result = unsafe { getpriority(PRIO_PROCESS, pid) };
@@ -381,7 +381,7 @@ fn shr(pid: u32, _stat: Stat) -> Box<dyn Column> {
381381
let content = read_to_string(file).unwrap();
382382
let values = content.split_whitespace();
383383
if let Some(shared) = values.collect::<Vec<_>>().get(2) {
384-
let page_size = unsafe { libc::sysconf(libc::_SC_PAGESIZE) };
384+
let page_size = unsafe { uucore::libc::sysconf(uucore::libc::_SC_PAGESIZE) };
385385
MemValue::new_boxed(shared.parse::<u64>().unwrap() * page_size as u64)
386386
} else {
387387
MemValue::new_boxed(0)

src/uu/top/src/platform/linux.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use std::collections::HashMap;
88
use std::str::FromStr;
99

1010
extern "C" {
11-
pub fn sd_booted() -> libc::c_int;
12-
pub fn sd_get_sessions(sessions: *mut *mut *mut libc::c_char) -> libc::c_int;
11+
pub fn sd_booted() -> uucore::libc::c_int;
12+
pub fn sd_get_sessions(sessions: *mut *mut *mut uucore::libc::c_char) -> uucore::libc::c_int;
1313
pub fn sd_session_get_class(
14-
session: *const libc::c_char,
15-
class: *mut *mut libc::c_char,
16-
) -> libc::c_int;
14+
session: *const uucore::libc::c_char,
15+
class: *mut *mut uucore::libc::c_char,
16+
) -> uucore::libc::c_int;
1717
}
1818

1919
pub fn get_nusers_systemd() -> uucore::error::UResult<usize> {

0 commit comments

Comments
 (0)