Lines 44-49
Link Here
|
44 |
# endif |
44 |
# endif |
45 |
#endif |
45 |
#endif |
46 |
|
46 |
|
|
|
47 |
#if defined (__linux__) |
48 |
#define USE_PROCINFO |
49 |
#define UNAME_HARDWARE_PLATFORM |
50 |
#endif |
51 |
|
47 |
#include "system.h" |
52 |
#include "system.h" |
48 |
#include "error.h" |
53 |
#include "error.h" |
49 |
|
54 |
|
Lines 129-134
Link Here
|
129 |
exit (status); |
134 |
exit (status); |
130 |
} |
135 |
} |
131 |
|
136 |
|
|
|
137 |
/* Carlos E. Gorges <carlos@techlinux.com.br> - return vendor_id from proc cpuinfo */ |
138 |
#if defined(USE_PROCINFO) |
139 |
/* x==0, processor type | x==1, hardware-platform */ |
140 |
int |
141 |
__linux_procinfo (int x, char *fstr) |
142 |
{ |
143 |
FILE *ffd; |
144 |
char *cstr=calloc(64,sizeof(char)), |
145 |
*dstr=calloc(257,sizeof(char)), |
146 |
*retr=NULL; |
147 |
#if defined(__s390__) || defined(__s390x__) |
148 |
if ( ffd=fopen("/proc/sysinfo", "r") ) |
149 |
#else |
150 |
if ( ffd=fopen("/proc/cpuinfo", "r") ) |
151 |
#endif |
152 |
{ |
153 |
#if defined(__s390__) || defined(__s390x__) |
154 |
while ( fscanf(ffd, "%[^ :]%*[ :]%[^\n]\n", cstr, dstr) != EOF ) |
155 |
#else |
156 |
while ( fscanf(ffd, "%[^:\t]\t: %[^\n]\n", cstr, dstr) != EOF ) |
157 |
#endif |
158 |
{ |
159 |
char *sdata[] = |
160 |
{ |
161 |
#if defined(__i386__) |
162 |
"model name", "vendor_id" |
163 |
#endif |
164 |
#if defined(__ia64__) || defined(__x86_64__) |
165 |
"model", "vendor" |
166 |
#endif |
167 |
#if defined(__alpha__) |
168 |
"cpu model", "system type" |
169 |
#endif |
170 |
#if defined(sparc) || defined(__sparc__) |
171 |
"type", "cpu" |
172 |
#endif |
173 |
#if defined(__hppa__) |
174 |
"cpu", "model" |
175 |
#endif |
176 |
#if defined(__mips__) |
177 |
"cpu model", "system type" |
178 |
#endif |
179 |
#if defined(PPC) |
180 |
"cpu", "machine" |
181 |
#endif |
182 |
#if defined(__s390__) || defined(__s390x__) |
183 |
"Type", "Manufacturer" |
184 |
#endif |
185 |
}; |
186 |
|
187 |
if(!retr) |
188 |
{ |
189 |
if (!strcmp(cstr, sdata[x])) |
190 |
retr = strdup(dstr); |
191 |
} else |
192 |
break; |
193 |
|
194 |
} |
195 |
fclose(ffd); |
196 |
|
197 |
if(retr) |
198 |
{ |
199 |
#if defined(__s390__) || defined(__s390x__) |
200 |
while (strlen(retr) && isblank(retr[strlen(retr)-1])) |
201 |
retr[strlen(retr)-1] = 0; |
202 |
#endif |
203 |
strncpy(fstr,retr,257); |
204 |
return 1; |
205 |
} |
206 |
} |
207 |
return 0; |
208 |
} |
209 |
|
210 |
#endif |
211 |
|
212 |
|
132 |
/* Print ELEMENT, preceded by a space if something has already been |
213 |
/* Print ELEMENT, preceded by a space if something has already been |
133 |
printed. */ |
214 |
printed. */ |
134 |
|
215 |
|
Lines 243-255
Link Here
|
243 |
if (toprint & PRINT_PROCESSOR) |
324 |
if (toprint & PRINT_PROCESSOR) |
244 |
{ |
325 |
{ |
245 |
char const *element = unknown; |
326 |
char const *element = unknown; |
246 |
#if HAVE_SYSINFO && defined SI_ARCHITECTURE |
327 |
#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO) |
247 |
{ |
328 |
{ |
248 |
static char processor[257]; |
329 |
static char processor[257]; |
|
|
330 |
#if HAVE_SYSINFO && defined SI_ARCHITECTURE |
249 |
if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) |
331 |
if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor)) |
|
|
332 |
#endif |
333 |
#if defined(USE_PROCINFO) |
334 |
if( 0 <= __linux_procinfo(0, processor)) |
335 |
#endif |
250 |
element = processor; |
336 |
element = processor; |
251 |
} |
337 |
} |
252 |
#endif |
338 |
#endif |
|
|
339 |
|
253 |
#ifdef UNAME_PROCESSOR |
340 |
#ifdef UNAME_PROCESSOR |
254 |
if (element == unknown) |
341 |
if (element == unknown) |
255 |
{ |
342 |
{ |
Lines 278-286
Link Here
|
278 |
if (element == unknown) |
365 |
if (element == unknown) |
279 |
{ |
366 |
{ |
280 |
static char hardware_platform[257]; |
367 |
static char hardware_platform[257]; |
|
|
368 |
#if ! defined (USE_PROCINFO) |
281 |
size_t s = sizeof hardware_platform; |
369 |
size_t s = sizeof hardware_platform; |
282 |
static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM }; |
370 |
static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM }; |
283 |
if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0) |
371 |
if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0) |
|
|
372 |
#else |
373 |
if( 0 <= __linux_procinfo(1, hardware_platform)) |
374 |
#endif |
284 |
element = hardware_platform; |
375 |
element = hardware_platform; |
285 |
} |
376 |
} |
286 |
#endif |
377 |
#endif |
Lines 294-296
Link Here
|
294 |
|
385 |
|
295 |
exit (EXIT_SUCCESS); |
386 |
exit (EXIT_SUCCESS); |
296 |
} |
387 |
} |
|
|
388 |
|