diff --git a/TitanEngine/Helper.cpp b/TitanEngine/Helper.cpp new file mode 100644 index 0000000..823349d --- /dev/null +++ b/TitanEngine/Helper.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" +#include "Helper.h" + + + +bool IsStrEqual( const char* const a, const char* const b, bool considercase/*=true*/ ) +{ + const int stringlen = std::strlen(a); + if(stringlen != std::strlen(b)) + return false; //cheap + + if(considercase) + { + //plain old strcmp + return std::strcmp(a, b)==0; + } + else + { + for(int i=0; i +#include + +/* +Compares two strings +a : string 1 +b : string 2 +considercase : casesensitivity +*/ +bool IsStrEqual(const char* const a, const char* const b, bool considercase=true); + +/* +A basic dynamic buffer, exception free. +*/ +class DynBuf +{ +public: + DynBuf(size_t sz=0) + { + Allocate(sz); + } + typedef std::vector DynBufVec; + + void* Allocate(size_t sz) + { + void* r=NULL; + try + { + if(Size() < sz) + mem.resize(sz); + if(Size()) + r = GetPtr(); + if(r && sz) + memset(r, 0, sz); + } + catch(...) + { + } + + return r; + } + void* GetPtr() + { + if(Size()) + return &mem.front(); //in c++11: .data() + return NULL; + } + void Free() + { + mem.clear(); + } + DynBufVec& GetVector() {return mem;} + const DynBufVec& GetVector() const {return mem;} + size_t Size() const {return mem.size();} + + +protected: + char& operator[](std::size_t idx) + { + return mem[idx]; + }; + const char& operator[](std::size_t idx) const + { + return mem[idx]; + }; + + DynBufVec mem; +}; + + +//Unused malloc/free wrappers + +/* +malloc wrapper +*/ +void* MemAlloc(size_t sz); + +/* +free wrapper +*/ +void MemFree(void* mem); + + + +#endif // Helper_h__ + diff --git a/TitanEngine/stdafx.h b/TitanEngine/stdafx.h index f3e4476..734fab9 100644 --- a/TitanEngine/stdafx.h +++ b/TitanEngine/stdafx.h @@ -17,6 +17,8 @@ #include "aplib.h" #include "LzmaDec.h" +#include "Helper.h" + #define STATUS_SUCCESS ((NTSTATUS)0x00000000L) // ntsubauth // Engine.Internal: