Skip to content

Commit 1091d56

Browse files
committed
Add gettid
1 parent 3f0c3e1 commit 1091d56

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ preadv_pwritev = []
2020
signalfd = []
2121

2222
[dependencies]
23-
libc = "0.2.7"
23+
libc = "0.2.8"
2424
bitflags = "0.4"
2525
cfg-if = "0.1.0"
2626

src/unistd.rs

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ pub fn setpgid(pid: pid_t, pgid: pid_t) -> Result<()> {
5656
Errno::result(res).map(drop)
5757
}
5858

59+
#[cfg(target_os = "linux", target_os = "android")]
60+
#[inline]
61+
pub fn gettid() -> pid_t {
62+
unsafe { libc::syscall(libc::SYS_gettid) as pid_t } // no error handling, according to man page: "These functions are always successful."
63+
}
64+
5965
#[inline]
6066
pub fn dup(oldfd: RawFd) -> Result<RawFd> {
6167
let res = unsafe { libc::dup(oldfd) };

test/test_unistd.rs

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ fn test_getpid() {
5454
assert!(ppid > 0);
5555
}
5656

57+
#[cfg(target_os = "linux", target_os = "android")]
58+
#[test]
59+
fn test_gettid() {
60+
let tid = gettid();
61+
assert!(tid > 0);
62+
}
63+
5764
macro_rules! execve_test_factory(
5865
($test_name:ident, $syscall:ident, $unix_sh:expr, $android_sh:expr) => (
5966
#[test]

0 commit comments

Comments
 (0)