X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstrsep.c;h=6037f4dddd4a74a68b709488da47c2cccdec7465;hb=3458f09caac5234831a315d073344fc898dde077;hp=1a86852b8d907341ce8c246db850d8887c8cf7b9;hpb=1e4ece4ab9850fbfa88c9ec43ea518c7bc266792;p=gnulib.git diff --git a/lib/strsep.c b/lib/strsep.c index 1a86852b8..6037f4ddd 100644 --- a/lib/strsep.c +++ b/lib/strsep.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2007, 2009, 2010 Free Software Foundation, Inc. Written by Yoann Vandoorselaere . @@ -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';