Windows: make the CMake build work with MSYS2's native toolchain
ci / linux (clang) (pull_request) Canceled after 0s
ci / linux (gcc) (pull_request) Canceled after 0s
ci / sanitizers (pull_request) Canceled after 0s
ci / musl (pull_request) Canceled after 0s
ci / macos (pull_request) Canceled after 0s

This commit is contained in:
XYZ
2026-10-06 16:13:45 +08:00
parent 1c26cc6e30
commit 3db33eddac
4 changed files with 106 additions and 6 deletions
+49
View File
@@ -1168,3 +1168,52 @@ void os_proc_kill(os_proc_t *p) {
}
}
#endif
/* --- libc gaps on Windows -----------------------------------------------
* strcasestr() is a GNU extension and setenv()/unsetenv() are POSIX; glibc
* has all three, MinGW-w64 has none of them. src/tui.c needs them (command
* filtering and ESCDELAY), so the Windows build supplies its own.
*
* The case folding here is ASCII-only, unlike glibc's locale-aware version.
* That is deliberate: these are used to match command and setting names,
* which are ASCII.
*/
#if defined(_WIN32)
static int ascii_lower(int c) {
return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c;
}
char *strcasestr(const char *haystack, const char *needle) {
if (!haystack || !needle)
return NULL;
if (!*needle)
return (char *)haystack;
for (; *haystack; haystack++) {
const char *h = haystack;
const char *n = needle;
while (*h && *n && ascii_lower((unsigned char)*h) == ascii_lower((unsigned char)*n)) {
h++;
n++;
}
if (!*n)
return (char *)haystack;
}
return NULL;
}
int setenv(const char *name, const char *value, int overwrite) {
if (!name || !*name || strchr(name, '='))
return -1;
if (!overwrite && getenv(name))
return 0;
return _putenv_s(name, value ? value : "");
}
int unsetenv(const char *name) {
if (!name || !*name || strchr(name, '='))
return -1;
return _putenv_s(name, "");
}
#endif /* _WIN32 */