From 36bba1238a398fb7f84a6c432e099db91d54c657 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Thu, 22 Apr 2021 14:48:14 +0200 Subject: [PATCH] lib: move strnlen() Allow the function to be individually linkable, discardable, and overridable. Signed-off-by: Jan Beulich Acked-by: Julien Grall --- xen/common/string.c | 16 ---------------- xen/lib/Makefile | 1 + xen/lib/strnlen.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 xen/lib/strnlen.c diff --git a/xen/common/string.c b/xen/common/string.c index 752f65954c..6be445e26e 100644 --- a/xen/common/string.c +++ b/xen/common/string.c @@ -184,22 +184,6 @@ char *(strrchr)(const char *s, int c) } #endif -#ifndef __HAVE_ARCH_STRNLEN -/** - * strnlen - Find the length of a length-limited string - * @s: The string to be sized - * @count: The maximum number of bytes to search - */ -size_t strnlen(const char * s, size_t count) -{ - const char *sc; - - for (sc = s; count-- && *sc != '\0'; ++sc) - /* nothing */; - return sc - s; -} -#endif - #ifndef __HAVE_ARCH_STRSPN /** * strspn - Calculate the length of the initial substring of @s which only diff --git a/xen/lib/Makefile b/xen/lib/Makefile index 25c6ec62b1..1a642c929f 100644 --- a/xen/lib/Makefile +++ b/xen/lib/Makefile @@ -15,6 +15,7 @@ lib-y += parse-size.o lib-y += rbtree.o lib-y += sort.o lib-y += strlen.o +lib-y += strnlen.o lib-$(CONFIG_X86) += xxhash32.o lib-$(CONFIG_X86) += xxhash64.o diff --git a/xen/lib/strnlen.c b/xen/lib/strnlen.c new file mode 100644 index 0000000000..4433f6ee87 --- /dev/null +++ b/xen/lib/strnlen.c @@ -0,0 +1,29 @@ +/* + * Copyright (C) 1991, 1992 Linus Torvalds + */ + +#include + +/** + * strnlen - Find the length of a length-limited string + * @s: The string to be sized + * @count: The maximum number of bytes to search + */ +size_t strnlen(const char * s, size_t count) +{ + const char *sc; + + for (sc = s; count-- && *sc != '\0'; ++sc) + /* nothing */; + return sc - s; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 8 + * tab-width: 8 + * indent-tabs-mode: t + * End: + */ -- 2.30.2