-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "c-nix" | ||
version = "0.1.0" | ||
authors = ["Dave Hylands <dhylands@gmail.com>"] | ||
build = "build.rs" | ||
|
||
[dependencies] | ||
libc = "0.2.7" | ||
|
||
[build-dependencies] | ||
gcc = "0.3.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extern crate gcc; | ||
|
||
fn main() { | ||
let mut c = gcc::Config::new(); | ||
let config = c.file("c-src/gettid.c") | ||
.cpp(false); | ||
|
||
config.compile("libc-nix.a"); | ||
println!("cargo:rustc-flags=-l c-nix"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <sys/syscall.h> | ||
|
||
// SYS_gettid has different values on different platforms, so we let the | ||
// C preprocessor figure things out for us. | ||
|
||
int c_gettid(void) { | ||
#if defined(__APPLE__) | ||
return syscall(SYS_thread_selfid); | ||
#else | ||
return syscall(SYS_gettid); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
extern crate libc; | ||
|
||
extern { | ||
pub fn c_gettid() -> libc::pid_t; | ||
} | ||
|
||
pub fn gettid() -> libc::pid_t { | ||
unsafe { c_gettid() } | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
#[test] | ||
fn it_works() { | ||
println!("gettid() = {}", gettid()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters