Re: Determining architecture type at run time
Re: Determining architecture type at run time
- Subject: Re: Determining architecture type at run time
- From: Terry Lambert <email@hidden>
- Date: Mon, 27 Apr 2009 12:24:41 -0700
sysctlbyname() is preferred.
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.
-- Terry
On Apr 27, 2009, at 4:35 AM, 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 4/27/09, Brian Bergstrand <email@hidden> 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.
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];
len = sizeof(cpuarch);
if (sysctlbyname("hw.machine_arch", cpuarch, &len, NULL,
NULL) == -1)
{
perror("sysctlbyname()");
return -1;
}
return 0;
}
However, sysctlbyname fails with the error
sysctlbyname(): No such file or directory
What needs to be done?
On 4/27/09, Brian Bergstrand <email@hidden> wrote:
#include <sys/sysctl.h>
$ man 3 sysctl
On Apr 27, 2009, at 12:11 PM, rohan a wrote:
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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden