@@ -6,6 +6,7 @@ export run_program;
6
6
export start_program;
7
7
export program_output;
8
8
export spawn_process;
9
+ export waitpid;
9
10
10
11
native "rust" mod rustrt {
11
12
fn rust_run_program ( argv : * sbuf , in_fd : int , out_fd : int , err_fd : int ) ->
@@ -33,7 +34,7 @@ fn spawn_process(prog: &str, args: &[str], in_fd: int, out_fd: int,
33
34
}
34
35
35
36
fn run_program ( prog : & str , args : & [ str ] ) -> int {
36
- ret os :: waitpid ( spawn_process ( prog, args, 0 , 0 , 0 ) ) ;
37
+ ret waitpid ( spawn_process ( prog, args, 0 , 0 , 0 ) ) ;
37
38
}
38
39
39
40
type program =
@@ -87,7 +88,7 @@ fn start_program(prog: &str, args: &[str]) -> @program_res {
87
88
if finished { ret 0 ; }
88
89
finished = true ;
89
90
self . close_input ( ) ;
90
- ret os :: waitpid ( pid) ;
91
+ ret waitpid( pid) ;
91
92
}
92
93
fn destroy ( ) {
93
94
self . finish ( ) ;
@@ -117,6 +118,44 @@ fn program_output(prog: &str, args: &[str]) ->
117
118
out : read_all ( pr. output ( ) ) ,
118
119
err : read_all ( pr. err ( ) ) } ;
119
120
}
121
+
122
+ /* Returns an exit status */
123
+ #[ cfg( target_os = "win32" ) ]
124
+ fn waitpid ( pid : int ) -> int {
125
+ os:: waitpid ( pid)
126
+ }
127
+
128
+ #[ cfg( target_os = "linux" ) ]
129
+ #[ cfg( target_os = "macos" ) ]
130
+ fn waitpid ( pid : int ) -> int {
131
+ #[ cfg( target_os = "linux" ) ]
132
+ fn WIFEXITED ( status : int ) -> bool {
133
+ ( status & 0xff ) == 0
134
+ }
135
+
136
+ #[ cfg( target_os = "macos" ) ]
137
+ fn WIFEXITED ( status : int ) -> bool {
138
+ ( status & 0x7f ) == 0
139
+ }
140
+
141
+ #[ cfg( target_os = "linux" ) ]
142
+ fn WEXITSTATUS ( status : int ) -> int {
143
+ ( status >> 8 ) & 0xff
144
+ }
145
+
146
+ #[ cfg( target_os = "macos" ) ]
147
+ fn WEXITSTATUS ( status : int ) -> int {
148
+ status >> 8
149
+ }
150
+
151
+ let status = os:: waitpid ( pid) ;
152
+ ret if WIFEXITED ( status) {
153
+ WEXITSTATUS ( status)
154
+ } else {
155
+ 1
156
+ } ;
157
+ }
158
+
120
159
// Local Variables:
121
160
// mode: rust
122
161
// fill-column: 78;
0 commit comments