diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2013-06-22 22:30:13 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2013-06-23 22:07:50 -0700 |
commit | dbbfda0e96037da4f208ff8f00d181a5294484ae (patch) | |
tree | 7a7b9982c6d98ddc2271aade72040ea9233a4a11 /src/common/utils.hpp | |
parent | 83db3bbee4e19e7426a32ee89ad6c2d8e48260f2 (diff) | |
download | tmwa-dbbfda0e96037da4f208ff8f00d181a5294484ae.tar.gz tmwa-dbbfda0e96037da4f208ff8f00d181a5294484ae.tar.bz2 tmwa-dbbfda0e96037da4f208ff8f00d181a5294484ae.tar.xz tmwa-dbbfda0e96037da4f208ff8f00d181a5294484ae.zip |
add new stuff stuff (with tests!), poison memcmp and strncpy
Diffstat (limited to 'src/common/utils.hpp')
-rw-r--r-- | src/common/utils.hpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/common/utils.hpp b/src/common/utils.hpp index cd45aa1..ab32948 100644 --- a/src/common/utils.hpp +++ b/src/common/utils.hpp @@ -34,7 +34,8 @@ void strzcpy(char *dest, const char *src, size_t n) { if (n) { - strncpy(dest, src, n); + // hmph + strncpy(dest, src, n - 1); dest[n - 1] = '\0'; } } @@ -50,6 +51,11 @@ void really_memmove(uint8_t *dest, const uint8_t *src, size_t n) { memmove(dest, src, n); } +inline +bool really_memequal(const uint8_t *a, const uint8_t *b, size_t n) +{ + return memcmp(a, b, n) == 0; +} inline void really_memset0(uint8_t *dest, size_t n) @@ -140,4 +146,10 @@ static_assert(sizeof(TIMESTAMP_DUMMY) == sizeof(timestamp_seconds_buffer), &t \ ) +template<class T> +const T& const_(T& t) +{ + return t; +} + #endif //UTILS_HPP |