diff --git a/lib/Makefile.am b/lib/Makefile.am index 8cbb6dfd..4e7c0b16 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 00000000..d7813d1b --- /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 00000000..f084bc46 --- /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