source: clfs-sysroot/patches/coreutils-6.7-uname-1.patch @ d26cc6e

Last change on this file since d26cc6e was d26cc6e, checked in by Joe Ciccone <jciccone@…>, 17 years ago

Update Coreutils patches.

  • Property mode set to 100644
File size: 4.2 KB
  • coreutils-5.97

    Submitted By: Jim Gifford <jim at linuxfromscratch dot org>
    Date: 2006-08-24
    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
    
    Original Patch by - Matthew Burgess and Scot McPherson
    
    diff -Naur coreutils-5.97.orig/src/uname.c coreutils-5.97/src/uname.c
    old new  
    5151# include <mach-o/arch.h>
    5252#endif
    5353
     54#if defined (__linux__)
     55# define USE_PROCINFO
     56# define UNAME_HARDWARE_PLATFORM
     57#endif
     58
    5459#include "system.h"
    5560#include "error.h"
    5661#include "quote.h"
     
    138143  exit (status);
    139144}
    140145
     146#if defined(USE_PROCINFO)
     147
     148# if defined(__s390__) || defined(__s390x__)
     149#  define CPUINFO_FILE    "/proc/sysinfo"
     150#  define CPUINFO_FORMAT  "%64[^\t :]%*[ :]%256[^\n]%c"
     151# else
     152#  define CPUINFO_FILE    "/proc/cpuinfo"
     153#  define CPUINFO_FORMAT  "%64[^\t:]\t:%256[^\n]%c"
     154# endif
     155
     156# define PROCINFO_PROCESSOR      0
     157# define PROCINFO_HARDWARE_PLATFORM 1
     158
     159static void __eat_cpuinfo_space(char *buf)
     160{
     161        /* first eat trailing space */
     162        char *tmp = buf + strlen(buf) - 1;
     163        while (tmp > buf && isspace(*tmp))
     164                *tmp-- = '\0';
     165        /* then eat leading space */
     166        tmp = buf;
     167        while (*tmp && isspace(*tmp))
     168                tmp++;
     169        if (tmp != buf)
     170                memmove(buf, tmp, strlen(tmp)+1);
     171}
     172
     173static int __linux_procinfo (int x, char *fstr, size_t s)
     174{
     175        FILE *fp;
     176
     177        char *procinfo_keys[] = {
     178                /* --processor --hardware-platform */
     179                #if defined(__alpha__)
     180                        "cpu model", "system type"
     181                #elif defined(__arm__)
     182                        "Processor", "Hardware"
     183                #elif defined(bfin)
     184                        "CPU", "BOARD Name"
     185                #elif defined(__cris__)
     186                        "cpu", "cpu model"
     187                #elif defined(__frv__)
     188                        "CPU-Core", "System"
     189                #elif defined(__i386__) || defined(__x86_64__)
     190                        "model name", "vendor_id"
     191                #elif defined(__ia64__)
     192                        "family", "vendor"
     193                #elif defined(__hppa__)
     194                        "cpu", "model"
     195                #elif defined(__m68k__)
     196                        "CPU", "MMU"
     197                #elif defined(__mips__)
     198                        "cpu model", "system type"
     199                #elif defined(__powerpc__) || defined(__powerpc64__)
     200                        "cpu", "machine"
     201                #elif defined(__s390__) || defined(__s390x__)
     202                        "Type", "Manufacturer"
     203                #elif defined(__sh__)
     204                        "cpu type", "machine"
     205                #elif defined(sparc) || defined(__sparc__)
     206                        "type", "cpu"
     207                #elif defined(__vax__)
     208                        "cpu type", "cpu"
     209                #else
     210                        "unknown", "unknown"
     211                #endif
     212        };
     213
     214        if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
     215                char key[65], value[257], eol, *ret = NULL;
     216
     217                while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
     218                        __eat_cpuinfo_space(key);
     219                        if (!strcmp(key, procinfo_keys[x])) {
     220                                __eat_cpuinfo_space(value);
     221                                ret = value;
     222                                break;
     223                        }
     224                        if (eol != '\n') {
     225                                /* we need two fscanf's here in case the previous
     226                                 * length limit caused us to read right up to the
     227                                 * newline ... doing "%*[^\n]\n" wont eat the newline
     228                                 */
     229                                fscanf(fp, "%*[^\n]");
     230                                fscanf(fp, "\n");
     231                        }
     232                }
     233                fclose(fp);
     234
     235                if (ret) {
     236                        strncpy(fstr, ret, s);
     237                        return 0;
     238                }
     239        }
     240
     241        return -1;
     242}
     243
     244#endif
     245
    141246/* Print ELEMENT, preceded by a space if something has already been
    142247   printed.  */
    143248
     
    250355  if (toprint & PRINT_PROCESSOR)
    251356    {
    252357      char const *element = unknown;
    253 #if HAVE_SYSINFO && defined SI_ARCHITECTURE
     358#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
    254359      {
    255360        static char processor[257];
     361#if defined(USE_PROCINFO)
     362        if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor))
     363#else
    256364        if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
     365#endif
    257366          element = processor;
    258367      }
    259368#endif
     
    306415      if (element == unknown)
    307416        {
    308417          static char hardware_platform[257];
     418#if defined(USE_PROCINFO)
     419          if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform))
     420#else
    309421          size_t s = sizeof hardware_platform;
    310422          static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
    311423          if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
     424#endif
    312425            element = hardware_platform;
    313426        }
    314427#endif
Note: See TracBrowser for help on using the repository browser.