From c748c8b5cc9cb993e29b95ac0ba862ccd735212b Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Sat, 28 Jun 2025 11:58:13 +1000 Subject: [PATCH 1/2] build with 64-bit fsblkcnt_t on 32-bit glibc platforms It is possible to build with 64-bit file offsets on 32-bit platforms such as armv7, and indeed this is the default for some build environments such as Yocto. Use fsblkcnt_t, which is an alias to a type of the correct width, when computing blockSize. --- .../FoundationEssentials/FileManager/FileManager+Files.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/FoundationEssentials/FileManager/FileManager+Files.swift b/Sources/FoundationEssentials/FileManager/FileManager+Files.swift index b2666ccbc..32cbc50cf 100644 --- a/Sources/FoundationEssentials/FileManager/FileManager+Files.swift +++ b/Sources/FoundationEssentials/FileManager/FileManager+Files.swift @@ -741,8 +741,12 @@ extension _FileManagerImpl { let blockSize = UInt64(result.f_bsize) #else let fsNumber = result.f_fsid + #if canImport(Glibc) + let blockSize = fsblkcnt_t(result.f_frsize) // support 64-bit block sizes on 32-bit platforms + #else let blockSize = UInt(result.f_frsize) #endif + #endif var totalSizeBytes = result.f_blocks * blockSize var availSizeBytes = result.f_bavail * blockSize var totalFiles = result.f_files From 9692f35892e1e67661328c56f571d60acdccedc8 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Sat, 28 Jun 2025 11:59:30 +1000 Subject: [PATCH 2/2] build with 64-bit time_t on 32-bit platforms It is good practice to build with 64-bit time_t/timeval on 32-bit platforms to avoid the Y2038 issue. This is the default when building on Yocto for armv7, for example. Unfortunately suseconds_t is not an alias to a type of the correct width (unlike time_t), so for Glibc make it a private alias of time_t to fix the build. --- .../FileManager/FileManager+Files.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/FoundationEssentials/FileManager/FileManager+Files.swift b/Sources/FoundationEssentials/FileManager/FileManager+Files.swift index 32cbc50cf..90e9e7472 100644 --- a/Sources/FoundationEssentials/FileManager/FileManager+Files.swift +++ b/Sources/FoundationEssentials/FileManager/FileManager+Files.swift @@ -967,6 +967,12 @@ extension _FileManagerImpl { #endif } + #if canImport(Glibc) + // support for 64-bit timestamps on 32-bit platforms; unfortunately + // suseconds_t is not an alias of the appropriate type, but time_t is + typealias suseconds_t = time_t + #endif + if let date = attributes[.modificationDate] as? Date { let (isecs, fsecs) = modf(date.timeIntervalSince1970) if let tv_sec = time_t(exactly: isecs),