site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com sysctlbyname() is preferred. -- Terry 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: _______________________________________________ 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... FWIW: I will be turning the oid-based sysctl() into a Libc routine and deprecating future additions using it. Too many people have been using oid-space as a parameter space, and failing to make their code 64 bit clean when passing around addresses as ints. Also the name you are looking for in this case is "hw.machine", but you are unlikely to be happy with it, since you'll still have to do string matching of the result, which is a string. On Apr 27, 2009, at 4:35 AM, rohan a wrote: 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? Thanks This email sent to site_archiver@lists.apple.com