6
6
import Darwin
7
7
#elseif canImport(Glibc)
8
8
import Glibc
9
+ #elseif canImport(Android)
10
+ import Android
9
11
#elseif canImport(Musl)
10
12
import Musl
11
13
#elseif os(Windows)
15
17
#warning("unsupported or untested platform (please open an issue at https://github.com/tayloraswift/swift-png/issues)")
16
18
#endif
17
19
18
- #if canImport(Darwin) || canImport(Glibc) || canImport(Musl) || os(Windows)
20
+ #if canImport(Darwin) || canImport(Glibc) || canImport(Android) || canImport( Musl) || os(Windows)
19
21
20
22
/// A namespace for platform-dependent functionality.
21
23
///
@@ -28,7 +30,11 @@ enum System
28
30
public
29
31
enum File
30
32
{
33
+ #if os(Android)
34
+ typealias Descriptor = OpaquePointer
35
+ #else
31
36
typealias Descriptor = UnsafeMutablePointer < FILE >
37
+ #endif
32
38
33
39
/// A type for reading data from files on disk.
34
40
public
@@ -100,7 +106,12 @@ extension System.File.Source
100
106
{
101
107
( buffer: inout UnsafeMutableBufferPointer < UInt8 > , count: inout Int ) in
102
108
103
- count = fread ( buffer. baseAddress, MemoryLayout< UInt8> . stride,
109
+ #if os(Android)
110
+ let baseAddress = buffer. baseAddress!
111
+ #else
112
+ let baseAddress = buffer. baseAddress
113
+ #endif
114
+ count = fread ( baseAddress, MemoryLayout< UInt8> . stride,
104
115
capacity, self . descriptor)
105
116
}
106
117
@@ -213,7 +224,12 @@ extension System.File.Destination
213
224
{
214
225
let count : Int = buffer. withUnsafeBufferPointer
215
226
{
216
- fwrite ( $0. baseAddress, MemoryLayout< UInt8> . stride,
227
+ #if os(Android)
228
+ let baseAddress = $0. baseAddress!
229
+ #else
230
+ let baseAddress = $0. baseAddress
231
+ #endif
232
+ return fwrite ( baseAddress, MemoryLayout< UInt8> . stride,
217
233
$0. count, self . descriptor)
218
234
}
219
235
0 commit comments