From: Timo Sirainen Date: Fri, 10 Apr 2020 16:50:54 +0000 (+0300) Subject: lib: Rename str_begins() to str_begins_with() and add compatibility macro X-Git-Tag: 2.4.0~4240 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f6f8a783e682adca3cd48ab4ce879dccde061ee;p=thirdparty%2Fdovecot%2Fcore.git lib: Rename str_begins() to str_begins_with() and add compatibility macro --- diff --git a/src/lib/strfuncs.h b/src/lib/strfuncs.h index 1ddb82f8b5..c338bf8798 100644 --- a/src/lib/strfuncs.h +++ b/src/lib/strfuncs.h @@ -87,15 +87,19 @@ bool mem_equals_timing_safe(const void *p1, const void *p2, size_t size); bool str_equals_timing_almost_safe(const char *s1, const char *s2); size_t str_match(const char *p1, const char *p2) ATTR_PURE; -static inline ATTR_PURE bool str_begins(const char *haystack, const char *needle) +static inline ATTR_PURE bool +str_begins_with(const char *haystack, const char *needle) { return needle[str_match(haystack, needle)] == '\0'; } #if defined(__GNUC__) && (__GNUC__ >= 2) /* GCC (and Clang) are known to have a compile-time strlen("literal") shortcut, and an optimised strncmp(), so use that by default. Macro is multi-evaluation safe. */ -# define str_begins(h, n) (__builtin_constant_p(n) ? strncmp((h), (n), strlen(n))==0 : (str_begins)((h), (n))) +# define str_begins_with(h, n) \ + (__builtin_constant_p(n) ? strncmp((h), (n), strlen(n))==0 : \ + (str_begins_with)((h), (n))) #endif +#define str_begins(h, n) str_begins_with(h, n) /* Get length of a prefix segment.