Skip to content

Commit

Permalink
Add gettid
Browse files Browse the repository at this point in the history
  • Loading branch information
dhylands committed Mar 6, 2016
1 parent 3f0c3e1 commit 8a2f0db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ pub fn setpgid(pid: pid_t, pgid: pid_t) -> Result<()> {
Errno::result(res).map(drop)
}

#[cfg(target_os = "linux")]
#[inline]
pub fn gettid() -> pid_t {
unsafe { libc::syscall(libc::SYS_gettid) as i32 } // no error handling, according to man page: "These functions are always successful."
}

#[inline]
pub fn dup(oldfd: RawFd) -> Result<RawFd> {
let res = unsafe { libc::dup(oldfd) };
Expand Down
7 changes: 7 additions & 0 deletions test/test_unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ fn test_getpid() {
assert!(ppid > 0);
}

#[cfg(target_os = "linux")]
#[test]
fn test_gettid() {
let tid = gettid();
assert!(tid > 0);
}

macro_rules! execve_test_factory(
($test_name:ident, $syscall:ident, $unix_sh:expr, $android_sh:expr) => (
#[test]
Expand Down

0 comments on commit 8a2f0db

Please sign in to comment.