How to determine kernel bitness in Mac OS X 10.6?

前端 未结 3 1185
耶瑟儿~
耶瑟儿~ 2021-01-18 16:05

I know that I can use the terminal and the system-profiler command to determine the current bitness of the kernel but I am trying to determine if there is a way to get that

3条回答
  •  -上瘾入骨i
    2021-01-18 16:45

    You could use sysctlbyname. Dig around mach/machine.h to get possible values.

    #include 
    #include 
    
    void example() 
    {
       unsigned int cpuType;   
       size_t size = sizeof(cpuType);
       sysctlbyname("hw.cputype", &cpuType, &size, NULL, 0);
    
       bool is64 = cpuType & CPU_ARCH_ABI64;
    
       const char *cpu;
    
       switch (cpuType) {
          case CPU_TYPE_X86:
             cpu = "x86";
             break;
          case CPU_TYPE_X86_64:
             cpu = "x86_64";
             break;
          case CPU_TYPE_POWERPC:
             cpu = "ppc";
             break;
          case CPU_TYPE_POWERPC64:
             cpu = "ppc_64";
             break;
          case CPU_TYPE_SPARC:
             cpu = "sparc";
             break;
          default:
             cpu = "unknown";
             break;
       }
    }
    

提交回复
热议问题