Skip to content

Commit 41466f4

Browse files
committed
Merge commit '246b3474' into github/main
2 parents 65abf58 + 246b347 commit 41466f4

28 files changed

+105
-13
lines changed

Sources/CoreFoundation/include/ForSwiftFoundationOnly.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@
6969
#include <sys/stat.h>
7070
#include <sys/syscall.h>
7171
#include <termios.h>
72+
#include <linux/fcntl.h>
73+
#ifdef __swift__
74+
// The linux/stat header is private in the Android modulemap.
75+
#pragma clang module import posix_filesystem.linux_stat
76+
#else
77+
#include <linux/stat.h>
78+
#endif
7279
#elif TARGET_OS_WASI
7380
#include <fcntl.h>
7481
#include <sys/stat.h>

Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ typedef char * Class;
109109
#include <pthread.h>
110110
#endif
111111

112+
#if TARGET_OS_ANDROID
113+
#define HAVE_STRLCPY 1
114+
#define HAVE_STRLCAT 1
115+
#endif
116+
112117
#if TARGET_OS_WIN32
113118
#define BOOL WINDOWS_BOOL
114119

Sources/Foundation/CGFloat.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if canImport(Android)
11+
import Android
12+
#endif
13+
1014
@frozen
1115
public struct CGFloat: Sendable {
1216
#if arch(i386) || arch(arm) || arch(wasm32)

Sources/Foundation/FileHandle.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ import WASILibc
3434
fileprivate let _read = WASILibc.read(_:_:_:)
3535
fileprivate let _write = WASILibc.write(_:_:_:)
3636
fileprivate let _close = WASILibc.close(_:)
37+
#elseif canImport(Android)
38+
import Android
39+
fileprivate let _read = Android.read(_:_:_:)
40+
fileprivate let _write = Android.write(_:_:_:)
41+
fileprivate let _close = Android.close(_:)
3742
#endif
3843

3944
#if canImport(WinSDK)
@@ -324,7 +329,7 @@ open class FileHandle : NSObject, @unchecked Sendable {
324329
let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0)
325330
// Swift does not currently expose MAP_FAILURE
326331
if data != UnsafeMutableRawPointer(bitPattern: -1) {
327-
return NSData.NSDataReadResult(bytes: data!, length: mapSize) { buffer, length in
332+
return NSData.NSDataReadResult(bytes: data, length: mapSize) { buffer, length in
328333
munmap(buffer, length)
329334
}
330335
}

Sources/Foundation/FileManager+POSIX.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
//
88
#if !os(Windows)
99

10+
#if canImport(Android)
11+
import Android
12+
#endif
13+
1014
#if os(Android) && (arch(i386) || arch(arm)) // struct stat.st_mode is UInt32
1115
internal func &(left: UInt32, right: mode_t) -> mode_t {
1216
return mode_t(left) & right
@@ -398,13 +402,13 @@ extension FileManager {
398402

399403
_current = fts_read(stream)
400404
while let current = _current {
401-
let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path, length: Int(current.pointee.fts_pathlen))
405+
let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path!, length: Int(current.pointee.fts_pathlen))
402406

403407
switch Int32(current.pointee.fts_info) {
404408
case FTS_D:
405409
let (showFile, skipDescendants) = match(filename: filename, to: _options, isDir: true)
406410
if skipDescendants {
407-
fts_set(_stream, _current, FTS_SKIP)
411+
fts_set(stream, _current!, FTS_SKIP)
408412
}
409413
if showFile {
410414
return URL(fileURLWithPath: filename, isDirectory: true)
@@ -578,7 +582,7 @@ extension FileManager {
578582
let finalErrno = originalItemURL.withUnsafeFileSystemRepresentation { (originalFS) -> Int32? in
579583
return newItemURL.withUnsafeFileSystemRepresentation { (newItemFS) -> Int32? in
580584
// This is an atomic operation in many OSes, but is not guaranteed to be atomic by the standard.
581-
if rename(newItemFS, originalFS) == 0 {
585+
if rename(newItemFS!, originalFS!) == 0 {
582586
return nil
583587
} else {
584588
return errno

Sources/Foundation/FileManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import WinSDK
2121

2222
#if os(WASI)
2323
import WASILibc
24+
#elseif canImport(Android)
25+
import Android
2426
#endif
2527

2628
#if os(Windows)

Sources/Foundation/Host.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import WinSDK
1313
#endif
1414

15-
#if os(Android)
16-
// Android Glibc differs a little with respect to the Linux Glibc.
15+
#if canImport(Android)
16+
import Android
17+
// Android Bionic differs a little with respect to the Linux Glibc.
1718

1819
// IFF_LOOPBACK is part of the enumeration net_device_flags, which needs to
1920
// convert to UInt32.
@@ -24,8 +25,8 @@ import WinSDK
2425
}
2526

2627
// getnameinfo uses size_t for its 4th and 6th arguments.
27-
private func getnameinfo(_ addr: UnsafePointer<sockaddr>?, _ addrlen: socklen_t, _ host: UnsafeMutablePointer<Int8>?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer<Int8>?, _ servlen: socklen_t, _ flags: Int32) -> Int32 {
28-
return Glibc.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags)
28+
private func getnameinfo(_ addr: UnsafePointer<sockaddr>, _ addrlen: socklen_t, _ host: UnsafeMutablePointer<Int8>?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer<Int8>?, _ servlen: socklen_t, _ flags: Int32) -> Int32 {
29+
return Android.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags)
2930
}
3031

3132
// getifaddrs and freeifaddrs are not available in Android 6.0 or earlier, so call these functions dynamically.

Sources/Foundation/NSData.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#if !os(WASI)
1212
import Dispatch
1313
#endif
14+
#if canImport(Android)
15+
import Android
16+
#endif
1417

1518
extension NSData {
1619
public typealias ReadingOptions = Data.ReadingOptions
@@ -469,6 +472,8 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
469472
let createMode = Int(Musl.S_IRUSR) | Int(Musl.S_IWUSR) | Int(Musl.S_IRGRP) | Int(Musl.S_IWGRP) | Int(Musl.S_IROTH) | Int(Musl.S_IWOTH)
470473
#elseif canImport(WASILibc)
471474
let createMode = Int(WASILibc.S_IRUSR) | Int(WASILibc.S_IWUSR) | Int(WASILibc.S_IRGRP) | Int(WASILibc.S_IWGRP) | Int(WASILibc.S_IROTH) | Int(WASILibc.S_IWOTH)
475+
#elseif canImport(Android)
476+
let createMode = Int(Android.S_IRUSR) | Int(Android.S_IWUSR) | Int(Android.S_IRGRP) | Int(Android.S_IWGRP) | Int(Android.S_IROTH) | Int(Android.S_IWOTH)
472477
#endif
473478
guard let fh = FileHandle(path: path, flags: flags, createMode: createMode) else {
474479
throw _NSErrorWithErrno(errno, reading: false, path: path)

Sources/Foundation/NSError.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Darwin
1616
import Glibc
1717
#elseif canImport(CRT)
1818
import CRT
19+
#elseif canImport(Android)
20+
import Android
1921
#endif
2022

2123
@_implementationOnly import CoreFoundation

Sources/Foundation/NSLock.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#if canImport(Glibc)
1313
import Glibc
14+
#elseif canImport(Android)
15+
import Android
1416
#endif
1517

1618
#if os(Windows)

0 commit comments

Comments
 (0)