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