Skip to content

Commit fd80c02

Browse files
committed
Auto merge of rust-lang#116463 - ChrisDenton:nlibc, r=workingjubilee
Remove libc We don't use much libc on Windows and it seemed silly to keep if for the sake of [two well documented constants](https://learn.microsoft.com/en-us/cpp/c-runtime-library/exit-success-exit-failure?view=msvc-170).
2 parents 579be69 + c8f3aa4 commit fd80c02

File tree

7 files changed

+18
-13
lines changed

7 files changed

+18
-13
lines changed

Diff for: library/std/src/sys/windows/c.rs

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ pub use FD_SET as fd_set;
4646
pub use LINGER as linger;
4747
pub use TIMEVAL as timeval;
4848

49+
// https://learn.microsoft.com/en-us/cpp/c-runtime-library/exit-success-exit-failure?view=msvc-170
50+
pub const EXIT_SUCCESS: u32 = 0;
51+
pub const EXIT_FAILURE: u32 = 1;
52+
4953
pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE { Ptr: ptr::null_mut() };
5054
pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { Ptr: ptr::null_mut() };
5155
pub const INIT_ONCE_STATIC_INIT: INIT_ONCE = INIT_ONCE { Ptr: ptr::null_mut() };

Diff for: library/std/src/sys/windows/cmath.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg(not(test))]
22

3-
use libc::{c_double, c_float, c_int};
3+
use core::ffi::{c_double, c_float, c_int};
44

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

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

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

5757
#[inline]
5858
pub unsafe fn acosf(n: c_float) -> c_float {

Diff for: library/std/src/sys/windows/fs.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use crate::sys::{c, cvt, Align8};
1616
use crate::sys_common::{AsInner, FromInner, IntoInner};
1717
use crate::thread;
1818

19+
use core::ffi::c_void;
20+
1921
use super::path::maybe_verbatim;
2022
use super::to_u16s;
2123

@@ -371,7 +373,7 @@ impl File {
371373
cvt(c::GetFileInformationByHandleEx(
372374
self.handle.as_raw_handle(),
373375
c::FileBasicInfo,
374-
&mut info as *mut _ as *mut libc::c_void,
376+
&mut info as *mut _ as *mut c_void,
375377
size as c::DWORD,
376378
))?;
377379
let mut attr = FileAttr {
@@ -399,7 +401,7 @@ impl File {
399401
cvt(c::GetFileInformationByHandleEx(
400402
self.handle.as_raw_handle(),
401403
c::FileStandardInfo,
402-
&mut info as *mut _ as *mut libc::c_void,
404+
&mut info as *mut _ as *mut c_void,
403405
size as c::DWORD,
404406
))?;
405407
attr.file_size = info.AllocationSize as u64;
@@ -624,7 +626,7 @@ impl File {
624626
cvt(c::GetFileInformationByHandleEx(
625627
self.handle.as_raw_handle(),
626628
c::FileBasicInfo,
627-
&mut info as *mut _ as *mut libc::c_void,
629+
&mut info as *mut _ as *mut c_void,
628630
size as c::DWORD,
629631
))?;
630632
Ok(info)

Diff for: library/std/src/sys/windows/io.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::mem::size_of;
33
use crate::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle};
44
use crate::slice;
55
use crate::sys::c;
6-
use libc;
6+
use core::ffi::c_void;
77

88
#[derive(Copy, Clone)]
99
#[repr(transparent)]
@@ -136,7 +136,7 @@ unsafe fn msys_tty_on(handle: c::HANDLE) -> bool {
136136
let res = c::GetFileInformationByHandleEx(
137137
handle,
138138
c::FileNameInfo,
139-
&mut name_info as *mut _ as *mut libc::c_void,
139+
&mut name_info as *mut _ as *mut c_void,
140140
size_of::<FILE_NAME_INFO>() as u32,
141141
);
142142
if res == 0 {

Diff for: library/std/src/sys/windows/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::sys_common::net;
1515
use crate::sys_common::{AsInner, FromInner, IntoInner};
1616
use crate::time::Duration;
1717

18-
use libc::{c_int, c_long, c_ulong, c_ushort};
18+
use core::ffi::{c_int, c_long, c_ulong, c_ushort};
1919

2020
pub type wrlen_t = i32;
2121

Diff for: library/std/src/sys/windows/process.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ use crate::path::{Path, PathBuf};
1919
use crate::ptr;
2020
use crate::sync::Mutex;
2121
use crate::sys::args::{self, Arg};
22-
use crate::sys::c;
23-
use crate::sys::c::NonZeroDWORD;
22+
use crate::sys::c::{self, NonZeroDWORD, EXIT_FAILURE, EXIT_SUCCESS};
2423
use crate::sys::cvt;
2524
use crate::sys::fs::{File, OpenOptions};
2625
use crate::sys::handle::Handle;
@@ -30,7 +29,7 @@ use crate::sys::stdio;
3029
use crate::sys_common::process::{CommandEnv, CommandEnvs};
3130
use crate::sys_common::IntoInner;
3231

33-
use libc::{c_void, EXIT_FAILURE, EXIT_SUCCESS};
32+
use core::ffi::c_void;
3433

3534
////////////////////////////////////////////////////////////////////////////////
3635
// Command

Diff for: library/std/src/sys/windows/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::sys::stack_overflow;
1010
use crate::sys_common::FromInner;
1111
use crate::time::Duration;
1212

13-
use libc::c_void;
13+
use core::ffi::c_void;
1414

1515
use super::to_u16s;
1616

0 commit comments

Comments
 (0)