mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-22 21:10:07 +00:00
8667f90ec5
Clean up string functions that do not have a version in gnulib on the assumption that glibc is the canonical upstream copy of this code. basename has a copy in gnulib but it is largely written to handle Windows paths so merging it is not really viable. The changes mostly consist of switching to ANSI function prototypes and removing unused includes. As many of these functions do not get built in a typical build due to architecture optimized versions being used instead I built these by hand to verify there were no build warnings and the code was identical. 2014-04-07 Will Newton <will.newton@linaro.org> * string/basename.c [HAVE_CONFIG_H]: Remove #ifdef and and contents. [!_LIBC] Remove #ifndef and contents. (basename): Use ANSI prototype. [_LIBC] Remove #idef. * string/memccpy.c (__memccpy): Use ANSI prototype. * string/memfrob.c (memfrob): Likewise. * string/strcoll.c (STRCOLL): Likewise. * string/strlen.c (strlen): Likewise. * string/strtok.c (STRTOK): Likewise. * string/strcat.c: Remove unused #include of memcopy.h. (strcat): Use ANSI prototype. * string/strchr.c: Remove unused #include of memcopy.h. (strchr): Use ANSI prototype. * string/strcmp.c: Remove unused #include of memcopy.h. (strcmp): Use ANSI prototype. * string/strcpy.c: Remove unused #include of memcopy.h. (strcpy): Use ANSI prototype.
68 lines
1.7 KiB
C
68 lines
1.7 KiB
C
/* Copyright (C) 1991-2014 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
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#include <string.h>
|
|
|
|
|
|
static char *olds;
|
|
|
|
#undef strtok
|
|
|
|
#ifndef STRTOK
|
|
# define STRTOK strtok
|
|
#endif
|
|
|
|
/* Parse S into tokens separated by characters in DELIM.
|
|
If S is NULL, the last string strtok() was called with is
|
|
used. For example:
|
|
char s[] = "-abc-=-def";
|
|
x = strtok(s, "-"); // x = "abc"
|
|
x = strtok(NULL, "-="); // x = "def"
|
|
x = strtok(NULL, "="); // x = NULL
|
|
// s = "abc\0=-def\0"
|
|
*/
|
|
char *
|
|
STRTOK (char *s, const char *delim)
|
|
{
|
|
char *token;
|
|
|
|
if (s == NULL)
|
|
s = olds;
|
|
|
|
/* Scan leading delimiters. */
|
|
s += strspn (s, delim);
|
|
if (*s == '\0')
|
|
{
|
|
olds = s;
|
|
return NULL;
|
|
}
|
|
|
|
/* Find the end of the token. */
|
|
token = s;
|
|
s = strpbrk (token, delim);
|
|
if (s == NULL)
|
|
/* This token finishes the string. */
|
|
olds = __rawmemchr (token, '\0');
|
|
else
|
|
{
|
|
/* Terminate the token and make OLDS point past it. */
|
|
*s = '\0';
|
|
olds = s + 1;
|
|
}
|
|
return token;
|
|
}
|