Skip to content

add signal and raise bindings for windows #1176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(),

Expand Down Expand Up @@ -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,
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/windows/gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
14 changes: 14 additions & 0 deletions src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")))]
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion src/windows/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ extern {
#[link_name = "_strnicmp"]
pub fn strnicmp(s1: *const ::c_char, s2: *const ::c_char,
n: ::size_t) -> ::c_int;
}
}