From: Alejandro Colomar Date: Thu, 14 Nov 2024 18:54:33 +0000 (+0100) Subject: lib/string/strchr/: strchrscnt(): Add function X-Git-Tag: 4.17.3~38 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=8d42b04c806bca1d997e8fd11c6dae5a067f7361;p=thirdparty%2Fshadow.git lib/string/strchr/: strchrscnt(): Add function Reviewed-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index 6ae24fb95..3d3a96ae7 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -192,6 +192,8 @@ libshadow_la_SOURCES = \ string/sprintf/xasprintf.h \ string/strchr/strchrcnt.c \ string/strchr/strchrcnt.h \ + string/strchr/strchrscnt.c \ + string/strchr/strchrscnt.h \ string/strchr/stpspn.c \ string/strchr/stpspn.h \ string/strchr/strnul.c \ diff --git a/lib/string/strchr/strchrscnt.c b/lib/string/strchr/strchrscnt.c new file mode 100644 index 000000000..8b1a5eca3 --- /dev/null +++ b/lib/string/strchr/strchrscnt.c @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "string/strchr/strchrscnt.h" + +#include + + +extern inline size_t strchrscnt(const char *s, const char *c); diff --git a/lib/string/strchr/strchrscnt.h b/lib/string/strchr/strchrscnt.h new file mode 100644 index 000000000..3d423bd29 --- /dev/null +++ b/lib/string/strchr/strchrscnt.h @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_STRING_STRCHR_STRCHRSCNT_H_ +#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STRCHRSCNT_H_ + + +#include + +#include + +#include "attr.h" +#include "string/strchr/strchrcnt.h" +#include "string/strcmp/streq.h" + + +ATTR_STRING(1) +ATTR_STRING(2) +inline size_t strchrscnt(const char *s, const char *c); + + +// Similar to strchrcnt(), but search for multiple characters. +inline size_t +strchrscnt(const char *s, const char *c) +{ + size_t n = 0; + + for (; !streq(c, ""); c++) + n += strchrcnt(s, *c); + + return n; +} + + +#endif // include guard