From 4bc558a9984de8e9285e9bac83884a1b2ead800b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 8 Feb 2017 21:51:02 -0800 Subject: [PATCH] Added memCmp. --- include/bx/bx.h | 3 +++ src/crt.cpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/bx/bx.h b/include/bx/bx.h index ea97d0d..f623b58 100644 --- a/include/bx/bx.h +++ b/include/bx/bx.h @@ -62,6 +62,9 @@ namespace bx /// void memSet(void* _dst, uint8_t _ch, size_t _numBytes); + /// + int32_t memCmp(const char* _lhs, const char* _rhs, size_t _numBytes); + } // namespace bx #include "bx.inl" diff --git a/src/crt.cpp b/src/crt.cpp index 66c09bb..ab6af2b 100644 --- a/src/crt.cpp +++ b/src/crt.cpp @@ -121,6 +121,18 @@ namespace bx #endif // BX_CRT_NONE } + int32_t memCmp(const char* _lhs, const char* _rhs, size_t _numBytes) + { + for ( + ; 0 < _numBytes && *_lhs == *_rhs + ; ++_lhs, ++_rhs, --_numBytes + ) + { + } + + return 0 == _numBytes ? 0 : *_lhs - *_rhs; + } + namespace { struct Param @@ -417,4 +429,9 @@ extern "C" void* memset(void* _dst, int _ch, size_t _numBytes) bx::memSet(_dst, uint8_t(_ch), _numBytes); return _dst; } + +extern "C" int32_t memcmp(const char* _lhs, const char* _rhs, size_t _numBytes) +{ + return bx::memCmp(_lhs, _rhs, _numBytes); +} #endif // BX_CRT_NONE