summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author諏訪子 <suwako@076.moe>2024-06-18 01:40:09 +0900
committer諏訪子 <suwako@076.moe>2024-06-18 01:40:09 +0900
commit759ca0074f7275b0bd1e58bc88ad2779035c9fb8 (patch)
tree6349a57c169242944af0080d3f70a58a4612e697 /src
parent11c97887ef28e9b073d9abf1c2da70cd01491c9e (diff)
NetBSDでの修正
Diffstat (limited to 'src')
-rw-r--r--src/host.c8
-rw-r--r--src/user.c27
2 files changed, 22 insertions, 13 deletions
diff --git a/src/host.c b/src/host.c
index ebafe13..12df5d3 100644
--- a/src/host.c
+++ b/src/host.c
@@ -27,9 +27,13 @@ void run_command(const char *command) {
}
void display_host_model() {
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
- defined(__DragonFly__) || defined(__minix)
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || \
+ defined(__DragonFly__)
run_command("sysctl -n hw.vendor hw.product");
+#elif defined(__NetBSD__)
+ run_command("sysctl -n machdep.dmi.system-vendor && "
+ "echo \" \" && sysctl -n machdep.dmi.system-version && "
+ "echo \" \" && sysctl -n machdep.dmi.system-product");
#elif defined(__sun)
run_command("prtconf -b | awk -F':' '/banner-name/ {printf $2}'");
#elif defined(__linux__)
diff --git a/src/user.c b/src/user.c
index 27a6b79..9c01c82 100644
--- a/src/user.c
+++ b/src/user.c
@@ -21,6 +21,20 @@ void display_user_name() {
void display_user_host() {
char buf[64];
+#ifdef __NetBSD__
+ FILE *p = popen("hostname", "r");
+ if (!p) {
+ perror("hostnameコマンドを見つけられません。");
+ return;
+ }
+
+ while (fgets(buf, sizeof(buf), p) != NULL) {
+ buf[strcspn(buf, "\n")] = '\0';
+ printf("%s", buf);
+ }
+
+ pclose(p);
+#else
const char *filename;
#ifdef __OpenBSD__
filename = "/etc/myname";
@@ -29,7 +43,7 @@ void display_user_host() {
#endif
FILE *f = fopen(filename, "r");
if (!f) {
- snprintf(buf, sizeof(buf), "「%s」を見つけられません。", filename);
+ snprintf(buf, sizeof(buf), "「%s」ファイルを見つけられません。", filename);
perror(buf);
return;
}
@@ -38,15 +52,6 @@ void display_user_host() {
printf("%s", buf);
}
- /* char hostname[128]; */
- /* int cnt = 0; */
- /* for (int i = 0; i < 128; i++) { */
- /* unsigned char key; */
- /* fread(&key, sizeof(key), 1, f); */
- /* hostname[i] = key; */
- /* cnt += 1; */
- /* } */
-
- /* hostname[cnt] = '\0'; */
fclose(f);
+#endif
}