From e98597a5398a4a2de3c1ec6aac53272054506107 Mon Sep 17 00:00:00 2001 From: Niklas Mohrin Date: Thu, 24 Oct 2024 16:46:11 +0200 Subject: [PATCH] Remove direct dependency on libc --- Cargo.toml | 3 --- src/clircle_unix.rs | 10 ++++------ src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d0a0731..e2f1c0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,6 @@ serde = { version = "1.0.117", optional = true } serde_derive = { version = "1.0.117", optional = true } cfg-if = "1.0.0" -[target.'cfg(not(windows))'.dependencies] -libc = "0.2" - [target.'cfg(windows)'.dependencies] winapi = { version = "0.3.9", features = ["winnt", "winbase", "processenv", "handleapi", "ntdef", "fileapi", "std"] } diff --git a/src/clircle_unix.rs b/src/clircle_unix.rs index 101f208..775e942 100644 --- a/src/clircle_unix.rs +++ b/src/clircle_unix.rs @@ -3,13 +3,11 @@ use crate::{Clircle, Stdio}; use std::convert::TryFrom; use std::fs::File; use std::io::{self, Seek}; +use std::os::fd::AsRawFd; use std::os::unix::fs::MetadataExt; use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd}; use std::{cmp, hash, ops}; -/// Re-export of libc -pub use libc; - /// Implementation of `Clircle` for Unix. #[derive(Debug)] pub struct UnixIdentifier { @@ -80,9 +78,9 @@ impl TryFrom for UnixIdentifier { fn try_from(stdio: Stdio) -> Result { let fd = match stdio { - Stdio::Stdin => libc::STDIN_FILENO, - Stdio::Stdout => libc::STDOUT_FILENO, - Stdio::Stderr => libc::STDERR_FILENO, + Stdio::Stdin => io::stdin().as_raw_fd(), + Stdio::Stdout => io::stdout().as_raw_fd(), + Stdio::Stderr => io::stderr().as_raw_fd(), }; // Safety: It is okay to create the file, because it won't be dropped later since the // `owns_fd` field is not set. diff --git a/src/lib.rs b/src/lib.rs index b0086f3..63d2273 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,7 +47,7 @@ cfg_if::cfg_if! { if #[cfg(unix)] { mod clircle_unix; - pub use clircle_unix::{libc, UnixIdentifier}; + pub use clircle_unix::UnixIdentifier; /// Identifies a file. The type is aliased according to the target platform. pub type Identifier = UnixIdentifier; } else if #[cfg(windows)] {