Skip to content

Commit 676fbe7

Browse files
committed
links old version of cf{g,s}et{i,o}speed for glibc
1 parent 7726e8f commit 676fbe7

File tree

4 files changed

+533
-0
lines changed

4 files changed

+533
-0
lines changed

libc-test/build.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ fn do_cc() {
5454
{
5555
cc::Build::new().file("src/sigrt.c").compile("sigrt");
5656
}
57+
if target.contains("linux") && target.contains("gnu") {
58+
cc::Build::new().file("src/baud.c").compile("baud");
59+
}
5760
}
5861

5962
fn do_ctest() {
@@ -4784,6 +4787,30 @@ fn test_linux(target: &str) {
47844787
_ => false,
47854788
});
47864789

4790+
if gnu {
4791+
// old constants, so tests fail if glibc is too new
4792+
cfg.skip_const(|s| {
4793+
[
4794+
"B50", "B75", "B110", "B134", "B150", "B200", "B300", "B600", "B1200", "B1800",
4795+
"B2400", "B4800", "B9600", "B19200", "B38400", "EXTA", "EXTB", "B57600", "B115200",
4796+
"B230400", "B460800", "B500000", "B576000", "B921600", "B1000000", "B1152000",
4797+
"B1500000", "B2000000", "B2500000", "B3000000", "B3500000", "B4000000",
4798+
]
4799+
.contains(&s.ident())
4800+
});
4801+
// old symbols, so tests fail if glibc is too new
4802+
cfg.skip_fn_ptrcheck(|s| {
4803+
[
4804+
"cfgetispeed",
4805+
"cfgetospeed",
4806+
"cfsetispeed",
4807+
"cfsetospeed",
4808+
"cfsetspeed",
4809+
]
4810+
.contains(&s)
4811+
});
4812+
}
4813+
47874814
ctest::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
47884815

47894816
if !l4re {

libc-test/src/baud.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <termios.h>
2+
#include <unistd.h>
3+
4+
int cfsetspeed_b38400(struct termios *termios_p) {
5+
return cfsetspeed(termios_p, B38400);
6+
}

libc-test/tests/linux_gnu_baud.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#[cfg(all(target_os = "linux", target_env = "gnu"))]
2+
#[test]
3+
fn baud() {
4+
use libc::*;
5+
let controller_fd = unsafe { posix_openpt(O_RDWR | O_NOCTTY) };
6+
assert!(controller_fd >= 0);
7+
unsafe {
8+
grantpt(controller_fd);
9+
unlockpt(controller_fd);
10+
}
11+
let mut buffer = [0; 256];
12+
let ret = unsafe { ptsname_r(controller_fd, buffer.as_mut_ptr(), 256) };
13+
assert!(ret >= 0);
14+
let terminal_fd = unsafe { open(buffer.as_ptr(), O_RDWR | O_NOCTTY) };
15+
assert!(terminal_fd >= 0);
16+
let mut tio: termios = unsafe { std::mem::zeroed() };
17+
let ret = unsafe { tcgetattr(terminal_fd, &mut tio) };
18+
assert!(ret >= 0);
19+
assert_eq!(unsafe { cfgetispeed(&tio) }, B38400);
20+
assert_eq!(unsafe { cfgetospeed(&tio) }, B38400);
21+
let ret = unsafe { cfsetspeed(&mut tio, B1000000) };
22+
assert!(ret >= 0);
23+
assert_eq!(unsafe { cfgetispeed(&tio) }, B1000000);
24+
assert_eq!(unsafe { cfgetospeed(&tio) }, B1000000);
25+
let ret = unsafe { cfsetispeed(&mut tio, B9600) };
26+
assert!(ret >= 0);
27+
assert_eq!(unsafe { cfgetispeed(&tio) }, B9600);
28+
assert!(matches!(unsafe { cfgetospeed(&tio) }, B9600 | B1000000));
29+
let ret = unsafe { cfsetospeed(&mut tio, B19200) };
30+
assert!(ret >= 0);
31+
assert!(matches!(unsafe { cfgetispeed(&tio) }, B9600 | B19200));
32+
assert_eq!(unsafe { cfgetospeed(&tio) }, B19200);
33+
unsafe extern "C" {
34+
unsafe fn cfsetspeed_b38400(termios: *mut termios) -> c_int;
35+
}
36+
let ret = unsafe { cfsetspeed_b38400(&mut tio) };
37+
assert!(ret >= 0);
38+
assert_eq!(unsafe { cfgetispeed(&tio) }, B38400);
39+
assert_eq!(unsafe { cfgetospeed(&tio) }, B38400);
40+
}

0 commit comments

Comments
 (0)