From 8f1fdbc54a873abc7375c785b2b6ee5440910de2 Mon Sep 17 00:00:00 2001 From: Claes Nästén Date: Mon, 6 Dec 2021 07:49:15 +0100 Subject: fix: add STRNLEN compatability macro Older SunOS systems come without strnlen, add STRNLEN macro in line with the other str* compat macros. --- src/nvim/strings.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index c58e052ae9..27f93fe4ce 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -394,6 +394,18 @@ void del_trailing_spaces(char_u *ptr) } } +#if !defined(HAVE_STRNLEN) +size_t xstrnlen(const char *s, size_t n) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE +{ + const char *end = memchr(s, '\0', n); + if (end == NULL) { + return n; + } + return end - s; +} +#endif + #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) /* * Compare two strings, ignoring case, using current locale. -- cgit