Skip to content

Commit

Permalink
Remove libc
Browse files Browse the repository at this point in the history
We don't use much libc on Windows.
  • Loading branch information
ChrisDenton committed Oct 5, 2023
1 parent cae0791 commit c8f3aa4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
4 changes: 4 additions & 0 deletions library/std/src/sys/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ pub use FD_SET as fd_set;
pub use LINGER as linger;
pub use TIMEVAL as timeval;

// https://learn.microsoft.com/en-us/cpp/c-runtime-library/exit-success-exit-failure?view=msvc-170
pub const EXIT_SUCCESS: u32 = 0;
pub const EXIT_FAILURE: u32 = 1;

pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE { Ptr: ptr::null_mut() };
pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { Ptr: ptr::null_mut() };
pub const INIT_ONCE_STATIC_INIT: INIT_ONCE = INIT_ONCE { Ptr: ptr::null_mut() };
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/windows/cmath.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(not(test))]

use libc::{c_double, c_float, c_int};
use core::ffi::{c_double, c_float, c_int};

extern "C" {
pub fn acos(n: c_double) -> c_double;
Expand Down Expand Up @@ -33,7 +33,7 @@ pub use self::shims::*;

#[cfg(not(all(target_env = "msvc", target_arch = "x86")))]
mod shims {
use libc::c_float;
use core::ffi::c_float;

extern "C" {
pub fn acosf(n: c_float) -> c_float;
Expand All @@ -52,7 +52,7 @@ mod shims {
// back to f32. While not precisely correct should be "correct enough" for now.
#[cfg(all(target_env = "msvc", target_arch = "x86"))]
mod shims {
use libc::c_float;
use core::ffi::c_float;

#[inline]
pub unsafe fn acosf(n: c_float) -> c_float {
Expand Down
8 changes: 5 additions & 3 deletions library/std/src/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use crate::sys::{c, cvt, Align8};
use crate::sys_common::{AsInner, FromInner, IntoInner};
use crate::thread;

use core::ffi::c_void;

use super::path::maybe_verbatim;
use super::to_u16s;

Expand Down Expand Up @@ -371,7 +373,7 @@ impl File {
cvt(c::GetFileInformationByHandleEx(
self.handle.as_raw_handle(),
c::FileBasicInfo,
&mut info as *mut _ as *mut libc::c_void,
&mut info as *mut _ as *mut c_void,
size as c::DWORD,
))?;
let mut attr = FileAttr {
Expand Down Expand Up @@ -399,7 +401,7 @@ impl File {
cvt(c::GetFileInformationByHandleEx(
self.handle.as_raw_handle(),
c::FileStandardInfo,
&mut info as *mut _ as *mut libc::c_void,
&mut info as *mut _ as *mut c_void,
size as c::DWORD,
))?;
attr.file_size = info.AllocationSize as u64;
Expand Down Expand Up @@ -624,7 +626,7 @@ impl File {
cvt(c::GetFileInformationByHandleEx(
self.handle.as_raw_handle(),
c::FileBasicInfo,
&mut info as *mut _ as *mut libc::c_void,
&mut info as *mut _ as *mut c_void,
size as c::DWORD,
))?;
Ok(info)
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/windows/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::mem::size_of;
use crate::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle};
use crate::slice;
use crate::sys::c;
use libc;
use core::ffi::c_void;

#[derive(Copy, Clone)]
#[repr(transparent)]
Expand Down Expand Up @@ -136,7 +136,7 @@ unsafe fn msys_tty_on(handle: c::HANDLE) -> bool {
let res = c::GetFileInformationByHandleEx(
handle,
c::FileNameInfo,
&mut name_info as *mut _ as *mut libc::c_void,
&mut name_info as *mut _ as *mut c_void,
size_of::<FILE_NAME_INFO>() as u32,
);
if res == 0 {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/windows/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::sys_common::net;
use crate::sys_common::{AsInner, FromInner, IntoInner};
use crate::time::Duration;

use libc::{c_int, c_long, c_ulong, c_ushort};
use core::ffi::{c_int, c_long, c_ulong, c_ushort};

pub type wrlen_t = i32;

Expand Down
5 changes: 2 additions & 3 deletions library/std/src/sys/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use crate::path::{Path, PathBuf};
use crate::ptr;
use crate::sync::Mutex;
use crate::sys::args::{self, Arg};
use crate::sys::c;
use crate::sys::c::NonZeroDWORD;
use crate::sys::c::{self, NonZeroDWORD, EXIT_FAILURE, EXIT_SUCCESS};
use crate::sys::cvt;
use crate::sys::fs::{File, OpenOptions};
use crate::sys::handle::Handle;
Expand All @@ -30,7 +29,7 @@ use crate::sys::stdio;
use crate::sys_common::process::{CommandEnv, CommandEnvs};
use crate::sys_common::IntoInner;

use libc::{c_void, EXIT_FAILURE, EXIT_SUCCESS};
use core::ffi::c_void;

////////////////////////////////////////////////////////////////////////////////
// Command
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/windows/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::sys::stack_overflow;
use crate::sys_common::FromInner;
use crate::time::Duration;

use libc::c_void;
use core::ffi::c_void;

use super::to_u16s;

Expand Down

0 comments on commit c8f3aa4

Please sign in to comment.