mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-16 10:17:02 +00:00
MSVC build fixes
This commit is contained in:
34
hecl/lib/winsupport.c
Normal file
34
hecl/lib/winsupport.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* 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 uint8_t *haystack, size_t hlen, const void *needle, size_t nlen)
|
||||
{
|
||||
int needle_first;
|
||||
const uint8_t *p = haystack;
|
||||
size_t plen = hlen;
|
||||
|
||||
if (!nlen)
|
||||
return NULL;
|
||||
|
||||
needle_first = *(unsigned char *)needle;
|
||||
|
||||
while (plen >= nlen && (p = memchr(p, needle_first, plen - nlen + 1)))
|
||||
{
|
||||
if (!memcmp(p, needle, nlen))
|
||||
return (void *)p;
|
||||
|
||||
p++;
|
||||
plen = hlen - (p - haystack);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user