[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bugs #10778] uname: "correct" Darwin/Mac OS X patch
From: |
Jim Meyering |
Subject: |
Re: [bugs #10778] uname: "correct" Darwin/Mac OS X patch |
Date: |
Tue, 09 Nov 2004 21:53:59 +0100 |
>> Original Submission: I realize that this is fixed in CVS,
>> but I've attached a "correct" patch for uname -p on
>> Darwin/Mac OS X. Diff is against coreutils 5.2.1.
>>
>> It attempts to use the correct sysctl to determine the CPU type.
>> Unfortunately, I found it necessary to convert "ppc" to "powerpc".
> ...
>> I don't have a Savannah account, sorry.
>> Please feel free to email me at address@hidden
>
> Thanks a lot!
> I'm forwarding a copy of your patch to the bug-coreutils mailing list:
>
> --- src/uname.c.orig Wed Jan 21 17:27:02 2004
> +++ src/uname.c Sat Oct 23 04:37:29 2004
Thanks again.
I've applied that, modulo a couple of minor changes:
2004-11-07 Jim Meyering <address@hidden>
* src/uname.c [__APPLE__]: Include <mach/machine.h> and <mach-o/arch.h>.
(main) [__APPLE__]: Get the processor type via syscall rather than
hard-coding "powerpc". From address@hidden
Index: src/uname.c
===================================================================
RCS file: /fetish/cu/src/uname.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -p -u -r1.62 -r1.63
--- src/uname.c 21 Sep 2004 22:26:42 -0000 1.62
+++ src/uname.c 9 Nov 2004 20:31:39 -0000 1.63
@@ -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
- Re: [bugs #10778] uname: "correct" Darwin/Mac OS X patch,
Jim Meyering <=