From 7617fd80db4871a1ccfaff243ba5bf7b48f7b379 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 22 Apr 2014 11:29:24 +0200 Subject: m + add string comparator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsserver/hash-help.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/libmdsserver') diff --git a/src/libmdsserver/hash-help.h b/src/libmdsserver/hash-help.h index 7fe87ad..ea8d371 100644 --- a/src/libmdsserver/hash-help.h +++ b/src/libmdsserver/hash-help.h @@ -28,7 +28,7 @@ * @param str The string * @return The hash of the string */ -static inline size_t __attribute__((const)) string_hash(const char* str) +static inline size_t __attribute__((pure)) string_hash(const char* str) { size_t hash = 0; @@ -40,5 +40,21 @@ static inline size_t __attribute__((const)) string_hash(const char* str) } +/** + * Check whether two char* are of equal value + * + * @param str_a The first string + * @param str_b The second string + * @return Whether the strings are equals + */ +static inline int __attribute__((pure)) string_comparator(char* str_a, char* str_b) +{ + if ((str_a != NULL) && (str_b != NULL) && (str_a != str_b)) + return !strcmp((char*)str_a, (char*)str_b); + else + return str_a == str_b; +} + + #endif -- cgit v1.2.3-70-g09d2