@@ -54,7 +54,7 @@ func posixPipe() -> (readFD: CInt, writeFD: CInt) {
54
54
( fds) in
55
55
let ptr = fds. baseAddress
56
56
if pipe ( ptr) != 0 {
57
- requirementFailure ( " pipe() failed " )
57
+ preconditionFailure ( " pipe() failed " )
58
58
}
59
59
}
60
60
return ( fds [ 0 ] , fds [ 1 ] )
@@ -66,46 +66,46 @@ public func spawnChild(args: [String])
66
66
-> ( pid: pid_t , stdinFD: CInt , stdoutFD: CInt , stderrFD: CInt ) {
67
67
var fileActions : posix_spawn_file_actions_t = nil
68
68
if swift_posix_spawn_file_actions_init ( & fileActions) != 0 {
69
- requirementFailure ( " swift_posix_spawn_file_actions_init() failed " )
69
+ preconditionFailure ( " swift_posix_spawn_file_actions_init() failed " )
70
70
}
71
71
72
72
let childStdin = posixPipe ( )
73
73
// Close the write end of the pipe on the child side.
74
74
if swift_posix_spawn_file_actions_addclose (
75
75
& fileActions, childStdin. writeFD) != 0 {
76
- requirementFailure ( " swift_posix_spawn_file_actions_addclose() failed " )
76
+ preconditionFailure ( " swift_posix_spawn_file_actions_addclose() failed " )
77
77
}
78
78
79
79
// Remap child's stdin.
80
80
if swift_posix_spawn_file_actions_adddup2 (
81
81
& fileActions, childStdin. readFD, STDIN_FILENO) != 0 {
82
- requirementFailure ( " swift_posix_spawn_file_actions_adddup2() failed " )
82
+ preconditionFailure ( " swift_posix_spawn_file_actions_adddup2() failed " )
83
83
}
84
84
85
85
let childStdout = posixPipe ( )
86
86
// Close the read end of the pipe on the child side.
87
87
if swift_posix_spawn_file_actions_addclose (
88
88
& fileActions, childStdout. readFD) != 0 {
89
- requirementFailure ( " swift_posix_spawn_file_actions_addclose() failed " )
89
+ preconditionFailure ( " swift_posix_spawn_file_actions_addclose() failed " )
90
90
}
91
91
92
92
// Remap child's stdout.
93
93
if swift_posix_spawn_file_actions_adddup2 (
94
94
& fileActions, childStdout. writeFD, STDOUT_FILENO) != 0 {
95
- requirementFailure ( " swift_posix_spawn_file_actions_adddup2() failed " )
95
+ preconditionFailure ( " swift_posix_spawn_file_actions_adddup2() failed " )
96
96
}
97
97
98
98
let childStderr = posixPipe ( )
99
99
// Close the read end of the pipe on the child side.
100
100
if swift_posix_spawn_file_actions_addclose (
101
101
& fileActions, childStderr. readFD) != 0 {
102
- requirementFailure ( " swift_posix_spawn_file_actions_addclose() failed " )
102
+ preconditionFailure ( " swift_posix_spawn_file_actions_addclose() failed " )
103
103
}
104
104
105
105
// Remap child's stderr.
106
106
if swift_posix_spawn_file_actions_adddup2 (
107
107
& fileActions, childStderr. writeFD, STDERR_FILENO) != 0 {
108
- requirementFailure ( " swift_posix_spawn_file_actions_adddup2() failed " )
108
+ preconditionFailure ( " swift_posix_spawn_file_actions_adddup2() failed " )
109
109
}
110
110
111
111
var pid : pid_t = - 1
@@ -115,26 +115,26 @@ public func spawnChild(args: [String])
115
115
}
116
116
if spawnResult != 0 {
117
117
print ( String ( cString: strerror ( spawnResult) ) )
118
- requirementFailure ( " swift_posix_spawn() failed " )
118
+ preconditionFailure ( " swift_posix_spawn() failed " )
119
119
}
120
120
121
121
if swift_posix_spawn_file_actions_destroy ( & fileActions) != 0 {
122
- requirementFailure ( " swift_posix_spawn_file_actions_destroy() failed " )
122
+ preconditionFailure ( " swift_posix_spawn_file_actions_destroy() failed " )
123
123
}
124
124
125
125
// Close the read end of the pipe on the parent side.
126
126
if close ( childStdin. readFD) != 0 {
127
- requirementFailure ( " close() failed " )
127
+ preconditionFailure ( " close() failed " )
128
128
}
129
129
130
130
// Close the write end of the pipe on the parent side.
131
131
if close ( childStdout. writeFD) != 0 {
132
- requirementFailure ( " close() failed " )
132
+ preconditionFailure ( " close() failed " )
133
133
}
134
134
135
135
// Close the write end of the pipe on the parent side.
136
136
if close ( childStderr. writeFD) != 0 {
137
- requirementFailure ( " close() failed " )
137
+ preconditionFailure ( " close() failed " )
138
138
}
139
139
140
140
return ( pid, childStdin. writeFD, childStdout. readFD, childStderr. readFD)
@@ -156,7 +156,7 @@ internal func _readAll(fd: CInt) -> String {
156
156
if readResult == 0 {
157
157
break
158
158
}
159
- requirementFailure ( " read() failed " )
159
+ preconditionFailure ( " read() failed " )
160
160
}
161
161
return String . _fromCodeUnitSequenceWithRepair (
162
162
UTF8 . self, input: buffer [ 0 ..< usedBytes] ) . 0
@@ -193,15 +193,15 @@ public enum ProcessTerminationStatus : CustomStringConvertible {
193
193
public func posixWaitpid( pid: pid_t ) -> ProcessTerminationStatus {
194
194
var status : CInt = 0
195
195
if waitpid ( pid, & status, 0 ) < 0 {
196
- requirementFailure ( " waitpid() failed " )
196
+ preconditionFailure ( " waitpid() failed " )
197
197
}
198
198
if ( WIFEXITED ( status) ) {
199
199
return . Exit( Int ( WEXITSTATUS ( status) ) )
200
200
}
201
201
if ( WIFSIGNALED ( status) ) {
202
202
return . Signal( Int ( WTERMSIG ( status) ) )
203
203
}
204
- requirementFailure ( " did not understand what happened to child process " )
204
+ preconditionFailure ( " did not understand what happened to child process " )
205
205
}
206
206
207
207
public func runChild( args: [ String ] )
@@ -215,10 +215,10 @@ public func runChild(args: [String])
215
215
let stderr = _readAll ( stderrFD)
216
216
217
217
if close ( stdoutFD) != 0 {
218
- requirementFailure ( " close() failed " )
218
+ preconditionFailure ( " close() failed " )
219
219
}
220
220
if close ( stderrFD) != 0 {
221
- requirementFailure ( " close() failed " )
221
+ preconditionFailure ( " close() failed " )
222
222
}
223
223
let status = posixWaitpid ( pid)
224
224
return ( stdout, stderr, status)
0 commit comments