]> sbz's 6dev Repos - android-sysinfo/.git/blame - sysinfo.c
Report CPU in output
[android-sysinfo/.git] / sysinfo.c
CommitLineData
e4b66277 1#include <fcntl.h>
410f5cae 2#include <stdio.h>
e4b66277
SB
3#include <stdlib.h>
4#include <string.h>
5#include <unistd.h>
410f5cae 6
e4b66277
SB
7#include <sys/types.h>
8#include <sys/uio.h>
410f5cae
SB
9#include <sys/utsname.h>
10#include <sys/system_properties.h>
11
12struct prop {
13 char *key_name;
14 char *prop_name;
15};
16
17static void system_kernel(void)
18{
19 struct utsname uts;
20 char build_host[512];
21 char build_user[512];
22
23 __system_property_get("ro.build.host", build_host);
24 __system_property_get("ro.build.user", build_user);
25
26 if (uname(&uts) != -1) {
27 printf("%-25s: %s %s %s@%s %s %s\n", "Kernel version", uts.sysname,
28 uts.release, build_user, build_host, uts.version, uts.machine);
29 }
30}
31
e4b66277
SB
32static void system_cpu(void)
33{
34 int i, fd, bytes;
35 char *p;
36 char buffer[1024];
37 const char *needle = "Processor :";
38
39 fd = open("/proc/cpuinfo", O_RDONLY);
40 if (fd == -1) {
41 return;
42 }
43
44 bytes = read(fd, buffer, sizeof(buffer) - 1);
45 if (bytes == -1) {
46 return;
47 }
48
49 buffer[bytes] = '\0';
50 p = buffer;
51
52 p = strstr(p, "Processor :");
53 p += strlen(needle) - 1;
54
55 printf("%-25s: ", "CPU");
56 while ( *p != '\n') {
57 printf("%c", *p++);
58 }
59
60 printf("\n");
61
62 close(fd);
63}
64
410f5cae
SB
65static void system_properties(struct prop *array, int size)
66{
67 int i, len;
68 char value[1024] = {0};
69
70 for (i=0; i < size; i++) {
71 if (i == 4)
72 system_kernel();
73
74 len = __system_property_get(array[i].prop_name, value);
75 value[len] = '\0';
76 printf("%-25s: %s\n", array[i].key_name, value);
77 }
78
e4b66277 79 system_cpu();
410f5cae
SB
80}
81
82int
83main(void)
84{
85 struct prop props[] = {
86 {.key_name = "Model number", .prop_name = "ro.product.model"},
87 {.key_name = "Android codename", .prop_name = "ro.build.product"},
88 {.key_name = "Android version", .prop_name = "ro.build.version.release"},
89 {.key_name = "Android SDK version", .prop_name = "ro.build.version.sdk"},
90 {.key_name = "Baseband version", .prop_name = "gsm.version.baseband"},
91 {.key_name = "Build number", .prop_name = "ro.build.display.id"},
92 };
93
94 system_properties(props, sizeof(props) / sizeof(props[0]));
95
96 return (0);
97}