registrychunks: Use strnlen if available
authorEdward Hervey <edward@centricular.com>
Fri, 20 Mar 2020 08:11:02 +0000 (09:11 +0100)
committerSebastian Dröge <slomo@coaxion.net>
Sun, 22 Mar 2020 10:40:21 +0000 (10:40 +0000)
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
meson.build

index 6801a18..c5d4197 100644 (file)
 #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{ \
index c158206..0392655 100644 (file)
@@ -230,6 +230,7 @@ check_functions = [
   'pselect',
   'getpagesize',
   'clock_gettime',
+  'strnlen',
   # These are needed by libcheck
   'getline',
   'mkstemp',