mirror of
https://github.com/encounter/aurora.git
synced 2025-07-04 20:26:07 +00:00
Add winsupport from hecl
This commit is contained in:
parent
061753f92f
commit
c75c6c74c5
14
include/kabufuda/winsupport.hpp
Normal file
14
include/kabufuda/winsupport.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef _HECL_WINSUPPORT_H_
|
||||||
|
#define _HECL_WINSUPPORT_H_
|
||||||
|
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
|
#endif
|
||||||
|
#ifndef NOMINMAX
|
||||||
|
#define NOMINMAX 1
|
||||||
|
#endif
|
||||||
|
#include "windows.h"
|
||||||
|
|
||||||
|
void* memmem(const void *haystack, size_t hlen, const void *needle, size_t nlen);
|
||||||
|
|
||||||
|
#endif // _HECL_WINSUPPORT_H_
|
36
lib/kabufuda/winsupport.cpp
Normal file
36
lib/kabufuda/winsupport.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#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