]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
[__APPLE__]: Include <mach/machine.h> and <mach-o/arch.h>.
authorJim Meyering <jim@meyering.net>
Tue, 9 Nov 2004 20:31:39 +0000 (20:31 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 9 Nov 2004 20:31:39 +0000 (20:31 +0000)
(main) [__APPLE__]: Get the processor type via syscall rather than
hard-coding "powerpc".  From toby@opendarwin.org.

src/uname.c

index 8380a63050303c25cf3ba6ec7fe01edad381b7d7..ffdc44a3e8ab70e047b5f81f640e4da10bb16d12 100644 (file)
 # 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