@@ -23,43 +23,43 @@ import Glibc
23
23
// posix_spawn is not available on Android.
24
24
// posix_spawn is not available on Haiku.
25
25
#if !os(Android) && !os(Haiku)
26
- // swift_posix_spawn isn't available in the public watchOS SDK, we sneak by the
26
+ // posix_spawn isn't available in the public watchOS SDK, we sneak by the
27
27
// unavailable attribute declaration here of the APIs that we need.
28
28
29
29
// FIXME: Come up with a better way to deal with APIs that are pointers on some
30
30
// platforms but not others.
31
31
#if os(Linux)
32
- typealias swift_posix_spawn_file_actions_t = posix_spawn_file_actions_t
32
+ typealias _stdlib_posix_spawn_file_actions_t = posix_spawn_file_actions_t
33
33
#else
34
- typealias swift_posix_spawn_file_actions_t = posix_spawn_file_actions_t ?
34
+ typealias _stdlib_posix_spawn_file_actions_t = posix_spawn_file_actions_t ?
35
35
#endif
36
36
37
- @_silgen_name ( " swift_posix_spawn_file_actions_init " )
38
- func swift_posix_spawn_file_actions_init (
39
- _ file_actions: UnsafeMutablePointer < swift_posix_spawn_file_actions_t >
37
+ @_silgen_name ( " _stdlib_posix_spawn_file_actions_init " )
38
+ internal func _stdlib_posix_spawn_file_actions_init (
39
+ _ file_actions: UnsafeMutablePointer < _stdlib_posix_spawn_file_actions_t >
40
40
) -> CInt
41
41
42
- @_silgen_name ( " swift_posix_spawn_file_actions_destroy " )
43
- func swift_posix_spawn_file_actions_destroy (
44
- _ file_actions: UnsafeMutablePointer < swift_posix_spawn_file_actions_t >
42
+ @_silgen_name ( " _stdlib_posix_spawn_file_actions_destroy " )
43
+ internal func _stdlib_posix_spawn_file_actions_destroy (
44
+ _ file_actions: UnsafeMutablePointer < _stdlib_posix_spawn_file_actions_t >
45
45
) -> CInt
46
46
47
- @_silgen_name ( " swift_posix_spawn_file_actions_addclose " )
48
- func swift_posix_spawn_file_actions_addclose (
49
- _ file_actions: UnsafeMutablePointer < swift_posix_spawn_file_actions_t > ,
47
+ @_silgen_name ( " _stdlib_posix_spawn_file_actions_addclose " )
48
+ internal func _stdlib_posix_spawn_file_actions_addclose (
49
+ _ file_actions: UnsafeMutablePointer < _stdlib_posix_spawn_file_actions_t > ,
50
50
_ filedes: CInt ) -> CInt
51
51
52
- @_silgen_name ( " swift_posix_spawn_file_actions_adddup2 " )
53
- func swift_posix_spawn_file_actions_adddup2 (
54
- _ file_actions: UnsafeMutablePointer < swift_posix_spawn_file_actions_t > ,
52
+ @_silgen_name ( " _stdlib_posix_spawn_file_actions_adddup2 " )
53
+ internal func _stdlib_posix_spawn_file_actions_adddup2 (
54
+ _ file_actions: UnsafeMutablePointer < _stdlib_posix_spawn_file_actions_t > ,
55
55
_ filedes: CInt ,
56
56
_ newfiledes: CInt ) -> CInt
57
57
58
- @_silgen_name ( " swift_posix_spawn " )
59
- func swift_posix_spawn (
58
+ @_silgen_name ( " _stdlib_posix_spawn " )
59
+ internal func _stdlib_posix_spawn (
60
60
_ pid: UnsafeMutablePointer < pid_t > ? ,
61
61
_ file: UnsafePointer < Int8 > ,
62
- _ file_actions: UnsafePointer < swift_posix_spawn_file_actions_t > ? ,
62
+ _ file_actions: UnsafePointer < _stdlib_posix_spawn_file_actions_t > ? ,
63
63
_ attrp: UnsafePointer < posix_spawnattr_t > ? ,
64
64
_ argv: UnsafePointer < UnsafeMutablePointer < Int8 > ? > ,
65
65
_ envp: UnsafePointer < UnsafeMutablePointer < Int8 > ? > ? ) -> CInt
@@ -113,7 +113,7 @@ public func spawnChild(_ args: [String])
113
113
// code after this block will never be executed, and the parent write pipe
114
114
// will be closed.
115
115
withArrayOfCStrings ( [ CommandLine . arguments [ 0 ] ] + args) {
116
- execve ( CommandLine . arguments [ 0 ] , $0, _getEnviron ( ) )
116
+ execve ( CommandLine . arguments [ 0 ] , $0, environ )
117
117
}
118
118
119
119
// If execve() encountered an error, we write the errno encountered to the
@@ -142,44 +142,44 @@ public func spawnChild(_ args: [String])
142
142
}
143
143
#else
144
144
var fileActions = _make_posix_spawn_file_actions_t ( )
145
- if swift_posix_spawn_file_actions_init ( & fileActions) != 0 {
146
- preconditionFailure ( " swift_posix_spawn_file_actions_init () failed" )
145
+ if _stdlib_posix_spawn_file_actions_init ( & fileActions) != 0 {
146
+ preconditionFailure ( " _stdlib_posix_spawn_file_actions_init () failed" )
147
147
}
148
148
149
149
// Close the write end of the pipe on the child side.
150
- if swift_posix_spawn_file_actions_addclose (
150
+ if _stdlib_posix_spawn_file_actions_addclose (
151
151
& fileActions, childStdin. writeFD) != 0 {
152
- preconditionFailure ( " swift_posix_spawn_file_actions_addclose () failed" )
152
+ preconditionFailure ( " _stdlib_posix_spawn_file_actions_addclose () failed" )
153
153
}
154
154
155
155
// Remap child's stdin.
156
- if swift_posix_spawn_file_actions_adddup2 (
156
+ if _stdlib_posix_spawn_file_actions_adddup2 (
157
157
& fileActions, childStdin. readFD, STDIN_FILENO) != 0 {
158
- preconditionFailure ( " swift_posix_spawn_file_actions_adddup2 () failed" )
158
+ preconditionFailure ( " _stdlib_posix_spawn_file_actions_adddup2 () failed" )
159
159
}
160
160
161
161
// Close the read end of the pipe on the child side.
162
- if swift_posix_spawn_file_actions_addclose (
162
+ if _stdlib_posix_spawn_file_actions_addclose (
163
163
& fileActions, childStdout. readFD) != 0 {
164
- preconditionFailure ( " swift_posix_spawn_file_actions_addclose () failed" )
164
+ preconditionFailure ( " _stdlib_posix_spawn_file_actions_addclose () failed" )
165
165
}
166
166
167
167
// Remap child's stdout.
168
- if swift_posix_spawn_file_actions_adddup2 (
168
+ if _stdlib_posix_spawn_file_actions_adddup2 (
169
169
& fileActions, childStdout. writeFD, STDOUT_FILENO) != 0 {
170
- preconditionFailure ( " swift_posix_spawn_file_actions_adddup2 () failed" )
170
+ preconditionFailure ( " _stdlib_posix_spawn_file_actions_adddup2 () failed" )
171
171
}
172
172
173
173
// Close the read end of the pipe on the child side.
174
- if swift_posix_spawn_file_actions_addclose (
174
+ if _stdlib_posix_spawn_file_actions_addclose (
175
175
& fileActions, childStderr. readFD) != 0 {
176
- preconditionFailure ( " swift_posix_spawn_file_actions_addclose () failed" )
176
+ preconditionFailure ( " _stdlib_posix_spawn_file_actions_addclose () failed" )
177
177
}
178
178
179
179
// Remap child's stderr.
180
- if swift_posix_spawn_file_actions_adddup2 (
180
+ if _stdlib_posix_spawn_file_actions_adddup2 (
181
181
& fileActions, childStderr. writeFD, STDERR_FILENO) != 0 {
182
- preconditionFailure ( " swift_posix_spawn_file_actions_adddup2 () failed" )
182
+ preconditionFailure ( " _stdlib_posix_spawn_file_actions_adddup2 () failed" )
183
183
}
184
184
185
185
var pid : pid_t = - 1
@@ -192,16 +192,16 @@ public func spawnChild(_ args: [String])
192
192
}
193
193
}
194
194
let spawnResult = withArrayOfCStrings ( childArgs) {
195
- swift_posix_spawn (
196
- & pid, childArgs [ 0 ] , & fileActions, nil , $0, _getEnviron ( ) )
195
+ _stdlib_posix_spawn (
196
+ & pid, childArgs [ 0 ] , & fileActions, nil , $0, environ )
197
197
}
198
198
if spawnResult != 0 {
199
199
print ( String ( cString: strerror ( spawnResult) ) )
200
- preconditionFailure ( " swift_posix_spawn () failed" )
200
+ preconditionFailure ( " _stdlib_posix_spawn () failed" )
201
201
}
202
202
203
- if swift_posix_spawn_file_actions_destroy ( & fileActions) != 0 {
204
- preconditionFailure ( " swift_posix_spawn_file_actions_destroy () failed" )
203
+ if _stdlib_posix_spawn_file_actions_destroy ( & fileActions) != 0 {
204
+ preconditionFailure ( " _stdlib_posix_spawn_file_actions_destroy () failed" )
205
205
}
206
206
#endif
207
207
@@ -226,12 +226,12 @@ public func spawnChild(_ args: [String])
226
226
#if !os(Android) && !os(Haiku)
227
227
#if os(Linux)
228
228
internal func _make_posix_spawn_file_actions_t( )
229
- -> swift_posix_spawn_file_actions_t {
229
+ -> _stdlib_posix_spawn_file_actions_t {
230
230
return posix_spawn_file_actions_t ( )
231
231
}
232
232
#else
233
233
internal func _make_posix_spawn_file_actions_t( )
234
- -> swift_posix_spawn_file_actions_t {
234
+ -> _stdlib_posix_spawn_file_actions_t {
235
235
return nil
236
236
}
237
237
#endif
@@ -292,27 +292,6 @@ public func posixWaitpid(_ pid: pid_t) -> ProcessTerminationStatus {
292
292
preconditionFailure ( " did not understand what happened to child process " )
293
293
}
294
294
295
- #if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
296
- @_silgen_name ( " swift_SwiftPrivateLibcExtras_NSGetEnviron " )
297
- func _NSGetEnviron( ) -> UnsafeMutablePointer < UnsafeMutablePointer < UnsafeMutablePointer < CChar > ? > >
298
- #endif
299
-
300
- internal func _getEnviron( ) -> UnsafeMutablePointer < UnsafeMutablePointer < CChar > ? > {
301
- #if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
302
- return _NSGetEnviron ( ) . pointee
303
- #elseif os(FreeBSD)
304
- return environ
305
- #elseif os(PS4)
306
- return environ
307
- #elseif os(Android)
308
- return environ
309
- #elseif os(Cygwin)
310
- return environ
311
- #elseif os(Haiku)
312
- return environ
313
- #else
314
- return __environ
315
- #endif
316
- }
295
+ // !os(Windows)
317
296
#endif
318
297
0 commit comments