diff options
Diffstat (limited to 'lib/string.c')
| -rw-r--r-- | lib/string.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/string.c b/lib/string.c index 0bdf942391c0..41a90d37e35a 100644 --- a/lib/string.c +++ b/lib/string.c @@ -326,21 +326,24 @@ char * strtok(char * s,const char * ct) * @ct: The characters to search for * * strsep() updates @s to point after the token, ready for the next call. + * + * It returns empty tokens, too, behaving exactly like the libc function + * of that name. In fact, it was stolen from glibc2 and de-fancy-fied. + * Same semantics, slimmer shape. ;) */ -char * strsep(char **s, const char * ct) +char * strsep(char **s, const char *ct) { - char *sbegin=*s; - if (!sbegin) - return NULL; - - sbegin += strspn(sbegin,ct); - if (*sbegin == '\0') + char *sbegin = *s, *end; + + if (sbegin == NULL) return NULL; - - *s = strpbrk( sbegin, ct); - if (*s && **s != '\0') - *(*s)++ = '\0'; - return (sbegin); + + end = strpbrk(sbegin, ct); + if (end) + *end++ = '\0'; + *s = end; + + return sbegin; } #endif |
