1313import SwiftPrivate
1414#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
1515import Darwin
16- #elseif os(Linux)
16+ #elseif os(Linux) || os(Android)
1717import Glibc
1818#endif
1919
20+ #if !os(Android)
21+
2022// swift_posix_spawn isn't available in the public watchOS SDK, we sneak by the
2123// unavailable attribute declaration here of the APIs that we need.
2224
@@ -47,6 +49,8 @@ func swift_posix_spawn(
4749 _ argv: UnsafePointer < UnsafeMutablePointer < Int8 > > ,
4850 _ envp: UnsafePointer < UnsafeMutablePointer < Int8 > > ) -> CInt
4951
52+ #endif
53+
5054/// Calls POSIX `pipe()`.
5155func posixPipe( ) -> ( readFD: CInt , writeFD: CInt ) {
5256 var fds : [ CInt ] = [ - 1 , - 1 ]
@@ -64,6 +68,9 @@ func posixPipe() -> (readFD: CInt, writeFD: CInt) {
6468/// stderr.
6569public func spawnChild( args: [ String ] )
6670 -> ( pid: pid_t , stdinFD: CInt , stdoutFD: CInt , stderrFD: CInt ) {
71+ #if os(Android)
72+ preconditionFailure ( " posix_spawn doesn't exist on Android " )
73+ #else
6774 var fileActions = posix_spawn_file_actions_t ( )
6875 if swift_posix_spawn_file_actions_init ( & fileActions) != 0 {
6976 preconditionFailure ( " swift_posix_spawn_file_actions_init() failed " )
@@ -138,6 +145,7 @@ public func spawnChild(args: [String])
138145 }
139146
140147 return ( pid, childStdin. writeFD, childStdout. readFD, childStderr. readFD)
148+ #endif
141149}
142150
143151internal func _readAll( fd: CInt ) -> String {
@@ -232,6 +240,8 @@ func _NSGetEnviron() -> UnsafeMutablePointer<UnsafeMutablePointer<UnsafeMutableP
232240internal func _getEnviron( ) -> UnsafeMutablePointer < UnsafeMutablePointer < CChar > > {
233241#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
234242 return _NSGetEnviron ( ) . memory
243+ #elseif os(Android)
244+ return environ
235245#else
236246 return __environ
237247#endif
0 commit comments