Skip to content

Commit

Permalink
Add memmem shim patch
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Oct 2, 2023
1 parent ec9d6fd commit 2ea1324
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/orig.c b/new.c
index 20c11bf..e355198 100644
--- a/src/base_bigstring_stubs.c
+++ b/src/base_bigstring_stubs.c
@@ -43,6 +43,26 @@ static inline uint16_t bswap_16 (uint16_t x)
#endif
#define bswap_32 __builtin_bswap32
#define bswap_64 __builtin_bswap64
+
+// https://stackoverflow.com/questions/52988769/writing-own-memmem-for-windows
+void *memmem(const void *haystack, size_t haystack_len,
+ const void * const needle, const size_t needle_len)
+{
+ if (haystack == NULL) return NULL;
+ if (haystack_len == 0) return NULL;
+ if (needle == NULL) return NULL;
+ if (needle_len == 0) return NULL;
+
+ for (const char *h = haystack;
+ haystack_len >= needle_len;
+ ++h, --haystack_len) {
+ if (!memcmp(h, needle, needle_len)) {
+ return h;
+ }
+ }
+ return NULL;
+}
+
#elif _MSC_VER
#define bswap_16 _byteswap_ushort
#define bswap_32 _byteswap_ulong
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ bug-reports: "https://github.com/janestreet/base_bigstring/issues"
dev-repo: "git+https://github.com/janestreet/base_bigstring.git"
doc: "https://ocaml.janestreet.com/ocaml-core/latest/doc/base_bigstring/index.html"
license: "MIT"
patches: [
"patches/memmem-shim.patch"
]
build: [
["dune" "build" "-p" "base_bigstring" "-j" jobs "-x" "windows"]
]
Expand Down

0 comments on commit 2ea1324

Please sign in to comment.