Sweden-Number/misc/cpu.c

48 lines
857 B
C

/*
* What processor?
*
* Copyright 1995 Morten Welinder
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "windows.h"
int runtime_cpu (void)
{
#ifndef __i386__
return 5; /* Might as well pretend to be a Pentium... */
#else /* __i386__ */
static int cache = 0;
#ifdef linux
if (!cache)
{
FILE *f = fopen ("/proc/cpuinfo", "r");
cache = 3; /* Default. */
if (f)
{
char info[5], value[5];
while (fscanf (f, " %4s%*s : %4s%*s", info, value) == 2)
if (!lstrcmpi32A(info, "cpu"))
{
if (isdigit (value[0]) && value[1] == '8'
&& value[2] == '6' && value[3] == 0)
{
cache = value[0] - '0';
break;
}
}
fclose (f);
}
}
return cache;
#endif /* linux */
/* FIXME: how do we do this on other systems? */
return 3;
#endif /* __i386__ */
}