diff options
author | Enyew Tan <enyew@tegile.com> | 2014-08-23 17:55:22 -0700 |
---|---|---|
committer | Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> | 2022-05-23 10:02:28 +0200 |
commit | 29219719c034367724cbf77434175b3c4e681e43 (patch) | |
tree | 76ce2e79fd09f06e3f590f9f7bff203894caa77a /usr/src/common | |
parent | 5b0d53307d70a828ad7aef4dc6d8a3ad7d5c231b (diff) | |
download | illumos-joyent-29219719c034367724cbf77434175b3c4e681e43.tar.gz |
14687 need in-kernel strtok_r()
Reviewed by: Robert Mustacchi <rm+illumos@fingolfin.org>
Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Yuri Pankov <ypankov@tintri.com>
Reviewed by: Andy Fiddaman <andy@omnios.org>
Approved by: Dan McDonald <danmcd@mnx.io>
Diffstat (limited to 'usr/src/common')
-rw-r--r-- | usr/src/common/util/string.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/usr/src/common/util/string.c b/usr/src/common/util/string.c index 8e1247f381..c44dc4b402 100644 --- a/usr/src/common/util/string.c +++ b/usr/src/common/util/string.c @@ -26,7 +26,7 @@ /* * Copyright (c) 2016 by Delphix. All rights reserved. - * Copyright 2018 Nexenta Systems, Inc. + * Copyright 2022 Tintri by DDN, Inc. All rights reserved. */ /* @@ -709,6 +709,40 @@ strsep(char **stringp, const char *delim) } /* + * strtok_r + * + * uses strpbrk and strspn to break string into tokens on + * sequentially subsequent calls. returns NULL when no + * non-separator characters remain. + * `subsequent' calls are calls with first argument NULL. + */ +char * +strtok_r(char *string, const char *sepset, char **lasts) +{ + char *q, *r; + + /* first or subsequent call */ + if (string == NULL) + string = *lasts; + + if (string == NULL) /* return if no tokens remaining */ + return (NULL); + + q = string + strspn(string, sepset); /* skip leading separators */ + + if (*q == '\0') /* return if no tokens remaining */ + return (NULL); + + if ((r = strpbrk(q, sepset)) == NULL) { /* move past token */ + *lasts = NULL; /* indicate this is last token */ + } else { + *r = '\0'; + *lasts = r + 1; + } + return (q); +} + +/* * Unless mentioned otherwise, all of the routines below should be added to * the Solaris DDI as necessary. For now, only provide them to standalone. */ |