diff options
author | bors <bors@rust-lang.org> | 2018-12-18 05:15:39 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2018-12-18 05:15:39 +0000 |
commit | 027d4834615cf8bce3faa9c4a1c2706413a7b275 (patch) | |
tree | 1dd25c97baae6a80b221e0c1a6a923059b3f21e6 | |
parent | 8b63b1cfb016ae70f0deec33b9d7d20395ec2988 (diff) | |
parent | af19934f292ddd230f99dae52faf29c83cf8bb37 (diff) | |
download | rust-libc-027d4834615cf8bce3faa9c4a1c2706413a7b275.tar.gz |
Auto merge of #1176 - xmclark:add-signal-and-raise-windows, r=alexcrichton
add signal and raise bindings for windows
This PR adds `signal` and `raise` bindings for windows.
I don't know these functions or linux very well, so I leaned on other overrides of signal in the linux bindings, and the [cppreference page](https://en.cppreference.com/w/cpp/header/csignal) for adding the bindings.
I added some constants that were shown on the [microsoft signal page](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=vs-2017) and used the default values I found spelunking through my own copy of `signal.h` that came along with visual studio.
The automated tests pass and my toy apps use the `signal` and `raise` as expected. Let me know if there is anything else I need to do, or any extra tests to write.
EDIT:
currently working on getting a nice isolated msys2 environment I can use to dev against.
- [x] msys2 env setup and building
-rw-r--r-- | libc-test/build.rs | 6 | ||||
-rw-r--r-- | src/windows/gnu.rs | 2 | ||||
-rw-r--r-- | src/windows/mod.rs | 14 | ||||
-rw-r--r-- | src/windows/msvc.rs | 2 |
4 files changed, 21 insertions, 3 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs index e6c9c7907d..ffab452301 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -76,6 +76,7 @@ fn main() { cfg.header("windows.h"); cfg.header("process.h"); cfg.header("ws2ipdef.h"); + cfg.header("signal.h"); if target.contains("gnu") { cfg.header("ws2tcpip.h"); @@ -372,7 +373,9 @@ fn main() { // Fixup a few types on windows that don't actually exist. "time64_t" if windows => "__time64_t".to_string(), "ssize_t" if windows => "SSIZE_T".to_string(), - + // windows + "sighandler_t" if windows && !mingw => "_crt_signal_t".to_string(), + "sighandler_t" if windows && mingw => "__p_sig_fn_t".to_string(), // OSX calls this something else "sighandler_t" if bsdlike => "sig_t".to_string(), @@ -507,6 +510,7 @@ fn main() { n if n.starts_with("P") => true, n if n.starts_with("H") => true, n if n.starts_with("LP") => true, + "__p_sig_fn_t" if mingw => true, _ => false, } }); diff --git a/src/windows/gnu.rs b/src/windows/gnu.rs index a67af15a8f..3568f6226e 100644 --- a/src/windows/gnu.rs +++ b/src/windows/gnu.rs @@ -4,5 +4,5 @@ pub const TMP_MAX: ::c_uint = 0x7fff; extern { pub fn strcasecmp(s1: *const ::c_char, s2: *const ::c_char) -> ::c_int; pub fn strncasecmp(s1: *const ::c_char, s2: *const ::c_char, - n: ::size_t) -> ::c_int; + n: ::size_t) -> ::c_int; } diff --git a/src/windows/mod.rs b/src/windows/mod.rs index f46eb362d8..e4db343ec2 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -27,6 +27,7 @@ pub type ptrdiff_t = isize; pub type intptr_t = isize; pub type uintptr_t = usize; pub type ssize_t = isize; +pub type sighandler_t = usize; pub type c_char = i8; pub type c_long = i32; @@ -177,6 +178,16 @@ pub const ENOTEMPTY: ::c_int = 41; pub const EILSEQ: ::c_int = 42; pub const STRUNCATE: ::c_int = 80; +// signal codes +pub const SIGINT: ::c_int = 2; +pub const SIGILL: ::c_int = 4; +pub const SIGFPE: ::c_int = 8; +pub const SIGSEGV: ::c_int = 11; +pub const SIGTERM: ::c_int = 15; +pub const SIGABRT: ::c_int = 22; +pub const NSIG: ::c_int = 23; +pub const SIG_ERR: ::c_int = -1; + // inline comment below appeases style checker #[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))] // " if " #[link(name = "msvcrt", cfg(not(target_feature = "crt-static")))] @@ -287,6 +298,9 @@ extern { pub fn rand() -> c_int; pub fn srand(seed: c_uint); + pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t; + pub fn raise(signum: c_int) -> c_int; + #[link_name = "_chmod"] pub fn chmod(path: *const c_char, mode: ::c_int) -> ::c_int; #[link_name = "_wchmod"] diff --git a/src/windows/msvc.rs b/src/windows/msvc.rs index 9e2a9b9e5d..1ebfcadd16 100644 --- a/src/windows/msvc.rs +++ b/src/windows/msvc.rs @@ -7,4 +7,4 @@ extern { #[link_name = "_strnicmp"] pub fn strnicmp(s1: *const ::c_char, s2: *const ::c_char, n: ::size_t) -> ::c_int; -}
\ No newline at end of file +} |