Skip to content

Commit ad6ca71

Browse files
hypjmschonfeld
andauthored
[android] fix the LP32 armv7/i686 android build (#846)
* [android] fix the LP32 armv7/i686 android build * Update Sources/FoundationEssentials/Android+Extensions.swift Co-authored-by: Jeremy Schonfeld <[email protected]> * drop the android Lp32 specific operator & --------- Co-authored-by: Jeremy Schonfeld <[email protected]>
1 parent bc47ca2 commit ad6ca71

File tree

8 files changed

+18
-14
lines changed

8 files changed

+18
-14
lines changed

Sources/FoundationEssentials/Data/Data+Reading.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ internal func readBytesFromFile(path inPath: PathOrURL, reportProgress: Bool, ma
325325
}
326326

327327
let fileSize = min(Int(clamping: filestat.st_size), maxLength ?? Int.max)
328-
let fileType = filestat.st_mode & S_IFMT
328+
let fileType = mode_t(filestat.st_mode) & S_IFMT
329329
#if !NO_FILESYSTEM
330330
let shouldMap = shouldMapFileDescriptor(fd, path: inPath, options: options)
331331
#else

Sources/FoundationEssentials/FileManager/FileManager+Basics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ internal struct _FileManagerImpl {
201201
var statBuf = stat()
202202
let fd = open(path, 0, 0)
203203
guard fd >= 0 else { return nil }
204-
if fstat(fd, &statBuf) < 0 || statBuf.st_mode & S_IFMT == S_IFDIR {
204+
if fstat(fd, &statBuf) < 0 || mode_t(statBuf.st_mode) & S_IFMT == S_IFDIR {
205205
close(fd)
206206
return nil
207207
}
@@ -220,7 +220,7 @@ internal struct _FileManagerImpl {
220220
}
221221

222222
/* check for being same type */
223-
if myInfo.st_mode & S_IFMT != otherInfo.st_mode & S_IFMT {
223+
if mode_t(myInfo.st_mode) & S_IFMT != mode_t(otherInfo.st_mode) & S_IFMT {
224224
return false
225225
}
226226

Sources/FoundationEssentials/FileManager/FileManager+Files.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ extension stat {
175175
}
176176

177177
fileprivate var fileAttributes: [FileAttributeKey : Any] {
178-
let fileType = st_mode.fileType
178+
// On 32 bit Android, st_mode is UInt32.
179+
let fileType = mode_t(st_mode).fileType
179180
var result: [FileAttributeKey : Any] = [
180181
.size : _writeFileAttributePrimitive(st_size, as: UInt.self),
181182
.modificationDate : modificationDate,
@@ -393,7 +394,7 @@ extension _FileManagerImpl {
393394
guard stat(rep, &fileInfo) == 0 else {
394395
return (false, false)
395396
}
396-
let isDir = (fileInfo.st_mode & S_IFMT) == S_IFDIR
397+
let isDir = (mode_t(fileInfo.st_mode) & S_IFMT) == S_IFDIR
397398
return (true, isDir)
398399
}
399400
#endif
@@ -472,7 +473,7 @@ extension _FileManagerImpl {
472473
return false
473474
}
474475

475-
if ((dirInfo.st_mode & S_ISVTX) != 0) && fileManager.fileExists(atPath: path) {
476+
if ((mode_t(dirInfo.st_mode) & S_ISVTX) != 0) && fileManager.fileExists(atPath: path) {
476477
// its sticky so verify that we own the file
477478
// otherwise we answer YES on the principle that if
478479
// we create files we can delete them

Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ extension FILETIME {
4848
#if !os(Windows)
4949
extension stat {
5050
var isDirectory: Bool {
51-
(self.st_mode & S_IFMT) == S_IFDIR
51+
(mode_t(self.st_mode) & S_IFMT) == S_IFDIR
5252
}
5353

5454
var isRegular: Bool {
55-
(self.st_mode & S_IFMT) == S_IFREG
55+
(mode_t(self.st_mode) & S_IFMT) == S_IFREG
5656
}
5757

5858
var isSymbolicLink: Bool {
59-
(self.st_mode & S_IFMT) == S_IFLNK
59+
(mode_t(self.st_mode) & S_IFMT) == S_IFLNK
6060
}
6161

6262
var isSpecial: Bool {
63-
let type = self.st_mode & S_IFMT
63+
let type = mode_t(self.st_mode) & S_IFMT
6464
return type == S_IFBLK || type == S_IFCHR
6565
}
6666
}

Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ struct _POSIXDirectoryContentsSequence: Sequence {
380380
let statDir = directoryPath + "/" + fileName
381381
if stat(statDir, &statBuf) == 0 {
382382
// #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
383-
if (statBuf.st_mode & S_IFMT) == S_IFDIR {
383+
if (mode_t(statBuf.st_mode) & S_IFMT) == S_IFDIR {
384384
isDirectory = true
385385
}
386386
}

Sources/FoundationEssentials/FileManager/FileOperations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ enum _FileOperations {
867867

868868
#if !os(WASI) // WASI doesn't have fchmod for now
869869
// Set the file permissions using fchmod() instead of when open()ing to avoid umask() issues
870-
let permissions = fileInfo.st_mode & ~S_IFMT
870+
let permissions = mode_t(fileInfo.st_mode) & ~S_IFMT
871871
guard fchmod(dstfd, permissions) == 0 else {
872872
try delegate.throwIfNecessary(errno, String(cString: srcPtr), String(cString: dstPtr))
873873
return

Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ final class _ProcessInfo: Sendable {
198198
}
199199

200200
var fullUserName: String {
201-
#if canImport(Darwin) || os(Android) || canImport(Glibc)
201+
#if os(Android) && (arch(i386) || arch(arm))
202+
// On LP32 Android, pw_gecos doesn't exist and is presumed to be NULL.
203+
return ""
204+
#elseif canImport(Darwin) || os(Android) || canImport(Glibc)
202205
let (euid, _) = Platform.getUGIDs()
203206
if let upwd = getpwuid(euid),
204207
let fullname = upwd.pointee.pw_gecos {

Sources/FoundationEssentials/String/String+Path.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ extension String {
739739
if lstat(buffer.baseAddress!, &statBuf) < 0 {
740740
return nil
741741
}
742-
if statBuf.st_mode & S_IFMT == S_IFLNK {
742+
if mode_t(statBuf.st_mode) & S_IFMT == S_IFLNK {
743743
/* Examples:
744744
* fspath == /foo/bar0baz/quux/froboz
745745
* linkx == /tic/tac/toe

0 commit comments

Comments
 (0)