Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding KERNEL_VERSION macro for linux. #3041

Merged
merged 1 commit into from Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions libc-test/semver/linux.txt
Expand Up @@ -1146,6 +1146,7 @@ J1939_PGN_ADDRESS_COMMANDED
J1939_PGN_MAX
J1939_PGN_PDU1_MAX
J1939_PGN_REQUEST
KERNEL_VERSION
KEYCTL_ASSUME_AUTHORITY
KEYCTL_CHOWN
KEYCTL_CLEAR
Expand Down
17 changes: 17 additions & 0 deletions libc-test/test/linux_kernel_version.rs
@@ -0,0 +1,17 @@
//! Compare libc's KERNEL_VERSION macro against a specific kernel version.

extern crate libc;

#[cfg(
target_os = "linux",
)]
mod t {
use libc;

#[test]
fn test_kernel_version() {
unsafe {
assert_eq!(libc::KERNEL_VERSION(6, 0, 0), 393216);
}
}
}
8 changes: 8 additions & 0 deletions src/unix/linux_like/mod.rs
Expand Up @@ -1615,6 +1615,14 @@ safe_f! {
pub {const} fn IPTOS_ECN(x: u8) -> u8 {
x & ::IPTOS_ECN_MASK
}

#[allow(ellipsis_inclusive_range_patterns)]
pub {const} fn KERNEL_VERSION(a: u32, b: u32, c: u32) -> u32 {
((a << 16) + (b << 8)) + match c {
0 ... 255 => c,
_ => 255,
}
}
}

extern "C" {
Expand Down