diff options
| author | Linus Torvalds <torvalds@athlon.transmeta.com> | 2002-02-04 18:13:58 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@athlon.transmeta.com> | 2002-02-04 18:13:58 -0800 |
| commit | 7216d3e927c3b6c5d28e5ffaa54afbb34649debb (patch) | |
| tree | 2b81b74fda9084131cd90731b0ec9e93e8edb853 /lib/string.c | |
| parent | 4095b99c09e3db837b17f031da096a0213cdd527 (diff) | |
v2.4.3.8 -> v2.4.4
- Andrea Arkangeli: raw-io fixes
- Johannes Erdfelt: USB updates
- reiserfs update
- Al Viro: fsync/umount race fix
- Rusty Russell: netfilter sync
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 |
