Skip to content

Commit f288e18

Browse files
committed
Auto merge of #246 - kamalmarhubi:openpty, r=alexcrichton
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
2 parents dfc1ab5 + 9c4af10 commit f288e18

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

libc-test/build.rs

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

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

135141
if linux {
@@ -139,6 +145,7 @@ fn main() {
139145
cfg.header("sys/xattr.h");
140146
cfg.header("sys/ipc.h");
141147
cfg.header("sys/shm.h");
148+
cfg.header("pty.h");
142149
}
143150

144151
if linux || android {

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ pub const RTLD_NODELETE: ::c_int = 0x1000;
568568
pub const RTLD_NOLOAD: ::c_int = 0x2000;
569569
pub const RTLD_GLOBAL: ::c_int = 0x100;
570570

571+
#[link(name = "util")]
571572
extern {
572573
pub fn getnameinfo(sa: *const ::sockaddr,
573574
salen: ::socklen_t,
@@ -617,6 +618,15 @@ extern {
617618
timeout: *const ::timespec) -> ::c_int;
618619
pub fn sigwaitinfo(set: *const sigset_t,
619620
info: *mut siginfo_t) -> ::c_int;
621+
pub fn openpty(amaster: *mut ::c_int,
622+
aslave: *mut ::c_int,
623+
name: *mut ::c_char,
624+
termp: *mut termios,
625+
winp: *mut ::winsize) -> ::c_int;
626+
pub fn forkpty(amaster: *mut ::c_int,
627+
name: *mut ::c_char,
628+
termp: *mut termios,
629+
winp: *mut ::winsize) -> ::pid_t;
620630
}
621631

622632
cfg_if! {

src/unix/bsd/openbsdlike/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ pub const Q_SETQUOTA: ::c_int = 0x400;
376376

377377
pub const RTLD_GLOBAL: ::c_int = 0x100;
378378

379+
#[link(name = "util")]
379380
extern {
380381
pub fn mincore(addr: *mut ::c_void, len: ::size_t,
381382
vec: *mut ::c_char) -> ::c_int;
@@ -393,6 +394,15 @@ extern {
393394
flags: ::c_int) -> ::c_int;
394395
pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int;
395396
pub fn fdatasync(fd: ::c_int) -> ::c_int;
397+
pub fn openpty(amaster: *mut ::c_int,
398+
aslave: *mut ::c_int,
399+
name: *mut ::c_char,
400+
termp: *mut termios,
401+
winp: *mut ::winsize) -> ::c_int;
402+
pub fn forkpty(amaster: *mut ::c_int,
403+
name: *mut ::c_char,
404+
termp: *mut termios,
405+
winp: *mut ::winsize) -> ::pid_t;
396406
}
397407

398408
cfg_if! {

src/unix/notbsd/linux/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ f! {
398398
}
399399
}
400400

401+
#[link(name = "util")]
401402
extern {
402403
pub fn shm_open(name: *const c_char, oflag: ::c_int,
403404
mode: mode_t) -> ::c_int;
@@ -531,6 +532,15 @@ extern {
531532
timeout: *const ::timespec) -> ::c_int;
532533
pub fn sigwaitinfo(set: *const sigset_t,
533534
info: *mut siginfo_t) -> ::c_int;
535+
pub fn openpty(amaster: *mut ::c_int,
536+
aslave: *mut ::c_int,
537+
name: *mut ::c_char,
538+
termp: *const termios,
539+
winp: *const ::winsize) -> ::c_int;
540+
pub fn forkpty(amaster: *mut ::c_int,
541+
name: *mut ::c_char,
542+
termp: *const termios,
543+
winp: *const ::winsize) -> ::pid_t;
534544
}
535545

536546
cfg_if! {

0 commit comments

Comments
 (0)