Skip to content

Commit

Permalink
Remove direct dependency on libc
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasmohrin committed Oct 24, 2024
1 parent dd2a4e2 commit e98597a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
10 changes: 4 additions & 6 deletions src/clircle_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -80,9 +78,9 @@ impl TryFrom<Stdio> for UnixIdentifier {

fn try_from(stdio: Stdio) -> Result<Self, Self::Error> {
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.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)] {
Expand Down

0 comments on commit e98597a

Please sign in to comment.