Starting on info functions

This commit is contained in:
Greg Neagle
2024-08-07 10:47:30 -07:00
parent 8870295b16
commit 44bea67ad4
+19
View File
@@ -6,3 +6,22 @@
//
import Foundation
func platform() -> String {
// returns platform ("x86_64", "arm64")
var systemInfo = utsname()
uname(&systemInfo)
let size = Int(_SYS_NAMELEN) // is 32, but posix AND its init is 256....
let s = withUnsafeMutablePointer(to: &systemInfo.machine) { p in
p.withMemoryRebound(to: CChar.self, capacity: size) { p2 in
return String(cString: p2)
}
}
return s
}
func isAppleSilicon() -> Bool {
// Returns true if we're running on Apple silicon"
return platform() == "arm64"
}