summaryrefslogtreecommitdiff
path: root/src/gpu.c
diff options
context:
space:
mode:
author諏訪子 <suwako@076.moe>2024-06-19 15:44:06 +0900
committer諏訪子 <suwako@076.moe>2024-06-19 15:44:06 +0900
commit171b28947349399d5590210635e57957c80f2876 (patch)
treefc2c8756b887715f37246301d337defd97b46636 /src/gpu.c
parentb79c513c07be42378167f412fa9bc35303f1a94a (diff)
GPU情報は文字化(glxinfoを実効出来なければ、スキップ)
Diffstat (limited to 'src/gpu.c')
-rw-r--r--src/gpu.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/gpu.c b/src/gpu.c
index 168fe23..dbcd259 100644
--- a/src/gpu.c
+++ b/src/gpu.c
@@ -3,26 +3,53 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
-void run_gpu_command(const char *command) {
+const char *run_gpu_command(const char *command) {
+ if (
+ access("/bin/glxinfo", F_OK) == -1 ||
+ access("/usr/bin/glxinfo", F_OK) == -1 ||
+ access("/usr/local/bin/glxinfo", F_OK) == -1 ||
+ access("/usr/X11R6/bin/glxinfo", F_OK) == -1 ||
+ access("/usr/X11R7/bin/glxinfo", F_OK) == -1 ||
+ access("/usr/pkg/bin/glxinfo", F_OK) == -1
+ ) return NULL;
char buf[128];
+ char *out = NULL;
+ size_t outsize = 0;
FILE *p = popen(command, "r");
if (!p) {
fprintf(stderr, "GPUコマンドを実効に失敗: %s", command);
- 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 display_gpu() {
- run_gpu_command("glxinfo -B | grep -F 'OpenGL renderer string' | "
+const char *display_gpu() {
+ return run_gpu_command("glxinfo -B | grep -F 'OpenGL renderer string' | "
"sed 's/OpenGL renderer string: //' | sed 's/Mesa //' | "
"sed 's/DRI //' | sed 's/(R)//' | sed 's/(.*$//'");
}