OSDN Git Service

Fix no pic
[uclinux-h8/uClinux-dist.git] / user / tpt / util.c
1 /*
2  * $Header: /cvs/sw/new-wave/user/tpt/util.c,v 1.1 2002-02-14 23:04:55 pauli Exp $
3  */
4
5 #include <stdio.h>
6
7 #include "tpt.h"
8
9 int
10 get_mhz(void)
11 {
12         FILE *f = fopen("/proc/cpuinfo", "r");
13         if (f == 0)
14         {
15                 perror("can't open /proc/cpuinfo\n");
16                 exit(1);
17         }
18
19         for ( ; ; )
20         {
21                 int mhz;
22                 int ret;
23                 char buf[1000];
24
25                 if (fgets(buf, sizeof(buf), f) == NULL)
26                 {
27                         fprintf(stderr, "cannot locate cpu MHz in /proc/cpuinfo\n");
28                         exit(1);
29                 }
30
31                 ret = sscanf(buf, "cpu MHz         : %d", &mhz);
32
33                 if (ret == 1)
34                 {
35                         fclose(f);
36                         return mhz;
37                 }
38         }
39 }
40
41