source:
patches/coreutils-6.4-uname-1.patch@
405cd62
Last change on this file since 405cd62 was 7c0b4b3, checked in by , 18 years ago | |
---|---|
|
|
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 51 51 # include <mach-o/arch.h> 52 52 #endif 53 53 54 #if defined (__linux__) 55 # define USE_PROCINFO 56 # define UNAME_HARDWARE_PLATFORM 57 #endif 58 54 59 #include "system.h" 55 60 #include "error.h" 56 61 #include "quote.h" … … 138 143 exit (status); 139 144 } 140 145 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 159 static 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 173 static 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 141 246 /* Print ELEMENT, preceded by a space if something has already been 142 247 printed. */ 143 248 … … 250 355 if (toprint & PRINT_PROCESSOR) 251 356 { 252 357 char const *element = unknown; 253 #if HAVE_SYSINFO && defined SI_ARCHITECTURE358 #if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO) 254 359 { 255 360 static char processor[257]; 361 #if defined(USE_PROCINFO) 362 if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor)) 363 #else 256 364 if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) 365 #endif 257 366 element = processor; 258 367 } 259 368 #endif … … 306 415 if (element == unknown) 307 416 { 308 417 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 309 421 size_t s = sizeof hardware_platform; 310 422 static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM }; 311 423 if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0) 424 #endif 312 425 element = hardware_platform; 313 426 } 314 427 #endif
Note:
See TracBrowser
for help on using the repository browser.