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.
This commit is contained in:
Jeff Johnston 2002-05-24 00:13:57 +00:00
parent bb2b4dedc6
commit 7a364eb364
6 changed files with 87 additions and 15 deletions

View File

@ -1,3 +1,13 @@
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.
2002-05-23 Gareth Pearce <tilps@hotmail.com>
* libc/stdio/Makefile.am: Modify to add setbuffer.c and setlinebuf.c.

View File

@ -33,6 +33,7 @@ LIB_SOURCES = \
strncpy.c \
strpbrk.c \
strrchr.c \
strsep.c \
strspn.c \
strtok.c \
strtok_r.c \

View File

@ -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)

View File

@ -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);
}

View File

@ -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

View File

@ -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);
}