Skip to content

Commit 95e05db

Browse files
committed
more android fixes to simplify PR
1 parent f3e12fb commit 95e05db

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

Sources/Foundation/Data.swift

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ internal func malloc_good_size(_ size: Int) -> Int {
6464
import Glibc
6565
#elseif canImport(Musl)
6666
import Musl
67+
#elseif canImport(Android)
68+
import Android
6769
#elseif canImport(WASILibc)
6870
import WASILibc
6971
#endif

Sources/Foundation/FileManager+POSIX.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
internal func &(left: UInt32, right: mode_t) -> mode_t {
1212
return mode_t(left) & right
1313
}
14-
#elseif os(Android)
15-
internal func &(left: mode_t, right: Int32) -> mode_t {
16-
return left & mode_t(right)
17-
}
1814
#endif
1915

2016
#if os(WASI)
@@ -413,7 +409,7 @@ extension FileManager {
413409
if !parent.isEmpty && !fileExists(atPath: parent, isDirectory: &isDir) {
414410
try createDirectory(atPath: parent, withIntermediateDirectories: true, attributes: attributes)
415411
}
416-
if mkdir(pathFsRep, mode_t(S_IRWXU) | mode_t(S_IRWXG) | mode_t(S_IRWXO)) != 0 {
412+
if mkdir(pathFsRep, S_IRWXU | S_IRWXG | S_IRWXO) != 0 {
417413
let posixError = errno
418414
if posixError == EEXIST && fileExists(atPath: path, isDirectory: &isDir) && isDir.boolValue {
419415
// Continue; if there is an existing file and it is a directory, that is still a success.
@@ -432,7 +428,7 @@ extension FileManager {
432428
throw _NSErrorWithErrno(EEXIST, reading: false, path: path)
433429
}
434430
} else {
435-
if mkdir(pathFsRep, mode_t(S_IRWXU) | mode_t(S_IRWXG) | mode_t(S_IRWXO)) != 0 {
431+
if mkdir(pathFsRep, S_IRWXU | S_IRWXG | S_IRWXO) != 0 {
436432
throw _NSErrorWithErrno(errno, reading: false, path: path)
437433
} else if let attr = attributes {
438434
try self.setAttributes(attr, ofItemAtPath: path)

Sources/Foundation/FileManager.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import WinSDK
2525
import WASILibc
2626
#endif
2727

28-
#if os(Android)
28+
#if canImport(Android)
2929
import Android
3030
#endif
3131

@@ -1346,12 +1346,12 @@ public struct FileAttributeType : RawRepresentable, Equatable, Hashable {
13461346
#else
13471347
internal init(statMode: mode_t) {
13481348
switch statMode & S_IFMT {
1349-
case mode_t(S_IFCHR): self = .typeCharacterSpecial
1350-
case mode_t(S_IFDIR): self = .typeDirectory
1351-
case mode_t(S_IFBLK): self = .typeBlockSpecial
1352-
case mode_t(S_IFREG): self = .typeRegular
1353-
case mode_t(S_IFLNK): self = .typeSymbolicLink
1354-
case mode_t(S_IFSOCK): self = .typeSocket
1349+
case S_IFCHR: self = .typeCharacterSpecial
1350+
case S_IFDIR: self = .typeDirectory
1351+
case S_IFBLK: self = .typeBlockSpecial
1352+
case S_IFREG: self = .typeRegular
1353+
case S_IFLNK: self = .typeSymbolicLink
1354+
case S_IFSOCK: self = .typeSocket
13551355
default: self = .typeUnknown
13561356
}
13571357
}

Sources/Foundation/Host.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import WinSDK
1313
#endif
1414

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

1919
// IFF_LOOPBACK is part of the enumeration net_device_flags, which needs to
2020
// convert to UInt32.

Sources/Foundation/NSPathUtilities.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ internal func _NSCreateTemporaryFile(_ filePath: String) throws -> (Int32, Strin
803803
}
804804

805805
// Set the file mode to match macOS
806-
guard fchmod(fd, mode_t(S_IRUSR) | mode_t(S_IWUSR) | mode_t(S_IRGRP) | mode_t(S_IWGRP) | mode_t(S_IROTH) | mode_t(S_IWOTH)) != -1 else {
806+
guard fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) != -1 else {
807807
let _errno = errno
808808
close(fd)
809809
throw _NSErrorWithErrno(_errno, reading: false, path: pathResult)

0 commit comments

Comments
 (0)