From 6df1b2474adfc23c9cfff5a4496108bea0c37511 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 4 Jan 1996 00:06:01 +0000 Subject: Rewritten. --- sysdeps/generic/strsep.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'sysdeps/generic/strsep.c') diff --git a/sysdeps/generic/strsep.c b/sysdeps/generic/strsep.c index bb4d68bd6e..b57a22f649 100644 --- a/sysdeps/generic/strsep.c +++ b/sysdeps/generic/strsep.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992, 1993 Free Software Foundation, Inc. +/* Copyright (C) 1992, 1993, 1996 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,24 +16,28 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include #include char * -DEFUN(strsep, (stringp, delim), - char **stringp AND CONST char *delim) +strsep (char **stringp, const char *delim) { char *begin, *end; - begin = *stringp + strspn (*stringp, delim); - end = *stringp + strcspn (*stringp, delim); - - if (end == *stringp) + begin = *stringp; + if (! begin || *begin == '\0') return NULL; - if (*end != '\0') - *end++ = '\0'; - *stringp = end; + /* Find the end of the token. */ + end = strpbrk (begin, delim); + if (end) + { + /* Terminate the token and advance *STRINGP past the delimiters. */ + *end++ = '\0'; + *stringp = end + strspn (end, delim); + } + else + /* No more delimiters; this is the last token. */ + *stringp = NULL; return begin; } -- cgit v1.2.3