Skip to content

Commit dd7a939

Browse files
committed
links old version of cf{g,s}et{i,o}speed for glibc
1 parent c24866a commit dd7a939

File tree

4 files changed

+534
-0
lines changed

4 files changed

+534
-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() {
@@ -4853,6 +4856,30 @@ fn test_linux(target: &str) {
48534856
});
48544857
}
48554858

4859+
if gnu {
4860+
// old constants, so tests fail if glibc is too new
4861+
cfg.skip_const(|s| {
4862+
[
4863+
"B50", "B75", "B110", "B134", "B150", "B200", "B300", "B600", "B1200", "B1800",
4864+
"B2400", "B4800", "B9600", "B19200", "B38400", "EXTA", "EXTB", "B57600", "B115200",
4865+
"B230400", "B460800", "B500000", "B576000", "B921600", "B1000000", "B1152000",
4866+
"B1500000", "B2000000", "B2500000", "B3000000", "B3500000", "B4000000",
4867+
]
4868+
.contains(&s.ident())
4869+
});
4870+
// old symbols, so tests fail if glibc is too new
4871+
cfg.skip_fn_ptrcheck(|s| {
4872+
[
4873+
"cfgetispeed",
4874+
"cfgetospeed",
4875+
"cfsetispeed",
4876+
"cfsetospeed",
4877+
"cfsetspeed",
4878+
]
4879+
.contains(&s)
4880+
});
4881+
}
4882+
48564883
ctest::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
48574884

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

0 commit comments

Comments
 (0)