2

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.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Rick
  • 3,298
  • 3
  • 29
  • 47
  • 4
    https://man.netbsd.org/libmagic.3 – Phil Feb 06 '23 at 00:32
  • Ah! Nearly perfect. Seems it gives the result as a human-readable textual description, rather than structured data. But it’ll do for my purposes. Thanks. – Rick Feb 06 '23 at 07:30

0 Answers0