Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 135562
Collapse All | Expand All

(-)coreutils-5.96.orig/src/uname.c (-1 / +103 lines)
Lines 51-56 Link Here
51
# include <mach-o/arch.h>
51
# include <mach-o/arch.h>
52
#endif
52
#endif
53
53
54
#if defined (__linux__)
55
# define USE_PROCINFO
56
# define UNAME_HARDWARE_PLATFORM
57
#endif
58
54
#include "system.h"
59
#include "system.h"
55
#include "error.h"
60
#include "error.h"
56
#include "quote.h"
61
#include "quote.h"
Lines 138-143 Print certain system information. With Link Here
138
  exit (status);
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  "%[^\t :]%*[ :]%[^\n]\n"
151
# else
152
#  define CPUINFO_FILE    "/proc/cpuinfo"
153
#  define CPUINFO_FORMAT  "%[^\t:]\t:%[^\n]\n"
154
# endif
155
156
# define PROCINFO_ARCHITECTURE      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
		#if defined(__i386__) || defined(__x86_64__)
179
			"model name", "vendor_id"
180
		#elif defined(__ia64__)
181
			"family", "vendor"
182
		#elif defined(__alpha__)
183
			"cpu model", "system type"
184
		#elif defined(sparc) || defined(__sparc__)
185
			"type", "cpu"
186
		#elif defined(__hppa__)
187
			"cpu", "model"
188
		#elif defined(__mips__)
189
			"cpu model", "system type"
190
		#elif defined(__powerpc__) || defined(__powerpc64__)
191
			"cpu", "machine"
192
		#elif defined(__arm__)
193
			"Processor", "Hardware"
194
		#elif defined(__s390__) || defined(__s390x__)
195
			"Type", "Manufacturer"
196
		#elif defined(__sh__)
197
			"cpu family", "machine"
198
		#elif defined(__m68k__)
199
			"CPU", "MMU"
200
		#elif defined(__cris__)
201
			"cpu", "cpu model"
202
		#elif defined(__frv__)
203
			"CPU-Core", "System"
204
		#elif defined(bfin)
205
			"CPU", "BOARD Name"
206
		#else
207
			"unknown", "unknown"
208
		#endif
209
	};
210
211
	if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
212
		char key[64], value[257], *ret = NULL;
213
214
		while (fscanf(fp, CPUINFO_FORMAT, key, value) != EOF) {
215
			__eat_cpuinfo_space(key);
216
			if (!strcmp(key, procinfo_keys[x])) {
217
				__eat_cpuinfo_space(value);
218
				ret = value;
219
				break;
220
			}
221
		}
222
		fclose(fp);
223
224
		if (ret) {
225
			strncpy(fstr, ret, s);
226
			return 0;
227
		}
228
	}
229
230
	return -1;
231
}
232
233
#endif
234
141
/* Print ELEMENT, preceded by a space if something has already been
235
/* Print ELEMENT, preceded by a space if something has already been
142
   printed.  */
236
   printed.  */
143
237
Lines 250-259 main (int argc, char **argv) Link Here
250
  if (toprint & PRINT_PROCESSOR)
344
  if (toprint & PRINT_PROCESSOR)
251
    {
345
    {
252
      char const *element = unknown;
346
      char const *element = unknown;
253
#if HAVE_SYSINFO && defined SI_ARCHITECTURE
347
#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
254
      {
348
      {
255
	static char processor[257];
349
	static char processor[257];
350
#if defined(USE_PROCINFO)
351
	if (0 <= __linux_procinfo (PROCINFO_ARCHITECTURE, processor, sizeof processor))
352
#else
256
	if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
353
	if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
354
#endif
257
	  element = processor;
355
	  element = processor;
258
      }
356
      }
259
#endif
357
#endif
Lines 306-314 main (int argc, char **argv) Link Here
306
      if (element == unknown)
404
      if (element == unknown)
307
	{
405
	{
308
	  static char hardware_platform[257];
406
	  static char hardware_platform[257];
407
#if defined(USE_PROCINFO)
408
	  if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform))
409
#else
309
	  size_t s = sizeof hardware_platform;
410
	  size_t s = sizeof hardware_platform;
310
	  static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
411
	  static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
311
	  if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
412
	  if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
413
#endif
312
	    element = hardware_platform;
414
	    element = hardware_platform;
313
	}
415
	}
314
#endif
416
#endif

Return to bug 135562