From dbbfda0e96037da4f208ff8f00d181a5294484ae Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sat, 22 Jun 2013 22:30:13 -0700 Subject: add new stuff stuff (with tests!), poison memcmp and strncpy --- src/common/utils.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/common/utils.hpp') 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 +const T& const_(T& t) +{ + return t; +} + #endif //UTILS_HPP -- cgit v1.2.3-70-g09d2