--- sh-utils-2.0.15/src/uname.c Thu Jul 18 15:32:33 2002 +++ sh-utils-2.0.15-carlos/src/uname.c Wed Sep 4 15:02:01 2002 @@ -44,6 +44,11 @@ # endif #endif +#if defined (__linux__) +#define USE_PROCINFO +#define UNAME_HARDWARE_PLATFORM +#endif + #include "system.h" #include "error.h" #include "closeout.h" @@ -130,6 +135,65 @@ exit (status); } +/* Carlos E. Gorges - return vendor_id from proc cpuinfo */ +#if defined(USE_PROCINFO) +/* x==0, processor type | x==1, hardware-platform */ +int +__linux_procinfo (int x, char *fstr) +{ + FILE *ffd; + char *cstr=calloc(64,sizeof(char)), + *dstr=calloc(257,sizeof(char)), + *retr=NULL; + + if ( ffd=fopen("/proc/cpuinfo", "r") ) + { + while ( fscanf(ffd, "%[^:\t]\t: %[^\n]\n", cstr, dstr) != EOF ) + { + char *sdata[] = + { + #if defined(__i386__) + "model name", "vendor_id" + #endif + #if defined(__ia64__) || defined(__x86_64__) + "model", "vendor" + #endif + #if defined(__alpha__) + "cpu model", "???" + #endif + #if defined(sparc) || defined(__sparc__) + "type", "cpu" + #endif + #if defined(__mips__) + "cpu model", "system type" + #endif + #if defined(PPC) + "processor", "cpu" + #endif + }; + + if(!retr) + { + if (!strcmp(cstr, sdata[x])) + retr = strdup(dstr); + } else + break; + + } + fclose(ffd); + + if(retr) + { + strncpy(fstr,retr,257); + return 1; + } + } + return 0; +} + +#endif + + /* Print ELEMENT, preceded by a space if something has already been printed. */ @@ -240,13 +304,19 @@ if (toprint & PRINT_PROCESSOR) { char const *element = unknown; -#if HAVE_SYSINFO && defined SI_ARCHITECTURE +#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO) { static char processor[257]; +#if HAVE_SYSINFO && defined SI_ARCHITECTURE if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) +#endif +#if defined(USE_PROCINFO) + if( 0 <= __linux_procinfo(0, processor)) +#endif element = processor; } #endif + #ifdef UNAME_PROCESSOR if (element == unknown) { @@ -275,9 +345,13 @@ if (element == unknown) { static char hardware_platform[257]; +#if ! defined (USE_PROCINFO) size_t s = sizeof hardware_platform; static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM }; if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0) +#else + if( 0 <= __linux_procinfo(1, hardware_platform)) +#endif element = hardware_platform; } #endif @@ -291,3 +365,4 @@ exit (0); } +