From 3eb8a04f9597ed71ddd3eb54db77a9d5e37f032d 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 64f8e21b1..824c3ac97 100644 --- a/Sources/FoundationEssentials/FileManager/FileManager+Files.swift +++ b/Sources/FoundationEssentials/FileManager/FileManager+Files.swift @@ -727,8 +727,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 ad2b4b35979caf1d66d77933dda66012f7108294 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 824c3ac97..c7ea78c6a 100644 --- a/Sources/FoundationEssentials/FileManager/FileManager+Files.swift +++ b/Sources/FoundationEssentials/FileManager/FileManager+Files.swift @@ -951,6 +951,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),