Skip to content

Commit bf8ce97

Browse files
committed
Auto merge of #451 - zethra:master, r=kamalmarhubi
Added tcgetpgrp and tcsetpgrp I added the tcgetpgrp and tcsetpgrp functions. I'm not sure if I did everything right so please tell me if I need to change anything.
2 parents f8d4c31 + 013e7c8 commit bf8ce97

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1616
([#448](https://github.com/nix-rust/nix/pull/448))
1717
- Added `getpgid` in `::nix::unistd`
1818
([#433](https://github.com/nix-rust/nix/pull/433))
19+
- Added `tcgetpgrp` and `tcsetpgrp` in `::nix::unistd`
20+
([#451](https://github.com/nix-rust/nix/pull/451))
1921

2022
### Changed
2123
- The minimum supported version of rustc is now 1.7.0.

src/unistd.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ pub fn setsid() -> Result<pid_t> {
129129
Errno::result(unsafe { libc::setsid() })
130130
}
131131

132+
133+
/// Get the terminal foreground process group (see
134+
/// [tcgetpgrp(3)](http://man7.org/linux/man-pages/man3/tcgetpgrp.3.html)).
135+
///
136+
/// Get the group process id (GPID) of the foreground process group on the
137+
/// terminal associated to file descriptor (FD).
138+
#[inline]
139+
pub fn tcgetgrp(fd: c_int) -> Result<pid_t> {
140+
let res = unsafe { libc::tcgetpgrp(fd) };
141+
Errno::result(res)
142+
}
143+
/// Set the terminal foreground process group (see
144+
/// [tcgetpgrp(3)](http://man7.org/linux/man-pages/man3/tcgetpgrp.3.html)).
145+
///
146+
/// Get the group process id (PGID) to the foreground process group on the
147+
/// terminal associated to file descriptor (FD).
148+
#[inline]
149+
pub fn tcsetpgrp(fd: c_int, pgrp: pid_t) -> Result<()> {
150+
let res = unsafe { libc::tcsetpgrp(fd, pgrp) };
151+
Errno::result(res).map(drop)
152+
}
153+
132154
/// Get the caller's thread ID (see
133155
/// [gettid(2)](http://man7.org/linux/man-pages/man2/gettid.2.html).
134156
///

0 commit comments

Comments
 (0)