Skip to content

Commit 96ea9c9

Browse files
committed
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
1 parent c8aa8ec commit 96ea9c9

File tree

8 files changed

+32
-13
lines changed

8 files changed

+32
-13
lines changed

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ fn main() {
1919
if let Some(12) = which_freebsd() {
2020
println!("cargo:rustc-cfg=freebsd12");
2121
}
22+
if let Some(13) = which_freebsd() {
23+
println!("cargo:rustc-cfg=freebsd13");
24+
}
2225
}
2326

2427
// Rust >= 1.15 supports private module use:
@@ -100,6 +103,7 @@ fn which_freebsd() -> Option<i32> {
100103
match &stdout {
101104
s if s.starts_with("11") => Some(11),
102105
s if s.starts_with("12") => Some(12),
106+
s if s.starts_with("13") => Some(13),
103107
_ => None,
104108
}
105109
}

libc-test/build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,11 @@ fn test_freebsd(target: &str) {
14551455
cfg.cfg("freebsd12", None);
14561456
}
14571457

1458+
if let Some(13) = freebsd_ver {
1459+
// If the host is FreeBSD 12, run FreeBSD 12 tests
1460+
cfg.cfg("freebsd13", None);
1461+
}
1462+
14581463
// Required for `getline`:
14591464
cfg.define("_WITH_GETLINE", None);
14601465
// Required for making freebsd11_stat available in the headers
@@ -1581,7 +1586,7 @@ fn test_freebsd(target: &str) {
15811586
| "IP_RECVORIGDSTADDR"
15821587
| "IPV6_ORIGDSTADDR"
15831588
| "IPV6_RECVORIGDSTADDR"
1584-
if Some(12) != freebsd_ver =>
1589+
if Some(11) == freebsd_ver =>
15851590
{
15861591
true
15871592
}
@@ -2468,6 +2473,7 @@ fn which_freebsd() -> Option<i32> {
24682473
match &stdout {
24692474
s if s.starts_with("11") => Some(11),
24702475
s if s.starts_with("12") => Some(12),
2476+
s if s.starts_with("13") => Some(13),
24712477
_ => None,
24722478
}
24732479
}

src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ cfg_if! {
189189
}
190190
}
191191

192+
pub const ELAST: ::c_int = 96;
193+
192194
extern {
193195
// Return type ::c_int was removed in FreeBSD 12
194196
pub fn setgrent() -> ::c_int;

src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ cfg_if! {
190190
}
191191
}
192192

193+
#[cfg(not(freebsd13))]
194+
pub const ELAST: ::c_int = 96;
195+
#[cfg(freebsd13)]
196+
pub const ELAST: ::c_int = 97;
197+
193198
extern {
194199
pub fn setgrent();
195200
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ pub const ENOTCAPABLE: ::c_int = 93;
333333
pub const ECAPMODE: ::c_int = 94;
334334
pub const ENOTRECOVERABLE: ::c_int = 95;
335335
pub const EOWNERDEAD: ::c_int = 96;
336-
pub const ELAST: ::c_int = 96;
337336
pub const RLIMIT_NPTS: ::c_int = 11;
338337
pub const RLIMIT_SWAP: ::c_int = 12;
339338
pub const RLIMIT_KQUEUES: ::c_int = 13;
@@ -1332,6 +1331,9 @@ cfg_if! {
13321331
if #[cfg(freebsd12)] {
13331332
mod freebsd12;
13341333
pub use self::freebsd12::*;
1334+
} else if #[cfg(freebsd13)] {
1335+
mod freebsd12;
1336+
pub use self::freebsd12::*;
13351337
} else {
13361338
mod freebsd11;
13371339
pub use self::freebsd11::*;

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ extern {
11521152
pub fn getutxline(ut: *const utmpx) -> *mut utmpx;
11531153
pub fn initgroups(name: *const ::c_char, basegid: ::gid_t) -> ::c_int;
11541154
#[cfg_attr(
1155-
all(target_os = "freebsd", not(freebsd12)),
1155+
all(target_os = "freebsd", freebsd11),
11561156
link_name = "kevent@FBSD_1.0"
11571157
)]
11581158
pub fn kevent(kq: ::c_int,
@@ -1171,7 +1171,7 @@ extern {
11711171
pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char,
11721172
mode: ::mode_t) -> ::c_int;
11731173
#[cfg_attr(
1174-
all(target_os = "freebsd", not(freebsd12)),
1174+
all(target_os = "freebsd", freebsd11),
11751175
link_name = "mknodat@FBSD_1.1"
11761176
)]
11771177
pub fn mknodat(dirfd: ::c_int, pathname: *const ::c_char,

src/unix/bsd/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ extern {
536536
#[cfg_attr(target_os = "macos", link_name = "glob$INODE64")]
537537
#[cfg_attr(target_os = "netbsd", link_name = "__glob30")]
538538
#[cfg_attr(
539-
all(target_os = "freebsd", not(freebsd12)),
539+
all(target_os = "freebsd", freebsd11),
540540
link_name = "glob@FBSD_1.0"
541541
)]
542542
pub fn glob(pattern: *const ::c_char,
@@ -546,7 +546,7 @@ extern {
546546
pglob: *mut ::glob_t) -> ::c_int;
547547
#[cfg_attr(target_os = "netbsd", link_name = "__globfree30")]
548548
#[cfg_attr(
549-
all(target_os = "freebsd", not(freebsd12)),
549+
all(target_os = "freebsd", freebsd11),
550550
link_name = "globfree@FBSD_1.0"
551551
)]
552552
pub fn globfree(pglob: *mut ::glob_t);

src/unix/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ extern {
567567
#[cfg_attr(target_os = "macos", link_name = "fstat$INODE64")]
568568
#[cfg_attr(target_os = "netbsd", link_name = "__fstat50")]
569569
#[cfg_attr(
570-
all(target_os = "freebsd", not(freebsd12)),
570+
all(target_os = "freebsd", freebsd11),
571571
link_name = "fstat@FBSD_1.0"
572572
)]
573573
pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int;
@@ -577,7 +577,7 @@ extern {
577577
#[cfg_attr(target_os = "macos", link_name = "stat$INODE64")]
578578
#[cfg_attr(target_os = "netbsd", link_name = "__stat50")]
579579
#[cfg_attr(
580-
all(target_os = "freebsd", not(freebsd12)),
580+
all(target_os = "freebsd", freebsd11),
581581
link_name = "stat@FBSD_1.0"
582582
)]
583583
pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int;
@@ -614,14 +614,14 @@ extern {
614614
#[cfg_attr(target_os = "macos", link_name = "readdir$INODE64")]
615615
#[cfg_attr(target_os = "netbsd", link_name = "__readdir30")]
616616
#[cfg_attr(
617-
all(target_os = "freebsd", not(freebsd12)),
617+
all(target_os = "freebsd", freebsd11),
618618
link_name = "readdir@FBSD_1.0"
619619
)]
620620
pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent;
621621
#[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")]
622622
#[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")]
623623
#[cfg_attr(
624-
all(target_os = "freebsd", not(freebsd12)),
624+
all(target_os = "freebsd", freebsd11),
625625
link_name = "readdir_r@FBSD_1.0"
626626
)]
627627
/// The 64-bit libc on Solaris and illumos only has readdir_r. If a
@@ -653,7 +653,7 @@ extern {
653653
flags: ::c_int) -> ::c_int;
654654
#[cfg_attr(target_os = "macos", link_name = "fstatat$INODE64")]
655655
#[cfg_attr(
656-
all(target_os = "freebsd", not(freebsd12)),
656+
all(target_os = "freebsd", freebsd11),
657657
link_name = "fstatat@FBSD_1.1"
658658
)]
659659
pub fn fstatat(dirfd: ::c_int, pathname: *const ::c_char,
@@ -815,7 +815,7 @@ extern {
815815
#[cfg_attr(target_os = "macos", link_name = "lstat$INODE64")]
816816
#[cfg_attr(target_os = "netbsd", link_name = "__lstat50")]
817817
#[cfg_attr(
818-
all(target_os = "freebsd", not(freebsd12)),
818+
all(target_os = "freebsd", freebsd11),
819819
link_name = "lstat@FBSD_1.0"
820820
)]
821821
pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int;
@@ -992,7 +992,7 @@ extern {
992992

993993
#[cfg_attr(target_os = "netbsd", link_name = "__mknod50")]
994994
#[cfg_attr(
995-
all(target_os = "freebsd", not(freebsd12)),
995+
all(target_os = "freebsd", freebsd11),
996996
link_name = "mknod@FBSD_1.0"
997997
)]
998998
pub fn mknod(pathname: *const ::c_char, mode: ::mode_t,

0 commit comments

Comments
 (0)