1 /* A GNU-like <string.h>.
3 Copyright (C) 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@
31 memmem (void const *__haystack, size_t __haystack_len,
32 void const *__needle, size_t __needle_len);
35 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
38 void *mempcpy (void *restrict __dest, void const *restrict __src, size_t __n);
41 /* Search backwards through a block for a byte (specified as an int). */
42 #if ! @HAVE_DECL_MEMRCHR@
43 void *memrchr (void const *, int, size_t);
46 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
48 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 char *stpncpy (char *restrict __dst, char const *restrict __src, size_t __n);
58 /* Compare strings S1 and S2, ignoring case, returning less than, equal to or
59 greater than zero if S1 is lexicographically less than, equal to or greater
61 Note: This function may, in multibyte locales, return 0 for strings of
63 No known system has a strcasecmp() function that works correctly in
64 multibyte locales. Therefore use our version always, if the
65 strcase module is available. */
66 #if @REPLACE_STRCASECMP@
67 # define strcasecmp rpl_strcasecmp
68 int strcasecmp (char const *__s1, char const *__s2);
71 /* Compare no more than N bytes of strings S1 and S2, ignoring case,
72 returning less than, equal to or greater than zero if S1 is
73 lexicographically less than, equal to or greater than S2.
74 Note: This function cannot work correctly in multibyte locales. */
75 #if ! @HAVE_DECL_STRNCASECMP@
76 int strncasecmp (char const *__s1, char const *__s2, size_t __n);
79 /* Find the first occurrence of C in S or the final NUL byte. */
80 #if ! @HAVE_STRCHRNUL@
81 char *strchrnul (char const *__s, int __c_in);
84 /* Duplicate S, returning an identical malloc'd string. */
85 #if ! @HAVE_DECL_STRDUP@ && ! defined strdup
86 char *strdup (char const *__s);
89 /* Return a newly allocated copy of at most N bytes of STRING. */
92 # define strndup rpl_strndup
93 # if ! @HAVE_DECL_STRNDUP@
94 char *strndup (char const *__string, size_t __n);
98 /* Find the length (number of bytes) of STRING, but scan at most
99 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
101 #if ! @HAVE_DECL_STRNLEN@
102 size_t strnlen (char const *__string, size_t __maxlen);
105 /* Find the first occurrence in S of any character in ACCEPT. */
107 char *strpbrk (char const *__s, char const *__accept);
110 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
111 If one is found, overwrite it with a NUL, and advance *STRINGP
112 to point to the next char after it. Otherwise, set *STRINGP to NULL.
113 If *STRINGP was already NULL, nothing happens.
114 Return the old value of *STRINGP.
116 This is a variant of strtok() that is multithread-safe and supports
119 Caveat: It modifies the original string.
120 Caveat: These functions cannot be used on constant strings.
121 Caveat: The identity of the delimiting character is lost.
122 Caveat: It doesn't work with multibyte strings unless all of the delimiter
123 characters are ASCII characters < 0x30.
125 See also strtok_r(). */
127 char *strsep (char **restrict __stringp, char const *restrict __delim);
130 /* Find the first occurrence of NEEDLE in HAYSTACK.
131 No known system has a strstr() function that works correctly in
132 multibyte locales. Therefore use our version always, if the strstr
133 module is available. */
136 # define strstr rpl_strstr
137 char *strstr (char const *__haystack, char const *__needle);
140 /* Parse S into tokens separated by characters in DELIM.
141 If S is NULL, the saved pointer in SAVE_PTR is used as
142 the next starting point. For example:
143 char s[] = "-abc-=-def";
145 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
146 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
147 x = strtok_r(NULL, "=", &sp); // x = NULL
150 This is a variant of strtok() that is multithread-safe.
152 For the POSIX documentation for this function, see:
153 http://www.opengroup.org/susv3xsh/strtok.html
155 Caveat: It modifies the original string.
156 Caveat: These functions cannot be used on constant strings.
157 Caveat: The identity of the delimiting character is lost.
158 Caveat: It doesn't work with multibyte strings unless all of the delimiter
159 characters are ASCII characters < 0x30.
161 See also strsep(). */
162 #if ! @HAVE_DECL_STRTOK_R@
163 char *strtok_r (char *restrict __s, char const *restrict __sep,
164 char **restrict __lasts);