Windows: make the CMake build work with MSYS2's native toolchain
This commit is contained in:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user