Skip to content

Commit 9ae6227

Browse files
committed
Auto merge of rust-lang#310 - nrc:WIF, r=alexcrichton
Add more constants from sys/wait.h And fix WIFEXITED on Linux, which seemed to be wrong.
2 parents d1f4c2d + 8c15a36 commit 9ae6227

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,20 @@ pub const TIOCSWINSZ: ::c_ulong = 0x80087467;
685685

686686
pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;
687687

688+
f! {
689+
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
690+
status >> 8
691+
}
692+
693+
pub fn WIFSIGNALED(status: ::c_int) -> bool {
694+
(status & 0o177) != 0o177 && (status & 0o177) != 0
695+
}
696+
697+
pub fn WIFSTOPPED(status: ::c_int) -> bool {
698+
(status & 0o177) == 0o177
699+
}
700+
}
701+
688702
#[link(name = "util")]
689703
extern {
690704
pub fn getnameinfo(sa: *const ::sockaddr,

src/unix/bsd/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,18 +324,18 @@ f! {
324324
}
325325
}
326326

327+
pub fn WTERMSIG(status: ::c_int) -> ::c_int {
328+
status & 0o177
329+
}
330+
327331
pub fn WIFEXITED(status: ::c_int) -> bool {
328-
(status & 0x7f) == 0
332+
(status & 0o177) == 0
329333
}
330334

331335
pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
332336
status >> 8
333337
}
334338

335-
pub fn WTERMSIG(status: ::c_int) -> ::c_int {
336-
status & 0o177
337-
}
338-
339339
pub fn WCOREDUMP(status: ::c_int) -> bool {
340340
(status & 0o200) != 0
341341
}

src/unix/bsd/openbsdlike/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,20 @@ pub const HW_NCPU: ::c_int = 3;
449449

450450
pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;
451451

452+
f! {
453+
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
454+
status >> 8
455+
}
456+
457+
pub fn WIFSIGNALED(status: ::c_int) -> bool {
458+
(status & 0o177) != 0o177 && (status & 0o177) != 0
459+
}
460+
461+
pub fn WIFSTOPPED(status: ::c_int) -> bool {
462+
(status & 0o177) == 0o177
463+
}
464+
}
465+
452466
#[link(name = "util")]
453467
extern {
454468
pub fn mincore(addr: *mut ::c_void, len: ::size_t,

src/unix/notbsd/mod.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,17 +682,33 @@ f! {
682682
}
683683
}
684684

685-
pub fn WIFEXITED(status: ::c_int) -> bool {
686-
(status & 0xff) == 0
685+
pub fn WIFSTOPPED(status: ::c_int) -> bool {
686+
(status & 0xff) == 0x7f
687687
}
688688

689-
pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
689+
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
690690
(status >> 8) & 0xff
691691
}
692692

693+
pub fn WIFSIGNALED(status: ::c_int) -> bool {
694+
(status & 0x7f) + 1 >= 2
695+
}
696+
693697
pub fn WTERMSIG(status: ::c_int) -> ::c_int {
694698
status & 0x7f
695699
}
700+
701+
pub fn WIFEXITED(status: ::c_int) -> bool {
702+
(status & 0x7f) == 0
703+
}
704+
705+
pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
706+
(status >> 8) & 0xff
707+
}
708+
709+
pub fn WCOREDUMP(status: ::c_int) -> bool {
710+
(status & 0x80) != 0
711+
}
696712
}
697713

698714
extern {

0 commit comments

Comments
 (0)