Commit 8053d112 authored by Jack Andersen's avatar Jack Andersen

Windows build fixes

parent 51c7163c
......@@ -9,7 +9,7 @@ unset(KABUFUDA_INCLUDE_DIR CACHE)
unset(PLAT_SRCS)
if(WIN32)
list(APPEND PLAT_SRCS lib/kabufuda/winsupport.cpp include/kabufuda/winsupport.hpp lib/kabufuda/AsyncIOWin32.cpp)
list(APPEND PLAT_SRCS include/kabufuda/winsupport.hpp lib/kabufuda/AsyncIOWin32.cpp)
else()
list(APPEND PLAT_SRCS lib/kabufuda/AsyncIOPosix.cpp)
endif()
......
......@@ -7,5 +7,28 @@
#define NOMINMAX 1
#endif
#include "windows.h"
#include <cstdint>
void* memmem(const void* haystack, size_t hlen, const void* needle, size_t nlen);
#ifndef DEF_INLINE_MEMMEM
#define DEF_INLINE_MEMMEM
inline void* memmem(const void* haystack, size_t hlen, const void* needle, size_t nlen) {
int needle_first;
const uint8_t* p = static_cast<const uint8_t*>(haystack);
size_t plen = hlen;
if (!nlen)
return NULL;
needle_first = *(unsigned char*)needle;
while (plen >= nlen && (p = static_cast<const uint8_t*>(memchr(p, needle_first, plen - nlen + 1)))) {
if (!memcmp(p, needle, nlen))
return (void*)p;
p++;
plen = hlen - (p - static_cast<const uint8_t*>(haystack));
}
return NULL;
}
#endif
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <string>
#include "hecl/winsupport.hpp"
/*
* The memmem() function finds the start of the first occurrence of the
* substring 'needle' of length 'nlen' in the memory area 'haystack' of
* length 'hlen'.
*
* The return value is a pointer to the beginning of the sub-string, or
* NULL if the substring is not found.
*/
void* memmem(const void* haystack, size_t hlen, const void* needle, size_t nlen) {
int needle_first;
const uint8_t* p = static_cast<const uint8_t*>(haystack);
size_t plen = hlen;
if (!nlen)
return NULL;
needle_first = *(unsigned char*)needle;
while (plen >= nlen && (p = static_cast<const uint8_t*>(memchr(p, needle_first, plen - nlen + 1)))) {
if (!memcmp(p, needle, nlen))
return (void*)p;
p++;
plen = hlen - (p - static_cast<const uint8_t*>(haystack));
}
return NULL;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment