mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-31 18:13:38 +01:00
Version: print libc version used when compiling
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_libc_libc
|
||||
#define FF_INCLUDED_detection_libc_libc
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
typedef struct FFLibcResult
|
||||
{
|
||||
const char* name;
|
||||
const char* version;
|
||||
} FFLibcResult;
|
||||
|
||||
const char* ffDetectLibc(FFLibcResult* result);
|
||||
|
||||
#endif
|
||||
@@ -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)
|
||||
{
|
||||
#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
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#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 __GNU_LIBRARY__
|
||||
result->name = "glibc";
|
||||
result->version = FF_STR(__GLIBC__) "." FF_STR(__GLIBC_MINOR__);
|
||||
#else
|
||||
result->name = "musl";
|
||||
result->version = NULL;
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "libc.h"
|
||||
|
||||
#define FF_STR_INDIR(x) #x
|
||||
#define FF_STR(x) FF_STR_INDIR(x)
|
||||
|
||||
const char* ffDetectLibc(FF_MAYBE_UNUSED FFLibcResult* result)
|
||||
{
|
||||
return "Not supported on this platform";
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user