From: Alejandro Colomar Date: Tue, 2 Jul 2024 17:31:38 +0000 (+0200) Subject: lib/string/strtok/stpsep.[ch]: stpsep(): Add function X-Git-Tag: 4.17.0-rc1~131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39da15614e5064bfb67345bf3dd9d854b230e071;p=thirdparty%2Fshadow.git lib/string/strtok/stpsep.[ch]: stpsep(): Add function This function is somewhat simpler to use than strsep(3) in some cases. Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index 8cbb6dfdb..4e7c0b169 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -186,6 +186,8 @@ libshadow_la_SOURCES = \ string/strdup/xstrndup.h \ string/strftime.c \ string/strftime.h \ + string/strtok/stpsep.c \ + string/strtok/stpsep.h \ strtoday.c \ sub.c \ subordinateio.h \ diff --git a/lib/string/strtok/stpsep.c b/lib/string/strtok/stpsep.c new file mode 100644 index 000000000..d7813d1bc --- /dev/null +++ b/lib/string/strtok/stpsep.c @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "string/strtok/stpsep.h" + + +extern inline char *stpsep(char *s, const char *delim); diff --git a/lib/string/strtok/stpsep.h b/lib/string/strtok/stpsep.h new file mode 100644 index 000000000..f084bc461 --- /dev/null +++ b/lib/string/strtok/stpsep.h @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_STRING_STRTOK_STPSEP_H_ +#define SHADOW_INCLUDE_LIB_STRING_STRTOK_STPSEP_H_ + + +#include + +#include + +#include "attr.h" + + +ATTR_STRING(1) ATTR_STRING(2) +inline char *stpsep(char *s, const char *delim); + + +// Similar to strsep(3), +// but return the next token, and don't update the input pointer. +// Similar to strtok(3), +// but don't store a state, and don't skip empty fields. +inline char * +stpsep(char *s, const char *delim) +{ + strsep(&s, delim); + + return s; +} + + +#endif // include guard