summaryrefslogtreecommitdiff
path: root/src/distro.c
diff options
context:
space:
mode:
author諏訪子 <suwako@076.moe>2024-06-19 19:57:33 +0900
committer諏訪子 <suwako@076.moe>2024-06-19 19:57:33 +0900
commite8b7158d34bda940b31fca56c2c97b586d6ee937 (patch)
treeff03c51d5582d29b0d3020b12951eef2e599810b /src/distro.c
parentb40fc45106967a7fd58581c6218f70b3b376712f (diff)
Linux: ディストロのロゴの表示
Diffstat (limited to 'src/distro.c')
-rw-r--r--src/distro.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/distro.c b/src/distro.c
index f39d1ea..784b76e 100644
--- a/src/distro.c
+++ b/src/distro.c
@@ -2,13 +2,17 @@
#include "distro.h"
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
const char *distroname;
-void display_distro() {
+const char *display_distro() {
char buf[1288];
+ char *out = NULL;
+ size_t outsize = 0;
+
const char *cmd = NULL;
if (access("/bedrock/etc/bedrock-release", F_OK) != -1) {
@@ -45,14 +49,36 @@ void display_distro() {
FILE *p = popen(cmd, "r");
if (!p) {
fprintf(stderr, "ディストロを見つけられるコマンドを実効に失敗: %s", cmd);
- return;
+ return NULL;
}
while (fgets(buf, sizeof(buf), p) != NULL) {
buf[strcspn(buf, "\n")] = '\0';
- printf("%s", buf);
+
+ size_t len = strlen(buf);
+ char *nout = realloc(out, outsize + len + 1);
+ if (nout == NULL) {
+ perror("メモリの役割に失敗");
+ free(out);
+ pclose(p);
+ return NULL;
+ }
+
+ out = nout;
+
+ memccpy(out + outsize, buf, sizeof(buf), len);
+ outsize += len;
+ out[outsize] = '\0';
}
+ pclose(p);
+
+ return out;
+}
+
+void get_distro() {
+ const char *buf = display_distro();
+
if (strstr(buf, "Devuan") != NULL) distroname = "devuan";
else if (strstr(buf, "Void Linux") != NULL) distroname = "void";
else if (strstr(buf, "Debian") != NULL) distroname = "debian";
@@ -60,7 +86,5 @@ void display_distro() {
else if (strstr(buf, "Artix Linux") != NULL) distroname = "artix";
else if (strstr(buf, "CRUX") != NULL) distroname = "crux";
else distroname = "linux";
-
- pclose(p);
}
#endif