1 /* A GNU-like <string.h>.
3 Copyright (C) 1995-1996, 2001-2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 #include @ABSOLUTE_STRING_H@
28 /* Return the first occurrence of NEEDLE in HAYSTACK. */
29 #if ! @HAVE_DECL_MEMMEM@
30 extern void *memmem (void const *__haystack, size_t __haystack_len,
31 void const *__needle, size_t __needle_len);
34 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
37 extern void *mempcpy (void *restrict __dest, void const *restrict __src,
41 /* Search backwards through a block for a byte (specified as an int). */
42 #if ! @HAVE_DECL_MEMRCHR@
43 extern void *memrchr (void const *, int, size_t);
46 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
48 extern char *stpcpy (char *restrict __dst, char const *restrict __src);
51 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
52 last non-NUL byte written into DST. */
54 # define stpncpy gnu_stpncpy
55 extern char *stpncpy (char *restrict __dst, char const *restrict __src,
59 /* Compare strings S1 and S2, ignoring case, returning less than, equal to or
60 greater than zero if S1 is lexicographically less than, equal to or greater
62 Note: This function may, in multibyte locales, return 0 for strings of
64 No known system has a strcasecmp() function that works correctly in
65 multibyte locales. Therefore use our version always, if the
66 strcase module is available. */
67 #if @REPLACE_STRCASECMP@
68 # define strcasecmp rpl_strcasecmp
69 extern int strcasecmp (char const *__s1, char const *__s2);
72 /* Compare no more than N bytes of strings S1 and S2, ignoring case,
73 returning less than, equal to or greater than zero if S1 is
74 lexicographically less than, equal to or greater than S2.
75 Note: This function cannot work correctly in multibyte locales. */
76 #if ! @HAVE_DECL_STRNCASECMP@
77 extern int strncasecmp (char const *__s1, char const *__s2, size_t __n);
80 /* Find the first occurrence of C in S or the final NUL byte. */
81 #if ! @HAVE_STRCHRNUL@
82 extern char *strchrnul (char const *__s, int __c_in);
85 /* Duplicate S, returning an identical malloc'd string. */
86 #if ! @HAVE_DECL_STRDUP@ && ! defined strdup
87 extern char *strdup (char const *__s);
90 /* Return a newly allocated copy of at most N bytes of STRING. */
93 # define strndup rpl_strndup
94 # if ! @HAVE_DECL_STRNDUP@
95 extern char *strndup (char const *__string, size_t __n);
99 /* Find the length (number of bytes) of STRING, but scan at most
100 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
102 #if ! @HAVE_DECL_STRNLEN@
103 extern size_t strnlen (char const *__string, size_t __maxlen);
106 /* Find the first occurrence in S of any character in ACCEPT. */
108 extern char *strpbrk (char const *__s, char const *__accept);
111 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
112 If one is found, overwrite it with a NUL, and advance *STRINGP
113 to point to the next char after it. Otherwise, set *STRINGP to NULL.
114 If *STRINGP was already NULL, nothing happens.
115 Return the old value of *STRINGP.
117 This is a variant of strtok() that is multithread-safe and supports
120 Caveat: It modifies the original string.
121 Caveat: These functions cannot be used on constant strings.
122 Caveat: The identity of the delimiting character is lost.
123 Caveat: It doesn't work with multibyte strings unless all of the delimiter
124 characters are ASCII characters < 0x30.
126 See also strtok_r(). */
128 extern char *strsep (char **restrict __stringp, char const *restrict __delim);
131 /* Find the first occurrence of NEEDLE in HAYSTACK.
132 No known system has a strstr() function that works correctly in
133 multibyte locales. Therefore use our version always, if the strstr
134 module is available. */
137 # define strstr rpl_strstr
138 extern char *strstr (char const *__haystack, char const *__needle);
141 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
143 Note: This function may, in multibyte locales, return success even if
144 strlen (haystack) < strlen (needle) ! */
145 #if @REPLACE_STRCASESTR@
147 # define strcasestr rpl_strcasestr
148 extern char *strcasestr (const char *haystack, const char *needle);
151 /* Parse S into tokens separated by characters in DELIM.
152 If S is NULL, the saved pointer in SAVE_PTR is used as
153 the next starting point. For example:
154 char s[] = "-abc-=-def";
156 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
157 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
158 x = strtok_r(NULL, "=", &sp); // x = NULL
161 This is a variant of strtok() that is multithread-safe.
163 For the POSIX documentation for this function, see:
164 http://www.opengroup.org/susv3xsh/strtok.html
166 Caveat: It modifies the original string.
167 Caveat: These functions cannot be used on constant strings.
168 Caveat: The identity of the delimiting character is lost.
169 Caveat: It doesn't work with multibyte strings unless all of the delimiter
170 characters are ASCII characters < 0x30.
172 See also strsep(). */
173 #if ! @HAVE_DECL_STRTOK_R@
174 extern char *strtok_r (char *restrict __s, char const *restrict __sep,
175 char **restrict __lasts);