Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2002-05-24 04:13:57 +0400
committerJeff Johnston <jjohnstn@redhat.com>2002-05-24 04:13:57 +0400
commit7a364eb36494dcac90196db3d93d15086d6c1bc1 (patch)
tree9df83ec6d394ab772dbcb50a69b427fe111cc697 /newlib/libc/string
parentbb2b4dedc6b053ee59d03cb436e937ecb9fd6571 (diff)
2002-05-23 Jeff Johnston <jjohnstn@redhat.com>
* libc/string/Makefile.am: Add support for strsep.c. * libc/string/Makefile.in: Regenerated. * libc/string/strsep.c: New file. * libc/string/strtok.c: Change to call __strtok_r service routine. * libc/string/strtok_r.c: Add __strtok_r routine which takes additional flag parameter regarding whether to skip leading delimeters. Change strtok_r to call __strtok_r.
Diffstat (limited to 'newlib/libc/string')
-rw-r--r--newlib/libc/string/Makefile.am1
-rw-r--r--newlib/libc/string/Makefile.in12
-rw-r--r--newlib/libc/string/strsep.c19
-rw-r--r--newlib/libc/string/strtok.c34
-rw-r--r--newlib/libc/string/strtok_r.c26
5 files changed, 77 insertions, 15 deletions
diff --git a/newlib/libc/string/Makefile.am b/newlib/libc/string/Makefile.am
index d97c1ff67..a56522121 100644
--- a/newlib/libc/string/Makefile.am
+++ b/newlib/libc/string/Makefile.am
@@ -33,6 +33,7 @@ LIB_SOURCES = \
strncpy.c \
strpbrk.c \
strrchr.c \
+ strsep.c \
strspn.c \
strtok.c \
strtok_r.c \
diff --git a/newlib/libc/string/Makefile.in b/newlib/libc/string/Makefile.in
index b3c41e496..c27d17aad 100644
--- a/newlib/libc/string/Makefile.in
+++ b/newlib/libc/string/Makefile.in
@@ -131,6 +131,7 @@ LIB_SOURCES = \
strncpy.c \
strpbrk.c \
strrchr.c \
+ strsep.c \
strspn.c \
strtok.c \
strtok_r.c \
@@ -181,9 +182,9 @@ lib_a_LIBADD =
@USE_LIBTOOL_FALSE@rindex.o strcat.o strchr.o strcmp.o strcasecmp.o \
@USE_LIBTOOL_FALSE@strcoll.o strcpy.o strcspn.o strerror.o strlcat.o \
@USE_LIBTOOL_FALSE@strlcpy.o strlen.o strlwr.o strncat.o strncmp.o \
-@USE_LIBTOOL_FALSE@strncasecmp.o strncpy.o strpbrk.o strrchr.o strspn.o \
-@USE_LIBTOOL_FALSE@strtok.o strtok_r.o strupr.o strxfrm.o strstr.o \
-@USE_LIBTOOL_FALSE@swab.o u_strerr.o
+@USE_LIBTOOL_FALSE@strncasecmp.o strncpy.o strpbrk.o strrchr.o strsep.o \
+@USE_LIBTOOL_FALSE@strspn.o strtok.o strtok_r.o strupr.o strxfrm.o \
+@USE_LIBTOOL_FALSE@strstr.o swab.o u_strerr.o
LTLIBRARIES = $(noinst_LTLIBRARIES)
libstring_la_LIBADD =
@@ -193,8 +194,9 @@ libstring_la_LIBADD =
@USE_LIBTOOL_TRUE@strcasecmp.lo strcoll.lo strcpy.lo strcspn.lo \
@USE_LIBTOOL_TRUE@strerror.lo strlcat.lo strlcpy.lo strlen.lo strlwr.lo \
@USE_LIBTOOL_TRUE@strncat.lo strncmp.lo strncasecmp.lo strncpy.lo \
-@USE_LIBTOOL_TRUE@strpbrk.lo strrchr.lo strspn.lo strtok.lo strtok_r.lo \
-@USE_LIBTOOL_TRUE@strupr.lo strxfrm.lo strstr.lo swab.lo u_strerr.lo
+@USE_LIBTOOL_TRUE@strpbrk.lo strrchr.lo strsep.lo strspn.lo strtok.lo \
+@USE_LIBTOOL_TRUE@strtok_r.lo strupr.lo strxfrm.lo strstr.lo swab.lo \
+@USE_LIBTOOL_TRUE@u_strerr.lo
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
diff --git a/newlib/libc/string/strsep.c b/newlib/libc/string/strsep.c
new file mode 100644
index 000000000..d3d0ad0a9
--- /dev/null
+++ b/newlib/libc/string/strsep.c
@@ -0,0 +1,19 @@
+/* BSD strsep function */
+
+/* Copyright 2002, Red Hat Inc. */
+
+/* undef STRICT_ANSI so that strsep prototype will be defined */
+#undef __STRICT_ANSI__
+#include <string.h>
+#include <_ansi.h>
+#include <reent.h>
+
+extern char *__strtok_r (char *, const char *, char **, int);
+
+char *
+_DEFUN (strsep, (source_ptr, delim),
+ register char **source_ptr _AND
+ register const char *delim)
+{
+ return __strtok_r (*source_ptr, delim, source_ptr, 0);
+}
diff --git a/newlib/libc/string/strtok.c b/newlib/libc/string/strtok.c
index 292c16743..8d53290c7 100644
--- a/newlib/libc/string/strtok.c
+++ b/newlib/libc/string/strtok.c
@@ -1,6 +1,6 @@
/*
FUNCTION
- <<strtok>>---get next token from a string
+ <<strtok>>,<<strtok_r>>,<<strsep>>---get next token from a string
INDEX
strtok
@@ -8,11 +8,15 @@ INDEX
INDEX
strtok_r
+INDEX
+ strsep
+
ANSI_SYNOPSIS
#include <string.h>
char *strtok(char *<[source]>, const char *<[delimiters]>)
char *strtok_r(char *<[source]>, const char *<[delimiters]>,
char **<[lasts]>)
+ char *strsep(char **<[source_ptr]>, const char *<[delimiters]>)
TRAD_SYNOPSIS
#include <string.h>
@@ -25,6 +29,10 @@ TRAD_SYNOPSIS
char *<[delimiters]>;
char **<[lasts]>;
+ char *strsep(<[source_ptr]>, <[delimiters]>)
+ char **<[source_ptr]>;
+ char *<[delimiters]>;
+
DESCRIPTION
The <<strtok>> function is used to isolate sequential tokens in a
null-terminated string, <<*<[source]>>>. These tokens are delimited
@@ -43,18 +51,30 @@ DESCRIPTION
The <<strtok_r>> function has the same behavior as <<strtok>>, except
a pointer to placeholder <<*[lasts]>> must be supplied by the caller.
+ The <<strsep>> function is similar in behavior to <<strtok>>, except
+ a pointer to the string pointer must be supplied <<[source_ptr]>> and
+ the function does not skip leading delimeters. When the string starts
+ with a delimeter, the delimeter is changed to the NUL character and
+ the empty string is returned. Like <<strtok_r>> and <<strtok>>, the
+ <<*[source_ptr]>> is updated to the next character following the
+ last delimeter found or NULL if the end of string is reached with
+ no more delimeters.
+
RETURNS
- <<strtok>> returns a pointer to the next token, or <<NULL>> if
- no more tokens can be found.
+ <<strtok>>, <<strtok_r>>, and <<strsep>> all return a pointer to the
+ next token, or <<NULL>> if no more tokens can be found. For
+ <<strsep>>, a token may be the empty string.
NOTES
<<strtok>> is unsafe for multi-thread applications. <<strtok_r>>
- is MT-Safe and should be used instead.
+ and <<strsep>> are MT-Safe and should be used instead.
PORTABILITY
<<strtok>> is ANSI C.
+<<strtok_r>> is POSIX.
+<<strsep>> is a BSD-extension.
-<<strtok>> requires no supporting OS subroutines.
+<<strtok>>, <<strtok_r>>, and <<strsep>> require no supporting OS subroutines.
QUICKREF
strtok ansi impure
@@ -68,12 +88,14 @@ QUICKREF
#ifndef _REENT_ONLY
+extern char *__strtok_r (char *, const char *, char **, int);
+
char *
_DEFUN (strtok, (s, delim),
register char *s _AND
register const char *delim)
{
_REENT_CHECK_MISC(_REENT);
- return strtok_r (s, delim, &(_REENT_STRTOK_LAST(_REENT)));
+ return __strtok_r (s, delim, &(_REENT_STRTOK_LAST(_REENT)), 1);
}
#endif
diff --git a/newlib/libc/string/strtok_r.c b/newlib/libc/string/strtok_r.c
index ed323369e..c4aecc811 100644
--- a/newlib/libc/string/strtok_r.c
+++ b/newlib/libc/string/strtok_r.c
@@ -34,10 +34,11 @@
#include <string.h>
char *
-_DEFUN (strtok_r, (s, delim, lasts),
+_DEFUN (__strtok_r, (s, delim, lasts, skip_leading_delim),
register char *s _AND
register const char *delim _AND
- char **lasts)
+ char **lasts _AND
+ int skip_leading_delim)
{
register char *spanp;
register int c, sc;
@@ -53,8 +54,16 @@ _DEFUN (strtok_r, (s, delim, lasts),
cont:
c = *s++;
for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
- if (c == sc)
- goto cont;
+ if (c == sc) {
+ if (skip_leading_delim) {
+ goto cont;
+ }
+ else {
+ *lasts = s;
+ s[-1] = 0;
+ return (s - 1);
+ }
+ }
}
if (c == 0) { /* no non-delimiter characters */
@@ -83,3 +92,12 @@ cont:
}
/* NOTREACHED */
}
+
+char *
+_DEFUN (strtok_r, (s, delim, lasts),
+ register char *s _AND
+ register const char *delim _AND
+ char **lasts)
+{
+ return __strtok_r (s, delim, lasts, 1);
+}