From 99901ffab4dbb96f6994c9927b6c0f63df373812 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Fri, 20 Mar 2020 09:11:02 +0100 Subject: [PATCH] registrychunks: Use strnlen if available When this `_strnlen` internal method was added, strnlen (in glibc) was not available yet (appeared in 2.10 it was released that same year). If available, use the much more optimized strnlen --- gst/gstregistrychunks.c | 14 +++++++++++++- meson.build | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gst/gstregistrychunks.c b/gst/gstregistrychunks.c index 6801a18..c5d4197 100644 --- a/gst/gstregistrychunks.c +++ b/gst/gstregistrychunks.c @@ -46,7 +46,18 @@ #define GST_CAT_DEFAULT GST_CAT_REGISTRY /* count string length, but return -1 if we hit the eof */ -static gint +#ifdef HAVE_STRNLEN +static inline gint +_strnlen (const gchar * str, gint maxlen) +{ + gint len = strnlen (str, maxlen); + + if (G_UNLIKELY (len == maxlen)) + return -1; + return len; +} +#else +static inline gint _strnlen (const gchar * str, gint maxlen) { gint len = 0; @@ -58,6 +69,7 @@ _strnlen (const gchar * str, gint maxlen) } return -1; } +#endif /* Macros */ #define unpack_element(inptr, outptr, element, endptr, error_label) G_STMT_START{ \ diff --git a/meson.build b/meson.build index c158206..0392655 100644 --- a/meson.build +++ b/meson.build @@ -230,6 +230,7 @@ check_functions = [ 'pselect', 'getpagesize', 'clock_gettime', + 'strnlen', # These are needed by libcheck 'getline', 'mkstemp', -- 2.7.4