diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2022-08-03 22:33:35 -0400 |
---|---|---|
committer | Suren Baghdasaryan <surenb@google.com> | 2023-03-13 15:11:32 +0000 |
commit | e739cc6a9f7259c91a0ef2e04687dc52bcb31807 (patch) | |
tree | 5beac6c82fba8dc08851965153d009c4dc7c73de /lib/string.c | |
parent | 6b25748c5e92d4459c73913c9fef48cfdf7f55d2 (diff) |
lib/string.c: strsep_no_empty()
This adds a new helper which is like strsep, except that it skips empty
tokens.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Diffstat (limited to 'lib/string.c')
-rw-r--r-- | lib/string.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c index 4fb566ea610f..462247073b5e 100644 --- a/lib/string.c +++ b/lib/string.c @@ -522,6 +522,25 @@ char *strsep(char **s, const char *ct) EXPORT_SYMBOL(strsep); #endif +/** + * strsep_no_empt - Split a string into tokens, but don't return empty tokens + * @s: The string to be searched + * @ct: The characters to search for + * + * strsep() updates @s to point after the token, ready for the next call. + */ +char *strsep_no_empty(char **s, const char *ct) +{ + char *ret; + + do { + ret = strsep(s, ct); + } while (ret && !*ret); + + return ret; +} +EXPORT_SYMBOL_GPL(strsep_no_empty); + #ifndef __HAVE_ARCH_MEMSET /** * memset - Fill a region of memory with the given value |