13
13
import SwiftPrivate
14
14
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
15
15
import Darwin
16
- #elseif os(Linux)
16
+ #elseif os(Linux) || os(Android)
17
17
import Glibc
18
18
#endif
19
19
20
+ #if !os(Android)
21
+
20
22
// swift_posix_spawn isn't available in the public watchOS SDK, we sneak by the
21
23
// unavailable attribute declaration here of the APIs that we need.
22
24
@@ -47,6 +49,8 @@ func swift_posix_spawn(
47
49
_ argv: UnsafePointer < UnsafeMutablePointer < Int8 > > ,
48
50
_ envp: UnsafePointer < UnsafeMutablePointer < Int8 > > ) -> CInt
49
51
52
+ #endif
53
+
50
54
/// Calls POSIX `pipe()`.
51
55
func posixPipe( ) -> ( readFD: CInt , writeFD: CInt ) {
52
56
var fds : [ CInt ] = [ - 1 , - 1 ]
@@ -64,6 +68,9 @@ func posixPipe() -> (readFD: CInt, writeFD: CInt) {
64
68
/// stderr.
65
69
public func spawnChild( args: [ String ] )
66
70
-> ( pid: pid_t , stdinFD: CInt , stdoutFD: CInt , stderrFD: CInt ) {
71
+ #if os(Android)
72
+ preconditionFailure ( " posix_spawn doesn't exist on Android " )
73
+ #else
67
74
var fileActions = posix_spawn_file_actions_t ( )
68
75
if swift_posix_spawn_file_actions_init ( & fileActions) != 0 {
69
76
preconditionFailure ( " swift_posix_spawn_file_actions_init() failed " )
@@ -138,6 +145,7 @@ public func spawnChild(args: [String])
138
145
}
139
146
140
147
return ( pid, childStdin. writeFD, childStdout. readFD, childStderr. readFD)
148
+ #endif
141
149
}
142
150
143
151
internal func _readAll( fd: CInt ) -> String {
@@ -232,6 +240,8 @@ func _NSGetEnviron() -> UnsafeMutablePointer<UnsafeMutablePointer<UnsafeMutableP
232
240
internal func _getEnviron( ) -> UnsafeMutablePointer < UnsafeMutablePointer < CChar > > {
233
241
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
234
242
return _NSGetEnviron ( ) . memory
243
+ #elseif os(Android)
244
+ return environ
235
245
#else
236
246
return __environ
237
247
#endif
0 commit comments