Skip to content

[android] fix the LP32 armv7/i686 android build #846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/FoundationEssentials/Data/Data+Reading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ internal func readBytesFromFile(path inPath: PathOrURL, reportProgress: Bool, ma
}

let fileSize = min(Int(clamping: filestat.st_size), maxLength ?? Int.max)
let fileType = filestat.st_mode & S_IFMT
let fileType = mode_t(filestat.st_mode) & S_IFMT
#if !NO_FILESYSTEM
let shouldMap = shouldMapFileDescriptor(fd, path: inPath, options: options)
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ internal struct _FileManagerImpl {
var statBuf = stat()
let fd = open(path, 0, 0)
guard fd >= 0 else { return nil }
if fstat(fd, &statBuf) < 0 || statBuf.st_mode & S_IFMT == S_IFDIR {
if fstat(fd, &statBuf) < 0 || mode_t(statBuf.st_mode) & S_IFMT == S_IFDIR {
close(fd)
return nil
}
Expand All @@ -220,7 +220,7 @@ internal struct _FileManagerImpl {
}

/* check for being same type */
if myInfo.st_mode & S_IFMT != otherInfo.st_mode & S_IFMT {
if mode_t(myInfo.st_mode) & S_IFMT != mode_t(otherInfo.st_mode) & S_IFMT {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ extension stat {
}

fileprivate var fileAttributes: [FileAttributeKey : Any] {
let fileType = st_mode.fileType
// On 32 bit Android, st_mode is UInt32.
let fileType = mode_t(st_mode).fileType
var result: [FileAttributeKey : Any] = [
.size : _writeFileAttributePrimitive(st_size, as: UInt.self),
.modificationDate : modificationDate,
Expand Down Expand Up @@ -393,7 +394,7 @@ extension _FileManagerImpl {
guard stat(rep, &fileInfo) == 0 else {
return (false, false)
}
let isDir = (fileInfo.st_mode & S_IFMT) == S_IFDIR
let isDir = (mode_t(fileInfo.st_mode) & S_IFMT) == S_IFDIR
return (true, isDir)
}
#endif
Expand Down Expand Up @@ -472,7 +473,7 @@ extension _FileManagerImpl {
return false
}

if ((dirInfo.st_mode & S_ISVTX) != 0) && fileManager.fileExists(atPath: path) {
if ((mode_t(dirInfo.st_mode) & S_ISVTX) != 0) && fileManager.fileExists(atPath: path) {
// its sticky so verify that we own the file
// otherwise we answer YES on the principle that if
// we create files we can delete them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ extension FILETIME {
#if !os(Windows)
extension stat {
var isDirectory: Bool {
(self.st_mode & S_IFMT) == S_IFDIR
(mode_t(self.st_mode) & S_IFMT) == S_IFDIR
}

var isRegular: Bool {
(self.st_mode & S_IFMT) == S_IFREG
(mode_t(self.st_mode) & S_IFMT) == S_IFREG
}

var isSymbolicLink: Bool {
(self.st_mode & S_IFMT) == S_IFLNK
(mode_t(self.st_mode) & S_IFMT) == S_IFLNK
}

var isSpecial: Bool {
let type = self.st_mode & S_IFMT
let type = mode_t(self.st_mode) & S_IFMT
return type == S_IFBLK || type == S_IFCHR
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ struct _POSIXDirectoryContentsSequence: Sequence {
let statDir = directoryPath + "/" + fileName
if stat(statDir, &statBuf) == 0 {
// #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
if (statBuf.st_mode & S_IFMT) == S_IFDIR {
if (mode_t(statBuf.st_mode) & S_IFMT) == S_IFDIR {
isDirectory = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ enum _FileOperations {

#if !os(WASI) // WASI doesn't have fchmod for now
// Set the file permissions using fchmod() instead of when open()ing to avoid umask() issues
let permissions = fileInfo.st_mode & ~S_IFMT
let permissions = mode_t(fileInfo.st_mode) & ~S_IFMT
guard fchmod(dstfd, permissions) == 0 else {
try delegate.throwIfNecessary(errno, String(cString: srcPtr), String(cString: dstPtr))
return
Expand Down
5 changes: 4 additions & 1 deletion Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ final class _ProcessInfo: Sendable {
}

var fullUserName: String {
#if canImport(Darwin) || os(Android) || canImport(Glibc)
#if os(Android) && (arch(i386) || arch(arm))
// On LP32 Android, pw_gecos doesn't exist and is presumed to be NULL.
return ""
#elseif canImport(Darwin) || os(Android) || canImport(Glibc)
let (euid, _) = Platform.getUGIDs()
if let upwd = getpwuid(euid),
let fullname = upwd.pointee.pw_gecos {
Expand Down
2 changes: 1 addition & 1 deletion Sources/FoundationEssentials/String/String+Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ extension String {
if lstat(buffer.baseAddress!, &statBuf) < 0 {
return nil
}
if statBuf.st_mode & S_IFMT == S_IFLNK {
if mode_t(statBuf.st_mode) & S_IFMT == S_IFLNK {
/* Examples:
* fspath == /foo/bar0baz/quux/froboz
* linkx == /tic/tac/toe
Expand Down