mirror of https://github.com/AxioDL/kabufuda.git
Add winsupport from hecl
This commit is contained in:
parent
2a9c18534a
commit
e7d49f7f3b
|
@ -10,6 +10,11 @@ endif()
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
set(KABUFUDA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE PATH "kabufuda include path" FORCE)
|
set(KABUFUDA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE PATH "kabufuda include path" FORCE)
|
||||||
|
|
||||||
|
unset(PLAT_SRCS)
|
||||||
|
if(WIN32)
|
||||||
|
list(APPEND PLAT_SRCS lib/kabufuda/winsupport.cpp include/kabufuda/winsupport.hpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(kabufuda STATIC
|
add_library(kabufuda STATIC
|
||||||
include/kabufuda/Constants.hpp
|
include/kabufuda/Constants.hpp
|
||||||
include/kabufuda/BlockAllocationTable.hpp lib/kabufuda/BlockAllocationTable.cpp
|
include/kabufuda/BlockAllocationTable.hpp lib/kabufuda/BlockAllocationTable.cpp
|
||||||
|
@ -18,7 +23,8 @@ add_library(kabufuda STATIC
|
||||||
include/kabufuda/File.hpp lib/kabufuda/File.cpp
|
include/kabufuda/File.hpp lib/kabufuda/File.cpp
|
||||||
include/kabufuda/Util.hpp lib/kabufuda/Util.cpp
|
include/kabufuda/Util.hpp lib/kabufuda/Util.cpp
|
||||||
include/kabufuda/SRAM.hpp lib/kabufuda/SRAM.cpp
|
include/kabufuda/SRAM.hpp lib/kabufuda/SRAM.cpp
|
||||||
include/kabufuda/WideStringConvert.hpp lib/kabufuda/WideStringConvert.cpp)
|
include/kabufuda/WideStringConvert.hpp lib/kabufuda/WideStringConvert.cpp
|
||||||
|
${PLAT_SRCS})
|
||||||
|
|
||||||
if (NOT TARGET hecl)
|
if (NOT TARGET hecl)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
|
|
@ -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_
|
|
@ -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…
Reference in New Issue