Programmatically getting the architecture info `file` produces on macOS?

80 Views Asked by At

On macOS, is there any way to programmatically get (from C or Swift) the same architecture info that file produces when run on an executable? E.g.:

$ file /Library/Audio/Plug-Ins/HAL/ACE.driver/Contents/MacOS/ACE 
/Library/Audio/Plug-Ins/HAL/ACE.driver/Contents/MacOS/ACE: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit bundle x86_64] [arm64:Mach-O 64-bit bundle arm64]
/Library/Audio/Plug-Ins/HAL/ACE.driver/Contents/MacOS/ACE (for architecture x86_64):    Mach-O 64-bit bundle x86_64
/Library/Audio/Plug-Ins/HAL/ACE.driver/Contents/MacOS/ACE (for architecture arm64): Mach-O 64-bit bundle arm64
$ file `which plutil`
/usr/bin/plutil: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/usr/bin/plutil (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/plutil (for architecture arm64e):  Mach-O 64-bit executable arm64e

I know I can invoke file from my code, but I’m looking for a library call I can make.

0

There are 0 best solutions below