Skip to content

Commit c59ca73

Browse files
committed
Auto merge of #3041 - devnexen:linux_kernel_version, r=JohnTitor
adding KERNEL_VERSION macro for linux.
2 parents 45b431a + 88d6a1f commit c59ca73

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

libc-test/semver/linux.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ J1939_PGN_ADDRESS_COMMANDED
11461146
J1939_PGN_MAX
11471147
J1939_PGN_PDU1_MAX
11481148
J1939_PGN_REQUEST
1149+
KERNEL_VERSION
11491150
KEYCTL_ASSUME_AUTHORITY
11501151
KEYCTL_CHOWN
11511152
KEYCTL_CLEAR
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Compare libc's KERNEL_VERSION macro against a specific kernel version.
2+
3+
extern crate libc;
4+
5+
#[cfg(
6+
target_os = "linux",
7+
)]
8+
mod t {
9+
use libc;
10+
11+
#[test]
12+
fn test_kernel_version() {
13+
unsafe {
14+
assert_eq!(libc::KERNEL_VERSION(6, 0, 0), 393216);
15+
}
16+
}
17+
}

src/unix/linux_like/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,14 @@ safe_f! {
16151615
pub {const} fn IPTOS_ECN(x: u8) -> u8 {
16161616
x & ::IPTOS_ECN_MASK
16171617
}
1618+
1619+
#[allow(ellipsis_inclusive_range_patterns)]
1620+
pub {const} fn KERNEL_VERSION(a: u32, b: u32, c: u32) -> u32 {
1621+
((a << 16) + (b << 8)) + match c {
1622+
0 ... 255 => c,
1623+
_ => 255,
1624+
}
1625+
}
16181626
}
16191627

16201628
extern "C" {

0 commit comments

Comments
 (0)