forked from KolibriOS/kolibrios
newlib: update
git-svn-id: svn://kolibrios.org@1906 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
147
programs/develop/libraries/newlib/string/strcasestr.c
Normal file
147
programs/develop/libraries/newlib/string/strcasestr.c
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcasestr>>---case-insensitive character string search
|
||||
|
||||
INDEX
|
||||
strcasestr
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strcasestr(const char *<[s]>, const char *<[find]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <string.h>
|
||||
int strcasecmp(<[s]>, <[find]>)
|
||||
char *<[s]>;
|
||||
char *<[find]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<strcasestr>> searchs the string <[s]> for
|
||||
the first occurrence of the sequence <[find]>. <<strcasestr>>
|
||||
is identical to <<strstr>> except the search is
|
||||
case-insensitive.
|
||||
|
||||
RETURNS
|
||||
|
||||
A pointer to the first case-insensitive occurrence of the sequence
|
||||
<[find]> or <<NULL>> if no match was found.
|
||||
|
||||
PORTABILITY
|
||||
<<strcasestr>> is in the Berkeley Software Distribution.
|
||||
|
||||
<<strcasestr>> requires no supporting OS subroutines. It uses
|
||||
tolower() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
strcasestr
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* The quadratic code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/* Linear algorithm Copyright (C) 2008 Eric Blake
|
||||
* Permission to use, copy, modify, and distribute the linear portion of
|
||||
* software is freely granted, provided that this notice is preserved.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||
# define RETURN_TYPE char *
|
||||
# define AVAILABLE(h, h_l, j, n_l) \
|
||||
(!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
|
||||
&& ((h_l) = (j) + (n_l)))
|
||||
# define CANON_ELEMENT(c) tolower (c)
|
||||
# define CMP_FUNC strncasecmp
|
||||
# include "str-two-way.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Find the first occurrence of find in s, ignore case.
|
||||
*/
|
||||
char *
|
||||
strcasestr(s, find)
|
||||
const char *s, *find;
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
|
||||
/* Less code size, but quadratic performance in the worst case. */
|
||||
char c, sc;
|
||||
size_t len;
|
||||
|
||||
if ((c = *find++) != 0) {
|
||||
c = tolower((unsigned char)c);
|
||||
len = strlen(find);
|
||||
do {
|
||||
do {
|
||||
if ((sc = *s++) == 0)
|
||||
return (NULL);
|
||||
} while ((char)tolower((unsigned char)sc) != c);
|
||||
} while (strncasecmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return ((char *)s);
|
||||
|
||||
#else /* compilation for speed */
|
||||
|
||||
/* Larger code size, but guaranteed linear performance. */
|
||||
const char *haystack = s;
|
||||
const char *needle = find;
|
||||
size_t needle_len; /* Length of NEEDLE. */
|
||||
size_t haystack_len; /* Known minimum length of HAYSTACK. */
|
||||
int ok = 1; /* True if NEEDLE is prefix of HAYSTACK. */
|
||||
|
||||
/* Determine length of NEEDLE, and in the process, make sure
|
||||
HAYSTACK is at least as long (no point processing all of a long
|
||||
NEEDLE if HAYSTACK is too short). */
|
||||
while (*haystack && *needle)
|
||||
ok &= (tolower ((unsigned char) *haystack++)
|
||||
== tolower ((unsigned char) *needle++));
|
||||
if (*needle)
|
||||
return NULL;
|
||||
if (ok)
|
||||
return (char *) s;
|
||||
needle_len = needle - find;
|
||||
haystack = s + 1;
|
||||
haystack_len = needle_len - 1;
|
||||
|
||||
/* Perform the search. */
|
||||
if (needle_len < LONG_NEEDLE_THRESHOLD)
|
||||
return two_way_short_needle ((const unsigned char *) haystack,
|
||||
haystack_len,
|
||||
(const unsigned char *) find, needle_len);
|
||||
return two_way_long_needle ((const unsigned char *) haystack, haystack_len,
|
||||
(const unsigned char *) find, needle_len);
|
||||
#endif /* compilation for speed */
|
||||
}
|
||||
104
programs/develop/libraries/newlib/string/strcat.c
Normal file
104
programs/develop/libraries/newlib/string/strcat.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcat>>---concatenate strings
|
||||
|
||||
INDEX
|
||||
strcat
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strcat(char *<[dst]>, const char *<[src]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strcat(<[dst]>, <[src]>)
|
||||
char *<[dst]>;
|
||||
char *<[src]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<strcat>> appends a copy of the string pointed to by <[src]>
|
||||
(including the terminating null character) to the end of the
|
||||
string pointed to by <[dst]>. The initial character of
|
||||
<[src]> overwrites the null character at the end of <[dst]>.
|
||||
|
||||
RETURNS
|
||||
This function returns the initial value of <[dst]>
|
||||
|
||||
PORTABILITY
|
||||
<<strcat>> is ANSI C.
|
||||
|
||||
<<strcat>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strcat ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if X is aligned on a "long" boundary. */
|
||||
#define ALIGNED(X) \
|
||||
(((long)X & (sizeof (long) - 1)) == 0)
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
|
||||
/*SUPPRESS 560*/
|
||||
/*SUPPRESS 530*/
|
||||
|
||||
char *
|
||||
_DEFUN (strcat, (s1, s2),
|
||||
char *s1 _AND
|
||||
_CONST char *s2)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
char *s = s1;
|
||||
|
||||
while (*s1)
|
||||
s1++;
|
||||
|
||||
while (*s1++ = *s2++)
|
||||
;
|
||||
return s;
|
||||
#else
|
||||
char *s = s1;
|
||||
|
||||
|
||||
/* Skip over the data in s1 as quickly as possible. */
|
||||
if (ALIGNED (s1))
|
||||
{
|
||||
unsigned long *aligned_s1 = (unsigned long *)s1;
|
||||
while (!DETECTNULL (*aligned_s1))
|
||||
aligned_s1++;
|
||||
|
||||
s1 = (char *)aligned_s1;
|
||||
}
|
||||
|
||||
while (*s1)
|
||||
s1++;
|
||||
|
||||
/* s1 now points to the its trailing null character, we can
|
||||
just use strcpy to do the work for us now.
|
||||
|
||||
?!? We might want to just include strcpy here.
|
||||
Also, this will cause many more unaligned string copies because
|
||||
s1 is much less likely to be aligned. I don't know if its worth
|
||||
tweaking strcpy to handle this better. */
|
||||
strcpy (s1, s2);
|
||||
|
||||
return s;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
48
programs/develop/libraries/newlib/string/strcoll.c
Normal file
48
programs/develop/libraries/newlib/string/strcoll.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcoll>>---locale-specific character string compare
|
||||
|
||||
INDEX
|
||||
strcoll
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <string.h>
|
||||
int strcoll(const char *<[stra]>, const char * <[strb]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <string.h>
|
||||
int strcoll(<[stra]>, <[strb]>)
|
||||
char *<[stra]>;
|
||||
char *<[strb]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<strcoll>> compares the string pointed to by <[stra]> to
|
||||
the string pointed to by <[strb]>, using an interpretation
|
||||
appropriate to the current <<LC_COLLATE>> state.
|
||||
|
||||
RETURNS
|
||||
If the first string is greater than the second string,
|
||||
<<strcoll>> returns a number greater than zero. If the two
|
||||
strings are equivalent, <<strcoll>> returns zero. If the first
|
||||
string is less than the second string, <<strcoll>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<strcoll>> is ANSI C.
|
||||
|
||||
<<strcoll>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strcoll ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
_DEFUN (strcoll, (a, b),
|
||||
_CONST char *a _AND
|
||||
_CONST char *b)
|
||||
|
||||
{
|
||||
return strcmp (a, b);
|
||||
}
|
||||
114
programs/develop/libraries/newlib/string/strncat.c
Normal file
114
programs/develop/libraries/newlib/string/strncat.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strncat>>---concatenate strings
|
||||
|
||||
INDEX
|
||||
strncat
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strncat(char *<[dst]>, const char *<[src]>, size_t <[length]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strncat(<[dst]>, <[src]>, <[length]>)
|
||||
char *<[dst]>;
|
||||
char *<[src]>;
|
||||
size_t <[length]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<strncat>> appends not more than <[length]> characters from
|
||||
the string pointed to by <[src]> (including the terminating
|
||||
null character) to the end of the string pointed to by
|
||||
<[dst]>. The initial character of <[src]> overwrites the null
|
||||
character at the end of <[dst]>. A terminating null character
|
||||
is always appended to the result
|
||||
|
||||
WARNINGS
|
||||
Note that a null is always appended, so that if the copy is
|
||||
limited by the <[length]> argument, the number of characters
|
||||
appended to <[dst]> is <<n + 1>>.
|
||||
|
||||
RETURNS
|
||||
This function returns the initial value of <[dst]>
|
||||
|
||||
PORTABILITY
|
||||
<<strncat>> is ANSI C.
|
||||
|
||||
<<strncat>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strncat ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if X is aligned on a "long" boundary. */
|
||||
#define ALIGNED(X) \
|
||||
(((long)X & (sizeof (long) - 1)) == 0)
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
char *
|
||||
_DEFUN (strncat, (s1, s2, n),
|
||||
char *s1 _AND
|
||||
_CONST char *s2 _AND
|
||||
size_t n)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
char *s = s1;
|
||||
|
||||
while (*s1)
|
||||
s1++;
|
||||
while (n-- != 0 && (*s1++ = *s2++))
|
||||
{
|
||||
if (n == 0)
|
||||
*s1 = '\0';
|
||||
}
|
||||
|
||||
return s;
|
||||
#else
|
||||
char *s = s1;
|
||||
|
||||
/* Skip over the data in s1 as quickly as possible. */
|
||||
if (ALIGNED (s1))
|
||||
{
|
||||
unsigned long *aligned_s1 = (unsigned long *)s1;
|
||||
while (!DETECTNULL (*aligned_s1))
|
||||
aligned_s1++;
|
||||
|
||||
s1 = (char *)aligned_s1;
|
||||
}
|
||||
|
||||
while (*s1)
|
||||
s1++;
|
||||
|
||||
/* s1 now points to the its trailing null character, now copy
|
||||
up to N bytes from S2 into S1 stopping if a NULL is encountered
|
||||
in S2.
|
||||
|
||||
It is not safe to use strncpy here since it copies EXACTLY N
|
||||
characters, NULL padding if necessary. */
|
||||
while (n-- != 0 && (*s1++ = *s2++))
|
||||
{
|
||||
if (n == 0)
|
||||
*s1 = '\0';
|
||||
}
|
||||
|
||||
return s;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
16
programs/develop/libraries/newlib/string/strndup.c
Normal file
16
programs/develop/libraries/newlib/string/strndup.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <reent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
_DEFUN (strndup, (str, n),
|
||||
_CONST char *str _AND
|
||||
size_t n)
|
||||
{
|
||||
return _strndup_r (_REENT, str, n);
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
27
programs/develop/libraries/newlib/string/strndup_r.c
Normal file
27
programs/develop/libraries/newlib/string/strndup_r.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <reent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
_DEFUN (_strndup_r, (reent_ptr, str, n),
|
||||
struct _reent *reent_ptr _AND
|
||||
_CONST char *str _AND
|
||||
size_t n)
|
||||
{
|
||||
_CONST char *ptr = str;
|
||||
size_t len;
|
||||
char *copy;
|
||||
|
||||
while (n-- > 0 && *ptr)
|
||||
ptr++;
|
||||
|
||||
len = ptr - str;
|
||||
|
||||
copy = _malloc_r (reent_ptr, len + 1);
|
||||
if (copy)
|
||||
{
|
||||
memcpy (copy, str, len);
|
||||
copy[len] = '\0';
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
58
programs/develop/libraries/newlib/string/strpbrk.c
Normal file
58
programs/develop/libraries/newlib/string/strpbrk.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strpbrk>>---find characters in string
|
||||
|
||||
INDEX
|
||||
strpbrk
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strpbrk(const char *<[s1]>, const char *<[s2]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strpbrk(<[s1]>, <[s2]>)
|
||||
char *<[s1]>;
|
||||
char *<[s2]>;
|
||||
|
||||
DESCRIPTION
|
||||
This function locates the first occurence in the string
|
||||
pointed to by <[s1]> of any character in string pointed to by
|
||||
<[s2]> (excluding the terminating null character).
|
||||
|
||||
RETURNS
|
||||
<<strpbrk>> returns a pointer to the character found in <[s1]>, or a
|
||||
null pointer if no character from <[s2]> occurs in <[s1]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strpbrk>> requires no supporting OS subroutines.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
_DEFUN (strpbrk, (s1, s2),
|
||||
_CONST char *s1 _AND
|
||||
_CONST char *s2)
|
||||
{
|
||||
_CONST char *c = s2;
|
||||
if (!*s1)
|
||||
return (char *) NULL;
|
||||
|
||||
while (*s1)
|
||||
{
|
||||
for (c = s2; *c; c++)
|
||||
{
|
||||
if (*s1 == *c)
|
||||
break;
|
||||
}
|
||||
if (*c)
|
||||
break;
|
||||
s1++;
|
||||
}
|
||||
|
||||
if (*c == '\0')
|
||||
s1 = NULL;
|
||||
|
||||
return (char *) s1;
|
||||
}
|
||||
19
programs/develop/libraries/newlib/string/strsep.c
Normal file
19
programs/develop/libraries/newlib/string/strsep.c
Normal 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);
|
||||
}
|
||||
101
programs/develop/libraries/newlib/string/strtok.c
Normal file
101
programs/develop/libraries/newlib/string/strtok.c
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strtok>>, <<strtok_r>>, <<strsep>>---get next token from a string
|
||||
|
||||
INDEX
|
||||
strtok
|
||||
|
||||
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>
|
||||
char *strtok(<[source]>, <[delimiters]>)
|
||||
char *<[source]>;
|
||||
char *<[delimiters]>;
|
||||
|
||||
char *strtok_r(<[source]>, <[delimiters]>, <[lasts]>)
|
||||
char *<[source]>;
|
||||
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
|
||||
in the string by at least one of the characters in <<*<[delimiters]>>>.
|
||||
The first time that <<strtok>> is called, <<*<[source]>>> should be
|
||||
specified; subsequent calls, wishing to obtain further tokens from
|
||||
the same string, should pass a null pointer instead. The separator
|
||||
string, <<*<[delimiters]>>>, must be supplied each time and may
|
||||
change between calls.
|
||||
|
||||
The <<strtok>> function returns a pointer to the beginning of each
|
||||
subsequent token in the string, after replacing the separator
|
||||
character itself with a null character. When no more tokens remain,
|
||||
a null pointer is returned.
|
||||
|
||||
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 delimiters. When the string starts
|
||||
with a delimiter, the delimiter is changed to the null character and
|
||||
the empty string is returned. Like <<strtok_r>> and <<strtok>>, the
|
||||
<<*<[source_ptr]>>> is updated to the next character following the
|
||||
last delimiter found or NULL if the end of string is reached with
|
||||
no more delimiters.
|
||||
|
||||
RETURNS
|
||||
<<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-threaded applications. <<strtok_r>>
|
||||
and <<strsep>> are thread-safe and should be used instead.
|
||||
|
||||
PORTABILITY
|
||||
<<strtok>> is ANSI C.
|
||||
<<strtok_r>> is POSIX.
|
||||
<<strsep>> is a BSD extension.
|
||||
|
||||
<<strtok>>, <<strtok_r>>, and <<strsep>> require no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strtok ansi impure
|
||||
*/
|
||||
|
||||
/* undef STRICT_ANSI so that strtok_r prototype will be defined */
|
||||
#undef __STRICT_ANSI__
|
||||
#include <string.h>
|
||||
#include <_ansi.h>
|
||||
#include <reent.h>
|
||||
|
||||
#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)), 1);
|
||||
}
|
||||
#endif
|
||||
99
programs/develop/libraries/newlib/string/strtok_r.c
Normal file
99
programs/develop/libraries/newlib/string/strtok_r.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 1988 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
_DEFUN (__strtok_r, (s, delim, lasts, skip_leading_delim),
|
||||
register char *s _AND
|
||||
register const char *delim _AND
|
||||
char **lasts _AND
|
||||
int skip_leading_delim)
|
||||
{
|
||||
register char *spanp;
|
||||
register int c, sc;
|
||||
char *tok;
|
||||
|
||||
|
||||
if (s == NULL && (s = *lasts) == NULL)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
||||
*/
|
||||
cont:
|
||||
c = *s++;
|
||||
for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
|
||||
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 */
|
||||
*lasts = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
tok = s - 1;
|
||||
|
||||
/*
|
||||
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
|
||||
* Note that delim must have one NUL; we stop if we see that, too.
|
||||
*/
|
||||
for (;;) {
|
||||
c = *s++;
|
||||
spanp = (char *)delim;
|
||||
do {
|
||||
if ((sc = *spanp++) == c) {
|
||||
if (c == 0)
|
||||
s = NULL;
|
||||
else
|
||||
s[-1] = 0;
|
||||
*lasts = s;
|
||||
return (tok);
|
||||
}
|
||||
} while (sc != 0);
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
46
programs/develop/libraries/newlib/string/strupr.c
Normal file
46
programs/develop/libraries/newlib/string/strupr.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strupr>>---force string to uppercase
|
||||
|
||||
INDEX
|
||||
strupr
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strupr(char *<[a]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strupr(<[a]>)
|
||||
char *<[a]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<strupr>> converts each character in the string at <[a]> to
|
||||
uppercase.
|
||||
|
||||
RETURNS
|
||||
<<strupr>> returns its argument, <[a]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strupr>> is not widely portable.
|
||||
|
||||
<<strupr>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strupr
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char *
|
||||
_DEFUN (strupr, (s),
|
||||
char *s)
|
||||
{
|
||||
unsigned char *ucs = (unsigned char *) s;
|
||||
for ( ; *ucs != '\0'; ucs++)
|
||||
{
|
||||
*ucs = toupper(*ucs);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
Reference in New Issue
Block a user