From a2a9973f5f29288bf167ec15e8f4a4c32bb2cbf7 Mon Sep 17 00:00:00 2001 From: angt Date: Tue, 20 Oct 2015 23:49:00 +0200 Subject: [PATCH] Add str_cmp() and use restrict --- common.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/common.h b/common.h index fcb4507..0afb7e0 100644 --- a/common.h +++ b/common.h @@ -43,7 +43,7 @@ static inline void byte_copy (void *dst, const void *src, size_t size) *d++ = *s++; } -static inline size_t str_cpy (char *dst, const char *src, size_t len) +static inline size_t str_cpy (char *restrict dst, const char *restrict src, size_t len) { if (!dst || !src) return 0; @@ -58,6 +58,18 @@ static inline size_t str_cpy (char *dst, const char *src, size_t len) return i; } +static inline int str_cmp (const char *restrict sa, const char *restrict sb) +{ + if (!sa || !sb) + return 1; + + while (*sa==*sb++) + if (!*sa++) + return 0; + + return 1; +} + typedef struct buffer buffer_t; struct buffer {