diff options
author | Pedro J. Ruiz Lopez <holzplatten@es.gnu.org> | 2007-02-12 23:24:21 +0000 |
---|---|---|
committer | Pedro J. Ruiz Lopez <holzplatten@es.gnu.org> | 2007-02-12 23:24:21 +0000 |
commit | 80f3bd30c7521091c1dea118603b20a76c2a180c (patch) | |
tree | 359d11fb051a720d6958341ab5ac1fbff2fe5fd2 /lib/strsep.c | |
parent | 56a64cd30f232800884506d88acd780c431be1a5 (diff) | |
download | idutils-80f3bd30c7521091c1dea118603b20a76c2a180c.tar.gz idutils-80f3bd30c7521091c1dea118603b20a76c2a180c.tar.bz2 idutils-80f3bd30c7521091c1dea118603b20a76c2a180c.zip |
* upgraded gnulib
Diffstat (limited to 'lib/strsep.c')
-rw-r--r-- | lib/strsep.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/lib/strsep.c b/lib/strsep.c index db2b074..9f2fdd2 100644 --- a/lib/strsep.c +++ b/lib/strsep.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2007 Free Software Foundation, Inc. Written by Yoann Vandoorselaere <yoann@prelude-ids.org>. @@ -21,31 +21,34 @@ #endif /* Specification. */ -#include "strsep.h" - #include <string.h> -#include "strpbrk.h" - char * 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'; |