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
This commit is contained in:
Edward Hervey 2020-03-20 09:11:02 +01:00 committed by Sebastian Dröge
parent 6907abdca8
commit 99901ffab4
2 changed files with 14 additions and 1 deletions

View file

@ -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{ \

View file

@ -230,6 +230,7 @@ check_functions = [
'pselect',
'getpagesize',
'clock_gettime',
'strnlen',
# These are needed by libcheck
'getline',
'mkstemp',