Merge commit 'e7d49'

This commit is contained in:
Jack Andersen 2016-06-30 09:41:50 -10:00
commit 7ff0fae093
3 changed files with 57 additions and 1 deletions

View File

@ -10,6 +10,11 @@ endif()
include_directories(include)
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
include/kabufuda/Constants.hpp
include/kabufuda/BlockAllocationTable.hpp lib/kabufuda/BlockAllocationTable.cpp
@ -18,6 +23,7 @@ add_library(kabufuda STATIC
include/kabufuda/File.hpp lib/kabufuda/File.cpp
include/kabufuda/Util.hpp lib/kabufuda/Util.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})
add_subdirectory(test)

View 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_

View 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;
}