source:
clfs-sysroot/patches/coreutils-7.4-uname-1.patch@
11462e6
Last change on this file since 11462e6 was 9e7e74c, checked in by , 15 years ago | |
---|---|
|
|
File size: 4.4 KB |
-
coreutils-7.1
Submitted By: Jim Gifford <jim at cross-lfs dot org> Date: 2009-02-21 Initial Package Version: 7.1 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 Original Patch by - Matthew Burgess and Scot McPherson diff -Naur coreutils-7.1.orig/src/uname.c coreutils-7.1/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" … … 155 160 exit (status); 156 161 } 157 162 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 176 static 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 199 static 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 158 274 /* Print ELEMENT, preceded by a space if something has already been 159 275 printed. */ 160 276 … … 302 418 if (toprint & PRINT_PROCESSOR) 303 419 { 304 420 char const *element = unknown; 305 #if HAVE_SYSINFO && defined SI_ARCHITECTURE421 #if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO) 306 422 { 307 423 static char processor[257]; 424 #if defined(USE_PROCINFO) 425 if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor)) 426 #else 308 427 if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) 428 #endif 309 429 element = processor; 310 430 } 311 431 #endif … … 358 478 if (element == unknown) 359 479 { 360 480 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 361 484 size_t s = sizeof hardware_platform; 362 485 static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM }; 363 486 if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0) 487 #endif 364 488 element = hardware_platform; 365 489 } 366 490 #endif
Note:
See TracBrowser
for help on using the repository browser.