summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cpu.c35
-rw-r--r--src/cpu.h6
-rw-r--r--src/uptime.c31
-rw-r--r--src/uptime.h7
4 files changed, 79 insertions, 0 deletions
diff --git a/src/cpu.c b/src/cpu.c
new file mode 100644
index 0000000..9b79eca
--- /dev/null
+++ b/src/cpu.c
@@ -0,0 +1,35 @@
+#include "memory.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+void run_cpu_command(const char *command) {
+ char buf[128];
+
+ FILE *p = popen(command, "r");
+ if (!p) {
+ fprintf(stderr, "ホストコマンドを実効に失敗: %s", command);
+ return;
+ }
+
+ while (fgets(buf, sizeof(buf), p) != NULL) {
+ buf[strcspn(buf, "\n")] = '\0';
+ printf("%s", buf);
+ }
+
+ pclose(p);
+}
+
+void display_cpu() {
+#if defined(__NetBSD__)
+ run_cpu_command("sysctl -n machdep.cpu_brand | sed 's/(R)//' | "
+ "sed 's/(TM)//' | sed 's/CPU //'");
+ run_cpu_command("echo \" (\" && sysctl -n hw.ncpu && echo \" core)\"");
+#elif defined(__FreeBSD__) || defined(__OpenBSD__)
+ run_cpu_command("sysctl -n hw.model | sed 's/(R)//' | "
+ "sed 's/(TM)//' | sed 's/CPU //'");
+ run_cpu_command("echo \" (\" && sysctl -n hw.ncpu && echo \" core)\"");
+#elif defined(__linux__)
+#endif
+}
diff --git a/src/cpu.h b/src/cpu.h
new file mode 100644
index 0000000..89a810a
--- /dev/null
+++ b/src/cpu.h
@@ -0,0 +1,6 @@
+#ifndef CPU_H
+#define CPU_H
+
+void display_cpu();
+
+#endif
diff --git a/src/uptime.c b/src/uptime.c
new file mode 100644
index 0000000..da19270
--- /dev/null
+++ b/src/uptime.c
@@ -0,0 +1,31 @@
+#include "memory.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+void run_uptime_command(const char *command) {
+ char buf[128];
+
+ FILE *p = popen(command, "r");
+ if (!p) {
+ fprintf(stderr, "ホストコマンドを実効に失敗: %s", command);
+ return;
+ }
+
+ while (fgets(buf, sizeof(buf), p) != NULL) {
+ buf[strcspn(buf, "\n")] = '\0';
+ printf("%s", buf);
+ }
+
+ pclose(p);
+}
+
+void display_days() {
+ run_uptime_command("uptime | awk '{print $3}' && echo \" days\"");
+}
+
+void display_time() {
+ run_uptime_command("uptime | awk '{print $5}' | sed 's/,//' | "
+ "sed 's/:/ hours, /' && echo \" mins\"");
+}
diff --git a/src/uptime.h b/src/uptime.h
new file mode 100644
index 0000000..12ee668
--- /dev/null
+++ b/src/uptime.h
@@ -0,0 +1,7 @@
+#ifndef UPTIME_H
+#define UPTIME_H
+
+void display_days();
+void display_time();
+
+#endif