about summary refs log tree commit diff
path: root/sysdeps/generic
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1996-01-04 00:06:01 +0000
committerRoland McGrath <roland@gnu.org>1996-01-04 00:06:01 +0000
commit6df1b2474adfc23c9cfff5a4496108bea0c37511 (patch)
tree48bd35ba5b0d766560edde694efec2b791ada613 /sysdeps/generic
parent71733723fb421bd54467d1a27096463ed1dcc2ed (diff)
downloadglibc-6df1b2474adfc23c9cfff5a4496108bea0c37511.tar.gz
glibc-6df1b2474adfc23c9cfff5a4496108bea0c37511.tar.xz
glibc-6df1b2474adfc23c9cfff5a4496108bea0c37511.zip
Rewritten. cvs/libc-960103
Diffstat (limited to 'sysdeps/generic')
-rw-r--r--sysdeps/generic/strsep.c26
1 files changed, 15 insertions, 11 deletions
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 <ansidecl.h>
 #include <string.h>
 
 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;
 }