summaryrefslogtreecommitdiff
path: root/lib/strsep.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2007-02-06 13:11:23 +0000
committerBruno Haible <bruno@clisp.org>2007-02-06 13:11:23 +0000
commitfdbaafb43b00f78c1fa350b8808a390918248cd1 (patch)
treed8f048db5c418f64a7f91d52c9d5f68e579244c0 /lib/strsep.c
parent237d6da6ea912f61169d7587f968284bf6074ec7 (diff)
downloadgnulib-fdbaafb43b00f78c1fa350b8808a390918248cd1.tar.gz
Fix bug with strsep(&string, ""). Optimize case of 1 delimiter.
Diffstat (limited to 'lib/strsep.c')
-rw-r--r--lib/strsep.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/strsep.c b/lib/strsep.c
index 1a86852b8d..9f2fdd2b57 100644
--- a/lib/strsep.c
+++ b/lib/strsep.c
@@ -29,19 +29,26 @@ strsep (char **stringp, const char *delim)
char *start = *stringp;
char *ptr;
- if (!start)
+ if (start == NULL)
return NULL;
- if (!*delim)
- ptr = start + strlen (start);
+ /* Optimize the case of no delimiters. */
+ if (delim[0] == '\0')
+ {
+ *stringp = NULL;
+ return start;
+ }
+
+ /* Optimize the case of one delimiter. */
+ if (delim[1] == '\0')
+ ptr = strchr (start, delim[0]);
else
+ /* The general case. */
+ ptr = strpbrk (start, delim);
+ if (ptr == NULL)
{
- ptr = strpbrk (start, delim);
- if (!ptr)
- {
- *stringp = NULL;
- return start;
- }
+ *stringp = NULL;
+ return start;
}
*ptr = '\0';