From 04a4125f66ad9b6702f40e5a6503e726cf808596 Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Sun, 8 Nov 2020 18:02:27 +0100 Subject: [PATCH] strnstr on win32 --- src/eez/util.cpp | 24 ++++++++++++++++++++++++ src/eez/util.h | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/src/eez/util.cpp b/src/eez/util.cpp index 9f5f5371a..6f52f3c92 100644 --- a/src/eez/util.cpp +++ b/src/eez/util.cpp @@ -615,3 +615,27 @@ void getBaseFileName(const char *path, char *baseName, unsigned basenameSize) { } } // namespace eez + +#ifdef EEZ_PLATFORM_SIMULATOR_WIN32 +char *strnstr(const char *s1, const char *s2, size_t n) { + char c = *s2; + + if (c == '\0') + return (char *)s1; + + for (size_t len = strlen(s2); len <= n; n--, s1++) { + if (*s1 == c) { + for (size_t i = 1;; i++) { + if (i == len) { + return (char *)s1; + } + if (s1[i] != s2[i]) { + break; + } + } + } + } + + return NULL; +} +#endif diff --git a/src/eez/util.h b/src/eez/util.h index 8f81b27b5..b027e66eb 100644 --- a/src/eez/util.h +++ b/src/eez/util.h @@ -129,3 +129,7 @@ void formatBytes(uint64_t bytes, char *text, int count); void getBaseFileName(const char *path, char *baseName, unsigned basenameSize); } // namespace eez + +#ifdef EEZ_PLATFORM_SIMULATOR_WIN32 +char *strnstr(const char *s1, const char *s2, size_t n); +#endif \ No newline at end of file