Re: Determining architecture type at run time
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com 2 things 1) you are passing a handle to sysctl, not a pointer sysctl(mib, 2, cputype, &len, NULL, 0) 2) It appears MACHINE_ARCH is not supported at all, use HW_MACHINE. On Apr 27, 2009, at 2:35 PM, rohan a wrote: Hi, I tried with sysctl(). I did this : #include<stdio.h> #include<sys/types.h> #include<sys/sysctl.h> #include<errno.h> int main() { int mib[2]; char cputype[64]; size_t len; mib[0] = CTL_HW ; mib[1] = HW_MACHINE_ARCH ; len = sizeof(cputype); if(sysctl(mib, 2, &cputype, &len, NULL, 0) == -1) { perror("sysctl() failed\n"); printf("errno = %d\n",errno); return -1; } printf("%s\n",cputype); return 0; } I continue to get the same error. On Apr 27, 2009, at 2:02 PM, rohan a wrote: Hi, Thanks for this. I tried the following : #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/sysctl.h> extern int errno; int main(void) { int len; char cpuarch[64]; However, sysctlbyname fails with the error sysctlbyname(): No such file or directory What needs to be done? $ man 3 sysctl On Apr 27, 2009, at 12:11 PM, rohan a wrote: Thanks _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... On 4/27/09, Brian Bergstrand <brian@classicalguitar.net> wrote: ENOENT is "no such file or directory". That would mean there's no name mapping for hw.machine_arch, so use sysctl() instead with HW_MACHINE_ARCH as the MIB ID. len = sizeof(cpuarch); if (sysctlbyname("hw.machine_arch", cpuarch, &len, NULL, NULL) == -1) { perror("sysctlbyname()"); return -1; } return 0; } On 4/27/09, Brian Bergstrand <brian@classicalguitar.net> wrote: #include <sys/sysctl.h> Hello, I need to determine at program run time, the architecture type(x86, ppc or x86_64) of the Mac OS X machine. Is it possible to do this? Does Mac OS provide any API for this? This email sent to site_archiver@lists.apple.com
participants (1)
-
Brian Bergstrand