Skip to content

Commit

Permalink
Add gettid
Browse files Browse the repository at this point in the history
  • Loading branch information
dhylands committed Mar 8, 2016
1 parent 3f0c3e1 commit 7814167
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ preadv_pwritev = []
signalfd = []

[dependencies]
libc = "0.2.7"
libc = "0.2.8"
bitflags = "0.4"
cfg-if = "0.1.0"

Expand Down
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 pid_t } // 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 7814167

Please sign in to comment.