1 Submitted by: DJ Lucas (dj_at_linuxfromscratch_dot_org)
3 Initial Package Version: 8.16
4 Upstream Status: Rejected
5 Origin: Based on Gentoo patch
6 Description: Makes uname -m output more descriptive
8 diff -Naurp coreutils-8.16-orig/src/uname.c coreutils-8.16/src/uname.c
9 --- coreutils-8.16-orig/src/uname.c 2012-04-22 20:02:39.000000000 +0000
10 +++ coreutils-8.16/src/uname.c 2012-04-22 20:02:50.000000000 +0000
12 # include <mach-o/arch.h>
15 +#if defined(__linux__)
16 +# define USE_PROCINFO
17 +# define UNAME_HARDWARE_PLATFORM
23 @@ -153,6 +158,117 @@ Print machine architecture.\n\
27 +#if defined(USE_PROCINFO)
29 +# if defined(__s390__) || defined(__s390x__)
30 +# define CPUINFO_FILE "/proc/sysinfo"
31 +# define CPUINFO_FORMAT "%64[^\t :]%*[ :]%256[^\n]%c"
33 +# define CPUINFO_FILE "/proc/cpuinfo"
34 +# define CPUINFO_FORMAT "%64[^\t:]\t:%256[^\n]%c"
37 +# define PROCINFO_PROCESSOR 0
38 +# define PROCINFO_HARDWARE_PLATFORM 1
40 +static void __eat_cpuinfo_space(char *buf)
42 + /* first eat trailing space */
43 + char *tmp = buf + strlen(buf) - 1;
44 + while (tmp > buf && isspace(*tmp))
46 + /* then eat leading space */
48 + while (*tmp && isspace(*tmp))
51 + memmove(buf, tmp, strlen(tmp)+1);
52 + /* finally collapse whitespace */
54 + while (tmp[0] && tmp[1]) {
55 + if (isspace(tmp[0]) && isspace(tmp[1])) {
56 + memmove(tmp, tmp+1, strlen(tmp));
63 +static int __linux_procinfo(int x, char *fstr, size_t s)
67 + char *procinfo_keys[] = {
68 + /* --processor --hardware-platform */
69 + #if defined(__alpha__)
70 + "cpu model", "system type"
71 + #elif defined(__arm__)
72 + "Processor", "Hardware"
73 + #elif defined(__avr32__)
74 + "processor", "cpu family"
75 + #elif defined(__bfin__)
77 + #elif defined(__cris__)
79 + #elif defined(__frv__)
80 + "CPU-Core", "System"
81 + #elif defined(__i386__) || defined(__x86_64__)
82 + "model name", "vendor_id"
83 + #elif defined(__ia64__)
85 + #elif defined(__hppa__)
87 + #elif defined(__m68k__)
89 + #elif defined(__mips__)
90 + "cpu model", "system type"
91 + #elif defined(__powerpc__) || defined(__powerpc64__)
93 + #elif defined(__s390__) || defined(__s390x__)
94 + "Type", "Manufacturer"
95 + #elif defined(__sh__)
96 + "cpu type", "machine"
97 + #elif defined(sparc) || defined(__sparc__)
99 + #elif defined(__vax__)
102 + "unknown", "unknown"
106 + if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
107 + char key[65], value[257], eol, *ret = NULL;
109 + while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
110 + __eat_cpuinfo_space(key);
111 + if (!strcmp(key, procinfo_keys[x])) {
112 + __eat_cpuinfo_space(value);
117 + /* we need two fscanf's here in case the previous
118 + * length limit caused us to read right up to the
119 + * newline ... doing "%*[^\n]\n" wont eat the newline
121 + fscanf(fp, "%*[^\n]");
128 + strncpy(fstr, ret, s);
138 /* Print ELEMENT, preceded by a space if something has already been
141 @@ -300,10 +416,14 @@ main (int argc, char **argv)
142 if (toprint & PRINT_PROCESSOR)
144 char const *element = unknown;
145 -#if HAVE_SYSINFO && defined SI_ARCHITECTURE
146 +#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
148 static char processor[257];
149 +#if defined(USE_PROCINFO)
150 + if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor))
152 if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
157 @@ -356,9 +476,13 @@ main (int argc, char **argv)
158 if (element == unknown)
160 static char hardware_platform[257];
161 +#if defined(USE_PROCINFO)
162 + if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform))
164 size_t s = sizeof hardware_platform;
165 static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
166 if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
168 element = hardware_platform;