summaryrefslogtreecommitdiffstats
path: root/src/detection/libc
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/libc
Add the files
Diffstat (limited to 'src/detection/libc')
-rw-r--r--src/detection/libc/libc.h10
-rw-r--r--src/detection/libc/libc_android.c24
-rw-r--r--src/detection/libc/libc_apple.c12
-rw-r--r--src/detection/libc/libc_bsd.c20
-rw-r--r--src/detection/libc/libc_linux.c25
-rw-r--r--src/detection/libc/libc_nosupport.c7
-rw-r--r--src/detection/libc/libc_windows.cpp68
7 files changed, 166 insertions, 0 deletions
diff --git a/src/detection/libc/libc.h b/src/detection/libc/libc.h
new file mode 100644
index 0000000..f2718e8
--- /dev/null
+++ b/src/detection/libc/libc.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "fastfetch.h"
+
+typedef struct FFLibcResult {
+ const char* name;
+ const char* version;
+} FFLibcResult;
+
+const char* ffDetectLibc(FFLibcResult* result);
diff --git a/src/detection/libc/libc_android.c b/src/detection/libc/libc_android.c
new file mode 100644
index 0000000..2aec4ed
--- /dev/null
+++ b/src/detection/libc/libc_android.c
@@ -0,0 +1,24 @@
+#include "libc.h"
+
+#define FF_STR_INDIR(x) #x
+#define FF_STR(x) FF_STR_INDIR(x)
+
+#include <features.h>
+
+const char* ffDetectLibc(FFLibcResult* result) {
+#if __ANDROID_NDK__
+ result->name = "ndk-bionic";
+ result->version = FF_STR(__NDK_MAJOR__) "." FF_STR(__NDK_MINOR__) "." FF_STR(__NDK_BUILD__)
+
+ #if __NDK_BETA__
+ "-beta" FF_STR(__NDK_BETA__)
+ #elif __NDK_CANARY__
+ "-canary"
+ #endif
+
+ ;
+ return NULL;
+#else
+ return "Unknown Android libc";
+#endif
+}
diff --git a/src/detection/libc/libc_apple.c b/src/detection/libc/libc_apple.c
new file mode 100644
index 0000000..07ca2b5
--- /dev/null
+++ b/src/detection/libc/libc_apple.c
@@ -0,0 +1,12 @@
+#include "libc.h"
+
+const char* ffDetectLibc(FFLibcResult* result) {
+ result->name = "libSystem";
+
+#ifdef FF_LIBSYSTEM_VERSION
+ result->version = FF_LIBSYSTEM_VERSION;
+#else
+ result->version = NULL;
+#endif
+ return NULL;
+}
diff --git a/src/detection/libc/libc_bsd.c b/src/detection/libc/libc_bsd.c
new file mode 100644
index 0000000..bd73165
--- /dev/null
+++ b/src/detection/libc/libc_bsd.c
@@ -0,0 +1,20 @@
+#include "libc.h"
+
+const char* ffDetectLibc(FFLibcResult* result) {
+ result->name = "Unknown";
+ result->version = NULL;
+
+#ifdef __DragonFly__ // We define `__FreeBSD__` on DragonFly BSD for simplification
+ result->name = "DF";
+ #ifdef FF_DF_VERSION
+ result->version = FF_DF_VERSION;
+ #endif
+#elif __FreeBSD__
+ result->name = "FBSD";
+ #ifdef FF_FBSD_VERSION
+ result->version = FF_FBSD_VERSION;
+ #endif
+#endif
+
+ return NULL;
+}
diff --git a/src/detection/libc/libc_linux.c b/src/detection/libc/libc_linux.c
new file mode 100644
index 0000000..53186a3
--- /dev/null
+++ b/src/detection/libc/libc_linux.c
@@ -0,0 +1,25 @@
+#include "libc.h"
+
+#define FF_STR_INDIR(x) #x
+#define FF_STR(x) FF_STR_INDIR(x)
+
+#include <features.h>
+
+const char* ffDetectLibc(FFLibcResult* result) {
+#ifdef __UCLIBC__
+ result->name = "uClibc";
+ result->version = FF_STR(__UCLIBC_MAJOR__) "." FF_STR(__UCLIBC_MINOR__) "." FF_STR(__UCLIBC_SUBLEVEL__);
+#elif defined(__GNU_LIBRARY__)
+ result->name = "glibc";
+ result->version = FF_STR(__GLIBC__) "." FF_STR(__GLIBC_MINOR__);
+#else
+ result->name = "musl";
+ #ifdef FF_MUSL_VERSION
+ result->version = FF_MUSL_VERSION;
+ #else
+ result->version = NULL;
+ #endif
+#endif
+
+ return NULL;
+}
diff --git a/src/detection/libc/libc_nosupport.c b/src/detection/libc/libc_nosupport.c
new file mode 100644
index 0000000..e4687b0
--- /dev/null
+++ b/src/detection/libc/libc_nosupport.c
@@ -0,0 +1,7 @@
+#include "libc.h"
+
+const char* ffDetectLibc(FFLibcResult* result) {
+ result->name = "Unknown";
+ result->version = NULL;
+ return NULL;
+}
diff --git a/src/detection/libc/libc_windows.cpp b/src/detection/libc/libc_windows.cpp
new file mode 100644
index 0000000..c94062a
--- /dev/null
+++ b/src/detection/libc/libc_windows.cpp
@@ -0,0 +1,68 @@
+extern "C" {
+#include "libc.h"
+}
+
+#ifdef __MINGW32__
+ #include <_mingw.h>
+#endif
+
+template <uint32_t Major, uint32_t Minor>
+class version_t {
+ constexpr static auto buflen() noexcept {
+ unsigned int len = 2; // "."
+ if (Major == 0) {
+ len++;
+ } else {
+ for (auto n = Major; n; len++, n /= 10);
+ }
+
+ if (Minor == 0) {
+ len++;
+ } else {
+ for (auto n = Minor; n; len++, n /= 10);
+ }
+ return len;
+ }
+
+ char buf[buflen()] = {};
+
+ public:
+ constexpr version_t() noexcept {
+ auto ptr = buf + buflen();
+ *--ptr = '\0';
+
+ if (Minor == 0) {
+ *--ptr = '0';
+ } else {
+ for (auto n = Minor; n; n /= 10) {
+ *--ptr = "0123456789"[n % 10];
+ }
+ }
+ *--ptr = '.';
+ if (Major == 0) {
+ *--ptr = '0';
+ } else {
+ for (auto n = Major; n; n /= 10) {
+ *--ptr = "0123456789"[n % 10];
+ }
+ }
+ }
+
+ constexpr operator const char*() const {
+ return buf;
+ }
+};
+
+template <uint32_t Major, uint32_t Minor>
+constexpr version_t<Major, Minor> version;
+
+extern "C" const char* ffDetectLibc(FFLibcResult* result) {
+#ifdef _UCRT
+ result->name = "ucrt";
+#else
+ result->name = "msvcrt";
+#endif
+
+ result->version = version<(__MSVCRT_VERSION__ >> 8), (__MSVCRT_VERSION__ & 8)>;
+ return NULL;
+}