diff options
author | Jim Meyering <jim@meyering.net> | 2002-07-18 18:28:53 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2002-07-18 18:28:53 +0000 |
commit | 510f7bfe8790b75cc84742626e4a171e3727bf1f (patch) | |
tree | 0c6896e0980c019789dba40d960e4cb26e6ee8ed /src | |
parent | 283c81ccddfdbdf4bca34a10bb07a9f4720a570c (diff) | |
download | coreutils-510f7bfe8790b75cc84742626e4a171e3727bf1f.tar.xz |
(UNAME_HARDWARE_PLATFORM, UNAME_PROCESSOR): New macros.
(main): Use them, along with sysctl, to support uname -i and uname -p
on BSD hosts.
Diffstat (limited to 'src')
-rw-r--r-- | src/uname.c | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/uname.c b/src/uname.c index b32ca8df2..d9acf74c4 100644 --- a/src/uname.c +++ b/src/uname.c @@ -29,6 +29,21 @@ # include <sys/systeminfo.h> #endif +#if HAVE_SYSCTL && HAVE_SYS_SYSCTL_H +# include <sys/param.h> /* needed for OpenBSD 3.0 */ +# include <sys/sysctl.h> +# ifdef HW_MODEL +# ifdef HW_MACHINE_ARCH +/* E.g., FreeBSD 4.5, NetBSD 1.5.2 */ +# define UNAME_HARDWARE_PLATFORM HW_MODEL +# define UNAME_PROCESSOR HW_MACHINE_ARCH +# else +/* E.g., OpenBSD 3.0 */ +# define UNAME_PROCESSOR HW_MODEL +# endif +# endif +#endif + #include "system.h" #include "error.h" #include "closeout.h" @@ -131,6 +146,7 @@ int main (int argc, char **argv) { int c; + static char const unknown[] = "unknown"; /* Mask indicating which elements to print. */ unsigned toprint = 0; @@ -223,24 +239,46 @@ main (int argc, char **argv) if (toprint & PRINT_PROCESSOR) { - char const *element = "unknown"; -#if HAVE_SYSINFO && defined SI_ARCHITECTURE + char const *element = unknown; char processor[257]; +#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE) if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) element = processor; #endif +#ifdef UNAME_PROCESSOR + if (element == unknown) + { + size_t s = sizeof processor; + int mib[2]; + mib[0] = CTL_HW; + mib[1] = UNAME_PROCESSOR; + if (sysctl (mib, 2, processor, &s, 0, 0) == 0) + element = processor; + } +#endif print_element (element); } if (toprint & PRINT_HARDWARE_PLATFORM) { - char const *element = "unknown"; -#if HAVE_SYSINFO && defined SI_PLATFORM + char const *element = unknown; char hardware_platform[257]; +#if defined (HAVE_SYSINFO) && defined (SI_PLATFORM) if (0 <= sysinfo (SI_PLATFORM, hardware_platform, sizeof hardware_platform)) element = hardware_platform; #endif +#ifdef UNAME_HARDWARE_PLATFORM + if (element == unknown) + { + size_t s = sizeof hardware_platform; + int mib[2]; + mib[0] = CTL_HW; + mib[1] = UNAME_HARDWARE_PLATFORM; + if (sysctl (mib, 2, hardware_platform, &s, 0, 0) == 0) + element = hardware_platform; + } +#endif print_element (element); } |