Skip to content

Commit 9d775a6

Browse files
committed
Implement strcasestr function for Windows compatibility
1 parent 7f00b53 commit 9d775a6

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/sqlite-vector.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
#include "sqlite-vector.h"
1010
#include "distance-cpu.h"
1111

12-
#ifdef _WIN32
13-
#define _GNU_SOURCE
14-
#endif
15-
1612
#include <math.h>
1713
#include <stdio.h>
1814
#include <ctype.h>
@@ -24,6 +20,33 @@
2420
#include <stdbool.h>
2521
#include <stddef.h>
2622

23+
#ifdef _WIN32
24+
char* strcasestr(const char* haystack, const char* needle) {
25+
if (!haystack || !needle) {
26+
return NULL;
27+
}
28+
29+
if (*needle == '\0') {
30+
return (char*)haystack;
31+
}
32+
33+
size_t needle_len = strlen(needle);
34+
size_t haystack_len = strlen(haystack);
35+
36+
if (needle_len > haystack_len) {
37+
return NULL;
38+
}
39+
40+
for (size_t i = 0; i <= haystack_len - needle_len; i++) {
41+
if (strnicmp(haystack + i, needle, needle_len) == 0) {
42+
return (char*)(haystack + i);
43+
}
44+
}
45+
46+
return NULL;
47+
}
48+
#endif
49+
2750
#if defined(_WIN32) || defined(__linux__)
2851
#include <float.h>
2952
#endif

0 commit comments

Comments
 (0)