diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/libc/libc_windows.cpp | |
Add the files
Diffstat (limited to 'src/detection/libc/libc_windows.cpp')
| -rw-r--r-- | src/detection/libc/libc_windows.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
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; +} |