Skip to content

Commit eba21f4

Browse files
committed
unix: Add openpty(3) and forkpty(3) for non-Apple platforms
The functions were added for Apple in #202. Adding them to other platforms was pending an amendment to RFC 1291 to expand the scope of libc to include libutil. The amendment was merged as rust-lang/rfcs#1529
1 parent 334b106 commit eba21f4

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

libc-test/build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ fn main() {
129129

130130
if bsdlike {
131131
cfg.header("sys/event.h");
132+
133+
if freebsd {
134+
cfg.header("libutil.h");
135+
} else {
136+
cfg.header("util.h");
137+
}
132138
}
133139

134140
if linux {
@@ -138,6 +144,7 @@ fn main() {
138144
cfg.header("sys/xattr.h");
139145
cfg.header("sys/ipc.h");
140146
cfg.header("sys/shm.h");
147+
cfg.header("pty.h");
141148
}
142149

143150
if linux || android {

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,19 @@ extern {
592592
info: *mut siginfo_t) -> ::c_int;
593593
}
594594

595+
#[link(name = "util")]
596+
extern "C" {
597+
pub fn openpty(amaster: *mut ::c_int,
598+
aslave: *mut ::c_int,
599+
name: *mut ::c_char,
600+
termp: *mut termios,
601+
winp: *mut ::winsize) -> ::c_int;
602+
pub fn forkpty(amaster: *mut ::c_int,
603+
name: *mut ::c_char,
604+
termp: *mut termios,
605+
winp: *mut ::winsize) -> ::pid_t;
606+
}
607+
595608
cfg_if! {
596609
if #[cfg(target_os = "freebsd")] {
597610
mod freebsd;

src/unix/bsd/openbsdlike/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,19 @@ extern {
395395
pub fn fdatasync(fd: ::c_int) -> ::c_int;
396396
}
397397

398+
#[link(name = "util")]
399+
extern "C" {
400+
pub fn openpty(amaster: *mut ::c_int,
401+
aslave: *mut ::c_int,
402+
name: *mut ::c_char,
403+
termp: *mut termios,
404+
winp: *mut ::winsize) -> ::c_int;
405+
pub fn forkpty(amaster: *mut ::c_int,
406+
name: *mut ::c_char,
407+
termp: *mut termios,
408+
winp: *mut ::winsize) -> ::pid_t;
409+
}
410+
398411
cfg_if! {
399412
if #[cfg(target_os = "bitrig")] {
400413
mod bitrig;

src/unix/notbsd/linux/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,19 @@ extern {
533533
info: *mut siginfo_t) -> ::c_int;
534534
}
535535

536+
#[link(name = "util")]
537+
extern "C" {
538+
pub fn openpty(amaster: *mut ::c_int,
539+
aslave: *mut ::c_int,
540+
name: *mut ::c_char,
541+
termp: *const termios,
542+
winp: *const ::winsize) -> ::c_int;
543+
pub fn forkpty(amaster: *mut ::c_int,
544+
name: *mut ::c_char,
545+
termp: *const termios,
546+
winp: *const ::winsize) -> ::pid_t;
547+
}
548+
536549
cfg_if! {
537550
if #[cfg(any(target_env = "musl",
538551
target_os = "emscripten"))] {

0 commit comments

Comments
 (0)