wsl/
lib.rs

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