source:
clfs-sysroot/patches/coreutils-6.12-uname-1.patch@
30fab4d
Last change on this file since 30fab4d was 589e899, checked in by , 16 years ago | |
---|---|
|
|
File size: 4.2 KB |
-
coreutils-6.12
Submitted By: Jim Gifford <jim at linuxfromscratch dot org> Date: 2006-08-24 Initial Package Version: 5.97 Rediffed against 6.12 by Joe Ciccone on 2008-08-30 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-6.12.orig/src/uname.c coreutils-6.12/src/uname.c
old new 50 50 # include <mach-o/arch.h> 51 51 #endif 52 52 53 #if defined (__linux__) 54 # define USE_PROCINFO 55 # define UNAME_HARDWARE_PLATFORM 56 #endif 57 53 58 #include "system.h" 54 59 #include "error.h" 55 60 #include "quote.h" … … 158 163 exit (status); 159 164 } 160 165 166 #if defined(USE_PROCINFO) 167 168 # if defined(__s390__) || defined(__s390x__) 169 # define CPUINFO_FILE "/proc/sysinfo" 170 # define CPUINFO_FORMAT "%64[^\t :]%*[ :]%256[^\n]%c" 171 # else 172 # define CPUINFO_FILE "/proc/cpuinfo" 173 # define CPUINFO_FORMAT "%64[^\t:]\t:%256[^\n]%c" 174 # endif 175 176 # define PROCINFO_PROCESSOR 0 177 # define PROCINFO_HARDWARE_PLATFORM 1 178 179 static void __eat_cpuinfo_space(char *buf) 180 { 181 /* first eat trailing space */ 182 char *tmp = buf + strlen(buf) - 1; 183 while (tmp > buf && isspace(*tmp)) 184 *tmp-- = '\0'; 185 /* then eat leading space */ 186 tmp = buf; 187 while (*tmp && isspace(*tmp)) 188 tmp++; 189 if (tmp != buf) 190 memmove(buf, tmp, strlen(tmp)+1); 191 } 192 193 static int __linux_procinfo (int x, char *fstr, size_t s) 194 { 195 FILE *fp; 196 197 char *procinfo_keys[] = { 198 /* --processor --hardware-platform */ 199 #if defined(__alpha__) 200 "cpu model", "system type" 201 #elif defined(__arm__) 202 "Processor", "Hardware" 203 #elif defined(bfin) 204 "CPU", "BOARD Name" 205 #elif defined(__cris__) 206 "cpu", "cpu model" 207 #elif defined(__frv__) 208 "CPU-Core", "System" 209 #elif defined(__i386__) || defined(__x86_64__) 210 "model name", "vendor_id" 211 #elif defined(__ia64__) 212 "family", "vendor" 213 #elif defined(__hppa__) 214 "cpu", "model" 215 #elif defined(__m68k__) 216 "CPU", "MMU" 217 #elif defined(__mips__) 218 "cpu model", "system type" 219 #elif defined(__powerpc__) || defined(__powerpc64__) 220 "cpu", "machine" 221 #elif defined(__s390__) || defined(__s390x__) 222 "Type", "Manufacturer" 223 #elif defined(__sh__) 224 "cpu type", "machine" 225 #elif defined(sparc) || defined(__sparc__) 226 "type", "cpu" 227 #elif defined(__vax__) 228 "cpu type", "cpu" 229 #else 230 "unknown", "unknown" 231 #endif 232 }; 233 234 if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) { 235 char key[65], value[257], eol, *ret = NULL; 236 237 while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) { 238 __eat_cpuinfo_space(key); 239 if (!strcmp(key, procinfo_keys[x])) { 240 __eat_cpuinfo_space(value); 241 ret = value; 242 break; 243 } 244 if (eol != '\n') { 245 /* we need two fscanf's here in case the previous 246 * length limit caused us to read right up to the 247 * newline ... doing "%*[^\n]\n" wont eat the newline 248 */ 249 fscanf(fp, "%*[^\n]"); 250 fscanf(fp, "\n"); 251 } 252 } 253 fclose(fp); 254 255 if (ret) { 256 strncpy(fstr, ret, s); 257 return 0; 258 } 259 } 260 261 return -1; 262 } 263 264 #endif 265 161 266 /* Print ELEMENT, preceded by a space if something has already been 162 267 printed. */ 163 268 … … 305 410 if (toprint & PRINT_PROCESSOR) 306 411 { 307 412 char const *element = unknown; 308 #if HAVE_SYSINFO && defined SI_ARCHITECTURE413 #if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO) 309 414 { 310 415 static char processor[257]; 416 #if defined(USE_PROCINFO) 417 if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor)) 418 #else 311 419 if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) 420 #endif 312 421 element = processor; 313 422 } 314 423 #endif … … 361 470 if (element == unknown) 362 471 { 363 472 static char hardware_platform[257]; 473 #if defined(USE_PROCINFO) 474 if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform)) 475 #else 364 476 size_t s = sizeof hardware_platform; 365 477 static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM }; 366 478 if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0) 479 #endif 367 480 element = hardware_platform; 368 481 } 369 482 #endif
Note:
See TracBrowser
for help on using the repository browser.