MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / openpty_get_peer

Function openpty_get_peer

tests/pty/openpty.rs:69–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67#[cfg(target_os = "linux")]
68#[test]
69fn openpty_get_peer() {
70 // Use `CLOEXEC` if we can.
71 #[cfg(any(linux_kernel, target_os = "freebsd", target_os = "netbsd"))]
72 let flags = OpenptFlags::RDWR | OpenptFlags::NOCTTY | OpenptFlags::CLOEXEC;
73 #[cfg(not(any(linux_kernel, target_os = "freebsd", target_os = "netbsd")))]
74 let flags = OpenptFlags::RDWR | OpenptFlags::NOCTTY;
75
76 let controller = openpt(flags).unwrap();
77
78 grantpt(&controller).unwrap();
79 unlockpt(&controller).unwrap();
80
81 let user = ioctl_tiocgptpeer(
82 &controller,
83 OpenptFlags::RDWR | OpenptFlags::NOCTTY | OpenptFlags::CLOEXEC,
84 )
85 .unwrap();
86
87 let mut controller = File::from(controller);
88 let mut user = File::from(user);
89
90 // The `'\x04'` is Ctrl-D, the default EOF control code.
91 controller.write_all(b"Hello, world!\n\x04").unwrap();
92
93 let mut s = String::new();
94
95 // Read the string back. Our `\x04` above ended the stream, so we can
96 // read to the end of the stream.
97 user.read_to_string(&mut s).unwrap();
98
99 assert_eq!(s, "Hello, world!\n");
100}

Callers

nothing calls this directly

Calls 4

ioctl_tiocgptpeerFunction · 0.85
openptFunction · 0.50
grantptFunction · 0.50
unlockptFunction · 0.50

Tested by

no test coverage detected