libc/string: Simplify strpbrk() - scc - simple c99 compiler
(HTM) git clone git://git.simple-cc.org/scc
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
(DIR) commit 281fd80448d875367f4be096a00ebbc847a06c1b
(DIR) parent 5a4639f2e13052cfd4ff099cf1fcee020af58a55
(HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Wed, 26 Mar 2025 14:41:30 +0100
libc/string: Simplify strpbrk()
Strpbrk() is trivial if strcspn() is used.
Diffstat:
M src/libc/string/strpbrk.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
---
(DIR) diff --git a/src/libc/string/strpbrk.c b/src/libc/string/strpbrk.c
@@ -5,16 +5,6 @@
char *
strpbrk(const char *s1, const char *s2)
{
- const unsigned char *s = (const unsigned char *) s1;
- const unsigned char *accept = (const unsigned char *) s2;
- unsigned ch;
- char map[__NUMCHARS] = {0};
-
- while ((ch = *accept++) != 0)
- map[ch] = 1;
-
- while ((ch = *s) != 0 && !map[ch])
- s++;
-
- return (ch == '\0') ? NULL : (char *) s;
+ s1 += strcspn(s1, s2);
+ return (*s1 != '\0') ? (char *) s1 : NULL;
}