mirror of
https://github.com/encounter/aurora.git
synced 2025-07-07 13:46:08 +00:00
Windows build fixes
This commit is contained in:
parent
8017bdf6c8
commit
2a463de413
@ -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
|
||||
|
@ -1,34 +0,0 @@
|
||||
#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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user