Skip to content

Commit

Permalink
strnstr on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 8, 2020
1 parent 42f8470 commit 04a4125
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/eez/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/eez/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 04a4125

Please sign in to comment.