From 594d5064c950fa1d99a9eafbd357c5f46320d002 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 9 Nov 2004 20:31:39 +0000 Subject: [__APPLE__]: Include and . (main) [__APPLE__]: Get the processor type via syscall rather than hard-coding "powerpc". From toby@opendarwin.org. --- src/uname.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/uname.c') diff --git a/src/uname.c b/src/uname.c index 8380a6305..ffdc44a3e 100644 --- a/src/uname.c +++ b/src/uname.c @@ -46,6 +46,11 @@ # endif #endif +#ifdef __APPLE__ +#include +#include +#endif + #include "system.h" #include "error.h" #include "quote.h" @@ -259,10 +264,25 @@ main (int argc, char **argv) static int mib[] = { CTL_HW, UNAME_PROCESSOR }; if (sysctl (mib, 2, processor, &s, 0, 0) >= 0) element = processor; -# ifdef __POWERPC__ + +# ifdef __APPLE__ /* This kludge works around a bug in Mac OS X. */ if (element == unknown) - element = "powerpc"; + { + cpu_type_t cputype; + size_t s = sizeof cputype; + NXArchInfo const *ai; + if (sysctlbyname ("hw.cputype", &cputype, &s, NULL, 0) == 0 + && (ai = NXGetArchInfoFromCpuType (cputype, + CPU_SUBTYPE_MULTIPLE)) + != NULL) + element = ai->name; + + /* Hack "safely" around the ppc vs. powerpc return value. */ + if (cputype == CPU_TYPE_POWERPC + && strncmp (element, "ppc", 3) == 0) + element = "powerpc"; + } # endif } #endif -- cgit v1.2.3-54-g00ecf