source: patches/coreutils-8.9-uname-1.patch @ 6d1db7d

clfs-1.2clfs-2.1clfs-3.0.0-systemdclfs-3.0.0-sysvinitsystemdsysvinit
Last change on this file since 6d1db7d was d6c718d, checked in by Joe Ciccone <jciccone@…>, 13 years ago

Updated Coreutils to 8.9.

  • Property mode set to 100644
File size: 4.5 KB
  • coreutils-8.9

    Submitted By: Jim Gifford <jim at cross-lfs dot org>
    Date: 2010-07-26
    Initial Package Version: 5.97
    Upstream Status: Not Accepted
    Origin: Gentoo - http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/coreutils
    Description: Display CPU Information from /proc/cpuinfo or /proc/sysinfo
    
    Rediffed for 7.1 by Jim Gifford
    Rediffed for 7.5 by Jim Gifford
    Rediffed for 8.4 by Joe Ciccone
    Rediffed for 8.9 by Joe Ciccone
    
    old new  
    5050# include <mach-o/arch.h>
    5151#endif
    5252
     53#if defined (__linux__)
     54# define USE_PROCINFO
     55# define UNAME_HARDWARE_PLATFORM
     56#endif
     57
    5358#include "system.h"
    5459#include "error.h"
    5560#include "quote.h"
     
    155160  exit (status);
    156161}
    157162
     163#if defined(USE_PROCINFO)
     164
     165# if defined(__s390__) || defined(__s390x__)
     166#  define CPUINFO_FILE    "/proc/sysinfo"
     167#  define CPUINFO_FORMAT  "%64[^\t :]%*[ :]%256[^\n]%c"
     168# else
     169#  define CPUINFO_FILE    "/proc/cpuinfo"
     170#  define CPUINFO_FORMAT  "%64[^\t:]\t:%256[^\n]%c"
     171# endif
     172
     173# define PROCINFO_PROCESSOR      0
     174# define PROCINFO_HARDWARE_PLATFORM 1
     175
     176static void __eat_cpuinfo_space(char *buf)
     177{
     178        /* first eat trailing space */
     179        char *tmp = buf + strlen(buf) - 1;
     180        while (tmp > buf && isspace(*tmp))
     181                *tmp-- = '\0';
     182        /* then eat leading space */
     183        tmp = buf;
     184        while (*tmp && isspace(*tmp))
     185                tmp++;
     186        if (tmp != buf)
     187                memmove(buf, tmp, strlen(tmp)+1);
     188        /* finally collapse whitespace */
     189        tmp = buf;
     190        while (tmp[0] && tmp[1]) {
     191                if (isspace(tmp[0]) && isspace(tmp[1])) {
     192                        memmove(tmp, tmp+1, strlen(tmp));
     193                        continue;
     194                }
     195                ++tmp;
     196        }
     197}
     198
     199static int __linux_procinfo (int x, char *fstr, size_t s)
     200{
     201        FILE *fp;
     202
     203        char *procinfo_keys[] = {
     204                /* --processor --hardware-platform */
     205                #if defined(__alpha__)
     206                        "cpu model", "system type"
     207                #elif defined(__arm__)
     208                        "Processor", "Hardware"
     209                #elif defined(__avr32__)
     210                        "processor", "cpu family"
     211                #elif defined(__bfin__)
     212                        "CPU", "BOARD Name"
     213                #elif defined(__cris__)
     214                        "cpu", "cpu model"
     215                #elif defined(__frv__)
     216                        "CPU-Core", "System"
     217                #elif defined(__i386__) || defined(__x86_64__)
     218                        "model name", "vendor_id"
     219                #elif defined(__ia64__)
     220                        "family", "vendor"
     221                #elif defined(__hppa__)
     222                        "cpu", "model"
     223                #elif defined(__m68k__)
     224                        "CPU", "MMU"
     225                #elif defined(__mips__)
     226                        "cpu model", "system type"
     227                #elif defined(__powerpc__) || defined(__powerpc64__)
     228                        "cpu", "machine"
     229                #elif defined(__s390__) || defined(__s390x__)
     230                        "Type", "Manufacturer"
     231                #elif defined(__sh__)
     232                        "cpu type", "machine"
     233                #elif defined(sparc) || defined(__sparc__)
     234                        "type", "cpu"
     235                #elif defined(__vax__)
     236                        "cpu type", "cpu"
     237                #else
     238                        "unknown", "unknown"
     239                #endif
     240        };
     241
     242        if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
     243                char key[65], value[257], eol, *ret = NULL;
     244
     245                while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
     246                        __eat_cpuinfo_space(key);
     247                        if (!strcmp(key, procinfo_keys[x])) {
     248                                __eat_cpuinfo_space(value);
     249                                ret = value;
     250                                break;
     251                        }
     252                        if (eol != '\n') {
     253                                /* we need two fscanf's here in case the previous
     254                                 * length limit caused us to read right up to the
     255                                 * newline ... doing "%*[^\n]\n" wont eat the newline
     256                                 */
     257                                fscanf(fp, "%*[^\n]");
     258                                fscanf(fp, "\n");
     259                        }
     260                }
     261                fclose(fp);
     262
     263                if (ret) {
     264                        strncpy(fstr, ret, s);
     265                        return 0;
     266                }
     267        }
     268
     269        return -1;
     270}
     271
     272#endif
     273
    158274/* Print ELEMENT, preceded by a space if something has already been
    159275   printed.  */
    160276
     
    302418  if (toprint & PRINT_PROCESSOR)
    303419    {
    304420      char const *element = unknown;
    305 #if HAVE_SYSINFO && defined SI_ARCHITECTURE
     421#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
    306422      {
    307423        static char processor[257];
     424#if defined(USE_PROCINFO)
     425        if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor))
     426#else
    308427        if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
     428#endif
    309429          element = processor;
    310430      }
    311431#endif
     
    358478      if (element == unknown)
    359479        {
    360480          static char hardware_platform[257];
     481#if defined(USE_PROCINFO)
     482        if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform))
     483#else
    361484          size_t s = sizeof hardware_platform;
    362485          static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
    363486          if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
     487#endif
    364488            element = hardware_platform;
    365489        }
    366490#endif
Note: See TracBrowser for help on using the repository browser.