1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//! Detect if the program is running under Windows Subsystem for Linux //! //! # Usage //! ``` //! wsl::is_wsl() //! ``` //! #![deny(clippy::all)] #![deny(missing_docs)] /// Test if the program is running under WSL #[cfg(target_os = "linux")] pub fn is_wsl() -> bool { if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") { if let Ok(s) = std::str::from_utf8(&b) { let a = s.to_ascii_lowercase(); return a.contains("microsoft") || a.contains("wsl"); } } false } /// Test if the program is running under WSL #[cfg(not(target_os = "linux"))] pub fn is_wsl() -> bool { false }