args::init(argc, argv);
unsafe fn sanitize_standard_fds() {
+ #[cfg(not(miri))]
+ // The standard fds are always available in Miri.
cfg_if::cfg_if! {
if #[cfg(not(any(
- // The standard fds are always available in Miri.
- miri,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "vxworks",
pub struct Socket(c::SOCKET);
+static INIT: Once = Once::new();
+
/// Checks whether the Windows socket interface has been started already, and
/// if not, starts it.
pub fn init() {
- static START: Once = Once::new();
-
- START.call_once(|| unsafe {
+ INIT.call_once(|| unsafe {
let mut data: c::WSADATA = mem::zeroed();
let ret = c::WSAStartup(
0x202, // version 2.2
}
pub fn cleanup() {
- unsafe {
- c::WSACleanup();
+ if INIT.is_completed() {
+ // only close the socket interface if it has actually been started
+ unsafe {
+ c::WSACleanup();
+ }
}
}
pub fn cleanup() {
static CLEANUP: Once = Once::new();
CLEANUP.call_once(|| unsafe {
- // SAFETY: Only called once during runtime cleanup.
- sys::cleanup();
// Flush stdout and disable buffering.
crate::io::cleanup();
+ // SAFETY: Only called once during runtime cleanup.
+ sys::cleanup();
});
}