summaryrefslogtreecommitdiff
path: root/src/uname.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-11-09 20:31:39 +0000
committerJim Meyering <jim@meyering.net>2004-11-09 20:31:39 +0000
commit594d5064c950fa1d99a9eafbd357c5f46320d002 (patch)
treed556467525dd01ed17ff98dd1d0b2aef8d3d1b76 /src/uname.c
parent15c10278a76b46b1f7ab976ecc2d088febca68ad (diff)
downloadcoreutils-594d5064c950fa1d99a9eafbd357c5f46320d002.tar.xz
[__APPLE__]: Include <mach/machine.h> and <mach-o/arch.h>.
(main) [__APPLE__]: Get the processor type via syscall rather than hard-coding "powerpc". From toby@opendarwin.org.
Diffstat (limited to 'src/uname.c')
-rw-r--r--src/uname.c24
1 files changed, 22 insertions, 2 deletions
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 <mach/machine.h>
+#include <mach-o/arch.h>
+#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