summaryrefslogtreecommitdiff
blob: ee1dcce04ab676ca125410fe2aac857e3b89ce69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
--- sh-utils-2.0.15/src/uname.c	Thu Jul 18 15:32:33 2002
+++ sh-utils-2.0.15-carlos/src/uname.c	Wed Sep  4 15:02:01 2002
@@ -44,6 +44,11 @@
 # endif
 #endif
 
+#if defined (__linux__)
+#define USE_PROCINFO	
+#define UNAME_HARDWARE_PLATFORM
+#endif
+
 #include "system.h"
 #include "error.h"
 #include "closeout.h"
@@ -130,6 +135,65 @@
   exit (status);
 }
 
+/* Carlos E. Gorges <carlos@techlinux.com.br> - return vendor_id from proc cpuinfo */
+#if defined(USE_PROCINFO)
+/* x==0, processor type | x==1, hardware-platform */
+int
+__linux_procinfo (int x, char *fstr) 
+{
+	FILE *ffd;
+	char 	*cstr=calloc(64,sizeof(char)),
+		*dstr=calloc(257,sizeof(char)),
+		*retr=NULL;
+
+	if ( ffd=fopen("/proc/cpuinfo", "r") )
+	{
+		while ( fscanf(ffd, "%[^:\t]\t: %[^\n]\n", cstr, dstr) != EOF )
+		{
+			char *sdata[] = 
+			{
+				#if defined(__i386__)
+					"model name", "vendor_id"
+				#endif
+				#if defined(__ia64__) || defined(__x86_64__)
+					"model", "vendor"
+				#endif
+				#if defined(__alpha__)
+					"cpu model", "???"
+				#endif
+				#if defined(sparc) || defined(__sparc__)
+					"type", "cpu"
+				#endif
+				#if defined(__mips__)
+					"processor", "system type"
+				#endif
+				#if defined(PPC)
+					"processor", "cpu"
+				#endif
+			};
+				
+			if(!retr)
+			{
+				if (!strcmp(cstr, sdata[x])) 
+						retr = strdup(dstr);
+			} else
+				break;
+			
+		}
+		fclose(ffd);
+
+		if(retr)
+		{
+			strncpy(fstr,retr,257);
+			return 1;
+		}
+	}
+	return 0;
+}
+
+#endif
+
+
 /* Print ELEMENT, preceded by a space if something has already been
    printed.  */
 
@@ -240,13 +304,19 @@
   if (toprint & PRINT_PROCESSOR)
     {
       char const *element = unknown;
-#if HAVE_SYSINFO && defined SI_ARCHITECTURE
+#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
       {
 	static char processor[257];
+#if HAVE_SYSINFO && defined SI_ARCHITECTURE
 	if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
+#endif
+#if defined(USE_PROCINFO)
+	if( 0 <= __linux_procinfo(0, processor))
+#endif
 	  element = processor;
       }
 #endif
+
 #ifdef UNAME_PROCESSOR
       if (element == unknown)
 	{
@@ -275,9 +345,13 @@
       if (element == unknown)
 	{
 	  static char hardware_platform[257];
+#if ! defined (USE_PROCINFO)
 	  size_t s = sizeof hardware_platform;
 	  static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
 	  if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
+#else
+	  if( 0 <= __linux_procinfo(1, hardware_platform))
+#endif
 	    element = hardware_platform;
 	}
 #endif
@@ -291,3 +365,4 @@
 
   exit (0);
 }
+