From 4a74f1e0df84257aac462b725f14b080da703037 Mon Sep 17 00:00:00 2001 From: Luca Pizzamiglio Date: Sun, 21 Jul 2019 17:49:08 +0200 Subject: [PATCH] Add support for FreeBSD CURRENT (aka freebsd13) Currently, libc supports and detects freebsd11 and freebsd13 Unknown versions, like freebsd13, is treated as freebsd11. This patch solve the issues, detecting freebsd13 and treating it like freebsd12. Inverting the logic not(freebsd12) -> freebsd11 where possible --- build.rs | 4 ++++ libc-test/build.rs | 8 +++++++- src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs | 2 ++ src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs | 5 +++++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 4 +++- src/unix/bsd/freebsdlike/mod.rs | 4 ++-- src/unix/bsd/mod.rs | 4 ++-- src/unix/mod.rs | 14 +++++++------- 8 files changed, 32 insertions(+), 13 deletions(-) diff --git a/build.rs b/build.rs index 76ca0961..c43cca36 100644 --- a/build.rs +++ b/build.rs @@ -19,6 +19,9 @@ fn main() { if let Some(12) = which_freebsd() { println!("cargo:rustc-cfg=freebsd12"); } + if let Some(13) = which_freebsd() { + println!("cargo:rustc-cfg=freebsd13"); + } } // Rust >= 1.15 supports private module use: @@ -100,6 +103,7 @@ fn which_freebsd() -> Option { match &stdout { s if s.starts_with("11") => Some(11), s if s.starts_with("12") => Some(12), + s if s.starts_with("13") => Some(13), _ => None, } } diff --git a/libc-test/build.rs b/libc-test/build.rs index 6edbd0f2..8dffc681 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1455,6 +1455,11 @@ fn test_freebsd(target: &str) { cfg.cfg("freebsd12", None); } + if let Some(13) = freebsd_ver { + // If the host is FreeBSD 12, run FreeBSD 12 tests + cfg.cfg("freebsd13", None); + } + // Required for `getline`: cfg.define("_WITH_GETLINE", None); // Required for making freebsd11_stat available in the headers @@ -1581,7 +1586,7 @@ fn test_freebsd(target: &str) { | "IP_RECVORIGDSTADDR" | "IPV6_ORIGDSTADDR" | "IPV6_RECVORIGDSTADDR" - if Some(12) != freebsd_ver => + if Some(11) == freebsd_ver => { true } @@ -2468,6 +2473,7 @@ fn which_freebsd() -> Option { match &stdout { s if s.starts_with("11") => Some(11), s if s.starts_with("12") => Some(12), + s if s.starts_with("13") => Some(13), _ => None, } } diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs index 7d7dc2c1..b71b284e 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs @@ -189,6 +189,8 @@ cfg_if! { } } +pub const ELAST: ::c_int = 96; + extern { // Return type ::c_int was removed in FreeBSD 12 pub fn setgrent() -> ::c_int; diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs index ab1b8d98..c0191695 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs @@ -190,6 +190,11 @@ cfg_if! { } } +#[cfg(not(freebsd13))] +pub const ELAST: ::c_int = 96; +#[cfg(freebsd13)] +pub const ELAST: ::c_int = 97; + extern { pub fn setgrent(); pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 9f11c202..c178b91b 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -333,7 +333,6 @@ pub const ENOTCAPABLE: ::c_int = 93; pub const ECAPMODE: ::c_int = 94; pub const ENOTRECOVERABLE: ::c_int = 95; pub const EOWNERDEAD: ::c_int = 96; -pub const ELAST: ::c_int = 96; pub const RLIMIT_NPTS: ::c_int = 11; pub const RLIMIT_SWAP: ::c_int = 12; pub const RLIMIT_KQUEUES: ::c_int = 13; @@ -1332,6 +1331,9 @@ cfg_if! { if #[cfg(freebsd12)] { mod freebsd12; pub use self::freebsd12::*; + } else if #[cfg(freebsd13)] { + mod freebsd12; + pub use self::freebsd12::*; } else { mod freebsd11; pub use self::freebsd11::*; diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index ce545206..f937d772 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -1152,7 +1152,7 @@ extern { pub fn getutxline(ut: *const utmpx) -> *mut utmpx; pub fn initgroups(name: *const ::c_char, basegid: ::gid_t) -> ::c_int; #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "kevent@FBSD_1.0" )] pub fn kevent(kq: ::c_int, @@ -1171,7 +1171,7 @@ extern { pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char, mode: ::mode_t) -> ::c_int; #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "mknodat@FBSD_1.1" )] pub fn mknodat(dirfd: ::c_int, pathname: *const ::c_char, diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 77f82b18..ee644114 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -536,7 +536,7 @@ extern { #[cfg_attr(target_os = "macos", link_name = "glob$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__glob30")] #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "glob@FBSD_1.0" )] pub fn glob(pattern: *const ::c_char, @@ -546,7 +546,7 @@ extern { pglob: *mut ::glob_t) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")] #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "globfree@FBSD_1.0" )] pub fn globfree(pglob: *mut ::glob_t); diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 65cf7ecf..721d2411 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -567,7 +567,7 @@ extern { #[cfg_attr(target_os = "macos", link_name = "fstat$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__fstat50")] #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "fstat@FBSD_1.0" )] pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; @@ -577,7 +577,7 @@ extern { #[cfg_attr(target_os = "macos", link_name = "stat$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__stat50")] #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "stat@FBSD_1.0" )] pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; @@ -608,7 +608,7 @@ extern { #[cfg_attr(target_os = "macos", link_name = "readdir$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__readdir30")] #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "readdir@FBSD_1.0" )] pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent; @@ -631,7 +631,7 @@ extern { flags: ::c_int) -> ::c_int; #[cfg_attr(target_os = "macos", link_name = "fstatat$INODE64")] #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "fstatat@FBSD_1.1" )] pub fn fstatat(dirfd: ::c_int, pathname: *const ::c_char, @@ -786,7 +786,7 @@ extern { #[cfg_attr(target_os = "macos", link_name = "lstat$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__lstat50")] #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "lstat@FBSD_1.0" )] pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int; @@ -962,7 +962,7 @@ extern { #[cfg_attr(target_os = "netbsd", link_name = "__mknod50")] #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "mknod@FBSD_1.0" )] pub fn mknod(pathname: *const ::c_char, mode: ::mode_t, @@ -1126,7 +1126,7 @@ cfg_if! { #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")] #[cfg_attr( - all(target_os = "freebsd", not(freebsd12)), + all(target_os = "freebsd", freebsd11), link_name = "readdir_r@FBSD_1.0" )] /// The 64-bit libc on Solaris and illumos only has readdir_r. If a