From a19f9253c46f191ce41858f8c6a37bbb02f8ba87 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 18 Jul 2002 18:35:42 +0000 Subject: (main): Test sysctl(...) >= 0, not == 0, since on NetBSD the return value may well be positive. Use one-line aggregate initializations. Use tightly scoped static buffers to avoid warnings about unused variables on some systems. --- src/uname.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'src/uname.c') diff --git a/src/uname.c b/src/uname.c index d9acf74c4..3b9403724 100644 --- a/src/uname.c +++ b/src/uname.c @@ -240,19 +240,20 @@ main (int argc, char **argv) if (toprint & PRINT_PROCESSOR) { char const *element = unknown; - char processor[257]; -#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE) - if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) - element = processor; +#if HAVE_SYSINFO && defined SI_ARCHITECTURE + { + static char processor[257]; + if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) + element = processor; + } #endif #ifdef UNAME_PROCESSOR if (element == unknown) { + static char processor[257]; 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) + static int mib[] = { CTL_HW, UNAME_PROCESSOR }; + if (sysctl (mib, 2, processor, &s, 0, 0) >= 0) element = processor; } #endif @@ -262,20 +263,21 @@ main (int argc, char **argv) if (toprint & PRINT_HARDWARE_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; +#if HAVE_SYSINFO && defined SI_PLATFORM + { + static char hardware_platform[257]; + if (0 <= sysinfo (SI_PLATFORM, + hardware_platform, sizeof hardware_platform)) + element = hardware_platform; + } #endif #ifdef UNAME_HARDWARE_PLATFORM if (element == unknown) { + static char hardware_platform[257]; 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) + static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM }; + if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0) element = hardware_platform; } #endif -- cgit v1.2.3-54-g00ecf