]> git.cworth.org Git - tar/blob - gnu/string.in.h
Imported Upstream version 1.24
[tar] / gnu / string.in.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* A GNU-like <string.h>.
4
5    Copyright (C) 1995-1996, 2001-2010 Free Software Foundation, Inc.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3, or (at your option)
10    any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software Foundation,
19    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
20
21 #ifndef _GL_STRING_H
22
23 #if __GNUC__ >= 3
24 @PRAGMA_SYSTEM_HEADER@
25 #endif
26 @PRAGMA_COLUMNS@
27
28 /* The include_next requires a split double-inclusion guard.  */
29 #@INCLUDE_NEXT@ @NEXT_STRING_H@
30
31 #ifndef _GL_STRING_H
32 #define _GL_STRING_H
33
34 /* NetBSD 5.0 mis-defines NULL.  */
35 #include <stddef.h>
36
37 /* MirBSD defines mbslen as a macro.  */
38 #if @GNULIB_MBSLEN@ && defined __MirBSD__
39 # include <wchar.h>
40 #endif
41
42 #ifndef __attribute__
43 /* This feature is available in gcc versions 2.5 and later.  */
44 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
45 #  define __attribute__(Spec) /* empty */
46 # endif
47 #endif
48 /* The attribute __pure__ was added in gcc 2.96.  */
49 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
50 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
51 #else
52 # define _GL_ATTRIBUTE_PURE /* empty */
53 #endif
54
55 /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>.  */
56 /* But in any case avoid namespace pollution on glibc systems.  */
57 #if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
58     && ! defined __GLIBC__
59 # include <unistd.h>
60 #endif
61
62 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
63
64 /* The definition of _GL_ARG_NONNULL is copied here.  */
65
66 /* The definition of _GL_WARN_ON_USE is copied here.  */
67
68
69 /* Return the first instance of C within N bytes of S, or NULL.  */
70 #if @GNULIB_MEMCHR@
71 # if @REPLACE_MEMCHR@
72 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
73 #   define memchr rpl_memchr
74 #  endif
75 _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
76                                   _GL_ATTRIBUTE_PURE
77                                   _GL_ARG_NONNULL ((1)));
78 _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
79 # else
80 #  if ! @HAVE_MEMCHR@
81 _GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
82                                   _GL_ATTRIBUTE_PURE
83                                   _GL_ARG_NONNULL ((1)));
84 #  endif
85   /* On some systems, this function is defined as an overloaded function:
86        extern "C" { const void * std::memchr (const void *, int, size_t); }
87        extern "C++" { void * std::memchr (void *, int, size_t); }  */
88 _GL_CXXALIAS_SYS_CAST2 (memchr,
89                         void *, (void const *__s, int __c, size_t __n),
90                         void const *, (void const *__s, int __c, size_t __n));
91 # endif
92 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
93      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
94 _GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
95 _GL_CXXALIASWARN1 (memchr, void const *,
96                    (void const *__s, int __c, size_t __n));
97 # else
98 _GL_CXXALIASWARN (memchr);
99 # endif
100 #elif defined GNULIB_POSIXCHECK
101 # undef memchr
102 /* Assume memchr is always declared.  */
103 _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
104                  "use gnulib module memchr for portability" );
105 #endif
106
107 /* Return the first occurrence of NEEDLE in HAYSTACK.  */
108 #if @GNULIB_MEMMEM@
109 # if @REPLACE_MEMMEM@
110 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
111 #   define memmem rpl_memmem
112 #  endif
113 _GL_FUNCDECL_RPL (memmem, void *,
114                   (void const *__haystack, size_t __haystack_len,
115                    void const *__needle, size_t __needle_len)
116                   _GL_ATTRIBUTE_PURE
117                   _GL_ARG_NONNULL ((1, 3)));
118 _GL_CXXALIAS_RPL (memmem, void *,
119                   (void const *__haystack, size_t __haystack_len,
120                    void const *__needle, size_t __needle_len));
121 # else
122 #  if ! @HAVE_DECL_MEMMEM@
123 _GL_FUNCDECL_SYS (memmem, void *,
124                   (void const *__haystack, size_t __haystack_len,
125                    void const *__needle, size_t __needle_len)
126                   _GL_ATTRIBUTE_PURE
127                   _GL_ARG_NONNULL ((1, 3)));
128 #  endif
129 _GL_CXXALIAS_SYS (memmem, void *,
130                   (void const *__haystack, size_t __haystack_len,
131                    void const *__needle, size_t __needle_len));
132 # endif
133 _GL_CXXALIASWARN (memmem);
134 #elif defined GNULIB_POSIXCHECK
135 # undef memmem
136 # if HAVE_RAW_DECL_MEMMEM
137 _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
138                  "use gnulib module memmem-simple for portability, "
139                  "and module memmem for speed" );
140 # endif
141 #endif
142
143 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
144    last written byte.  */
145 #if @GNULIB_MEMPCPY@
146 # if ! @HAVE_MEMPCPY@
147 _GL_FUNCDECL_SYS (mempcpy, void *,
148                   (void *restrict __dest, void const *restrict __src,
149                    size_t __n)
150                   _GL_ARG_NONNULL ((1, 2)));
151 # endif
152 _GL_CXXALIAS_SYS (mempcpy, void *,
153                   (void *restrict __dest, void const *restrict __src,
154                    size_t __n));
155 _GL_CXXALIASWARN (mempcpy);
156 #elif defined GNULIB_POSIXCHECK
157 # undef mempcpy
158 # if HAVE_RAW_DECL_MEMPCPY
159 _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
160                  "use gnulib module mempcpy for portability");
161 # endif
162 #endif
163
164 /* Search backwards through a block for a byte (specified as an int).  */
165 #if @GNULIB_MEMRCHR@
166 # if ! @HAVE_DECL_MEMRCHR@
167 _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
168                                    _GL_ATTRIBUTE_PURE
169                                    _GL_ARG_NONNULL ((1)));
170 # endif
171   /* On some systems, this function is defined as an overloaded function:
172        extern "C++" { const void * std::memrchr (const void *, int, size_t); }
173        extern "C++" { void * std::memrchr (void *, int, size_t); }  */
174 _GL_CXXALIAS_SYS_CAST2 (memrchr,
175                         void *, (void const *, int, size_t),
176                         void const *, (void const *, int, size_t));
177 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
178      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
179 _GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t));
180 _GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t));
181 # else
182 _GL_CXXALIASWARN (memrchr);
183 # endif
184 #elif defined GNULIB_POSIXCHECK
185 # undef memrchr
186 # if HAVE_RAW_DECL_MEMRCHR
187 _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
188                  "use gnulib module memrchr for portability");
189 # endif
190 #endif
191
192 /* Find the first occurrence of C in S.  More efficient than
193    memchr(S,C,N), at the expense of undefined behavior if C does not
194    occur within N bytes.  */
195 #if @GNULIB_RAWMEMCHR@
196 # if ! @HAVE_RAWMEMCHR@
197 _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
198                                      _GL_ATTRIBUTE_PURE
199                                      _GL_ARG_NONNULL ((1)));
200 # endif
201   /* On some systems, this function is defined as an overloaded function:
202        extern "C++" { const void * std::rawmemchr (const void *, int); }
203        extern "C++" { void * std::rawmemchr (void *, int); }  */
204 _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
205                         void *, (void const *__s, int __c_in),
206                         void const *, (void const *__s, int __c_in));
207 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
208      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
209 _GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in));
210 _GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in));
211 # else
212 _GL_CXXALIASWARN (rawmemchr);
213 # endif
214 #elif defined GNULIB_POSIXCHECK
215 # undef rawmemchr
216 # if HAVE_RAW_DECL_RAWMEMCHR
217 _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
218                  "use gnulib module rawmemchr for portability");
219 # endif
220 #endif
221
222 /* Copy SRC to DST, returning the address of the terminating '\0' in DST.  */
223 #if @GNULIB_STPCPY@
224 # if ! @HAVE_STPCPY@
225 _GL_FUNCDECL_SYS (stpcpy, char *,
226                   (char *restrict __dst, char const *restrict __src)
227                   _GL_ARG_NONNULL ((1, 2)));
228 # endif
229 _GL_CXXALIAS_SYS (stpcpy, char *,
230                   (char *restrict __dst, char const *restrict __src));
231 _GL_CXXALIASWARN (stpcpy);
232 #elif defined GNULIB_POSIXCHECK
233 # undef stpcpy
234 # if HAVE_RAW_DECL_STPCPY
235 _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
236                  "use gnulib module stpcpy for portability");
237 # endif
238 #endif
239
240 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
241    last non-NUL byte written into DST.  */
242 #if @GNULIB_STPNCPY@
243 # if @REPLACE_STPNCPY@
244 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
245 #   undef stpncpy
246 #   define stpncpy rpl_stpncpy
247 #  endif
248 _GL_FUNCDECL_RPL (stpncpy, char *,
249                   (char *restrict __dst, char const *restrict __src,
250                    size_t __n)
251                   _GL_ARG_NONNULL ((1, 2)));
252 _GL_CXXALIAS_RPL (stpncpy, char *,
253                   (char *restrict __dst, char const *restrict __src,
254                    size_t __n));
255 # else
256 #  if ! @HAVE_STPNCPY@
257 _GL_FUNCDECL_SYS (stpncpy, char *,
258                   (char *restrict __dst, char const *restrict __src,
259                    size_t __n)
260                   _GL_ARG_NONNULL ((1, 2)));
261 #  endif
262 _GL_CXXALIAS_SYS (stpncpy, char *,
263                   (char *restrict __dst, char const *restrict __src,
264                    size_t __n));
265 # endif
266 _GL_CXXALIASWARN (stpncpy);
267 #elif defined GNULIB_POSIXCHECK
268 # undef stpncpy
269 # if HAVE_RAW_DECL_STPNCPY
270 _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
271                  "use gnulib module stpncpy for portability");
272 # endif
273 #endif
274
275 #if defined GNULIB_POSIXCHECK
276 /* strchr() does not work with multibyte strings if the locale encoding is
277    GB18030 and the character to be searched is a digit.  */
278 # undef strchr
279 /* Assume strchr is always declared.  */
280 _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
281                  "in some multibyte locales - "
282                  "use mbschr if you care about internationalization");
283 #endif
284
285 /* Find the first occurrence of C in S or the final NUL byte.  */
286 #if @GNULIB_STRCHRNUL@
287 # if ! @HAVE_STRCHRNUL@
288 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
289                                      _GL_ATTRIBUTE_PURE
290                                      _GL_ARG_NONNULL ((1)));
291 # endif
292   /* On some systems, this function is defined as an overloaded function:
293        extern "C++" { const char * std::strchrnul (const char *, int); }
294        extern "C++" { char * std::strchrnul (char *, int); }  */
295 _GL_CXXALIAS_SYS_CAST2 (strchrnul,
296                         char *, (char const *__s, int __c_in),
297                         char const *, (char const *__s, int __c_in));
298 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
299      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
300 _GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
301 _GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
302 # else
303 _GL_CXXALIASWARN (strchrnul);
304 # endif
305 #elif defined GNULIB_POSIXCHECK
306 # undef strchrnul
307 # if HAVE_RAW_DECL_STRCHRNUL
308 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
309                  "use gnulib module strchrnul for portability");
310 # endif
311 #endif
312
313 /* Duplicate S, returning an identical malloc'd string.  */
314 #if @GNULIB_STRDUP@
315 # if @REPLACE_STRDUP@
316 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
317 #   undef strdup
318 #   define strdup rpl_strdup
319 #  endif
320 _GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
321 _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
322 # else
323 #  if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
324     /* strdup exists as a function and as a macro.  Get rid of the macro.  */
325 #   undef strdup
326 #  endif
327 #  if !(@HAVE_DECL_STRDUP@ || defined strdup)
328 _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
329 #  endif
330 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
331 # endif
332 _GL_CXXALIASWARN (strdup);
333 #elif defined GNULIB_POSIXCHECK
334 # undef strdup
335 # if HAVE_RAW_DECL_STRDUP
336 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
337                  "use gnulib module strdup for portability");
338 # endif
339 #endif
340
341 /* Append no more than N characters from SRC onto DEST.  */
342 #if @GNULIB_STRNCAT@
343 # if @REPLACE_STRNCAT@
344 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
345 #   undef strncat
346 #   define strncat rpl_strncat
347 #  endif
348 _GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n)
349                                    _GL_ARG_NONNULL ((1, 2)));
350 _GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n));
351 # else
352 _GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n));
353 # endif
354 _GL_CXXALIASWARN (strncat);
355 #elif defined GNULIB_POSIXCHECK
356 # undef strncat
357 # if HAVE_RAW_DECL_STRNCAT
358 _GL_WARN_ON_USE (strncat, "strncat is unportable - "
359                  "use gnulib module strncat for portability");
360 # endif
361 #endif
362
363 /* Return a newly allocated copy of at most N bytes of STRING.  */
364 #if @GNULIB_STRNDUP@
365 # if @REPLACE_STRNDUP@
366 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
367 #   undef strndup
368 #   define strndup rpl_strndup
369 #  endif
370 _GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n)
371                                    _GL_ARG_NONNULL ((1)));
372 _GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n));
373 # else
374 #  if ! @HAVE_DECL_STRNDUP@
375 _GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n)
376                                    _GL_ARG_NONNULL ((1)));
377 #  endif
378 _GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n));
379 # endif
380 _GL_CXXALIASWARN (strndup);
381 #elif defined GNULIB_POSIXCHECK
382 # undef strndup
383 # if HAVE_RAW_DECL_STRNDUP
384 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
385                  "use gnulib module strndup for portability");
386 # endif
387 #endif
388
389 /* Find the length (number of bytes) of STRING, but scan at most
390    MAXLEN bytes.  If no '\0' terminator is found in that many bytes,
391    return MAXLEN.  */
392 #if @GNULIB_STRNLEN@
393 # if @REPLACE_STRNLEN@
394 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
395 #   undef strnlen
396 #   define strnlen rpl_strnlen
397 #  endif
398 _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
399                                    _GL_ATTRIBUTE_PURE
400                                    _GL_ARG_NONNULL ((1)));
401 _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
402 # else
403 #  if ! @HAVE_DECL_STRNLEN@
404 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
405                                    _GL_ATTRIBUTE_PURE
406                                    _GL_ARG_NONNULL ((1)));
407 #  endif
408 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
409 # endif
410 _GL_CXXALIASWARN (strnlen);
411 #elif defined GNULIB_POSIXCHECK
412 # undef strnlen
413 # if HAVE_RAW_DECL_STRNLEN
414 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
415                  "use gnulib module strnlen for portability");
416 # endif
417 #endif
418
419 #if defined GNULIB_POSIXCHECK
420 /* strcspn() assumes the second argument is a list of single-byte characters.
421    Even in this simple case, it does not work with multibyte strings if the
422    locale encoding is GB18030 and one of the characters to be searched is a
423    digit.  */
424 # undef strcspn
425 /* Assume strcspn is always declared.  */
426 _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
427                  "in multibyte locales - "
428                  "use mbscspn if you care about internationalization");
429 #endif
430
431 /* Find the first occurrence in S of any character in ACCEPT.  */
432 #if @GNULIB_STRPBRK@
433 # if ! @HAVE_STRPBRK@
434 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
435                                    _GL_ATTRIBUTE_PURE
436                                    _GL_ARG_NONNULL ((1, 2)));
437 # endif
438   /* On some systems, this function is defined as an overloaded function:
439        extern "C" { const char * strpbrk (const char *, const char *); }
440        extern "C++" { char * strpbrk (char *, const char *); }  */
441 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
442                         char *, (char const *__s, char const *__accept),
443                         const char *, (char const *__s, char const *__accept));
444 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
445      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
446 _GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
447 _GL_CXXALIASWARN1 (strpbrk, char const *,
448                    (char const *__s, char const *__accept));
449 # else
450 _GL_CXXALIASWARN (strpbrk);
451 # endif
452 # if defined GNULIB_POSIXCHECK
453 /* strpbrk() assumes the second argument is a list of single-byte characters.
454    Even in this simple case, it does not work with multibyte strings if the
455    locale encoding is GB18030 and one of the characters to be searched is a
456    digit.  */
457 #  undef strpbrk
458 _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
459                  "in multibyte locales - "
460                  "use mbspbrk if you care about internationalization");
461 # endif
462 #elif defined GNULIB_POSIXCHECK
463 # undef strpbrk
464 # if HAVE_RAW_DECL_STRPBRK
465 _GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
466                  "use gnulib module strpbrk for portability");
467 # endif
468 #endif
469
470 #if defined GNULIB_POSIXCHECK
471 /* strspn() assumes the second argument is a list of single-byte characters.
472    Even in this simple case, it cannot work with multibyte strings.  */
473 # undef strspn
474 /* Assume strspn is always declared.  */
475 _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
476                  "in multibyte locales - "
477                  "use mbsspn if you care about internationalization");
478 #endif
479
480 #if defined GNULIB_POSIXCHECK
481 /* strrchr() does not work with multibyte strings if the locale encoding is
482    GB18030 and the character to be searched is a digit.  */
483 # undef strrchr
484 /* Assume strrchr is always declared.  */
485 _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
486                  "in some multibyte locales - "
487                  "use mbsrchr if you care about internationalization");
488 #endif
489
490 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
491    If one is found, overwrite it with a NUL, and advance *STRINGP
492    to point to the next char after it.  Otherwise, set *STRINGP to NULL.
493    If *STRINGP was already NULL, nothing happens.
494    Return the old value of *STRINGP.
495
496    This is a variant of strtok() that is multithread-safe and supports
497    empty fields.
498
499    Caveat: It modifies the original string.
500    Caveat: These functions cannot be used on constant strings.
501    Caveat: The identity of the delimiting character is lost.
502    Caveat: It doesn't work with multibyte strings unless all of the delimiter
503            characters are ASCII characters < 0x30.
504
505    See also strtok_r().  */
506 #if @GNULIB_STRSEP@
507 # if ! @HAVE_STRSEP@
508 _GL_FUNCDECL_SYS (strsep, char *,
509                   (char **restrict __stringp, char const *restrict __delim)
510                   _GL_ARG_NONNULL ((1, 2)));
511 # endif
512 _GL_CXXALIAS_SYS (strsep, char *,
513                   (char **restrict __stringp, char const *restrict __delim));
514 _GL_CXXALIASWARN (strsep);
515 # if defined GNULIB_POSIXCHECK
516 #  undef strsep
517 _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
518                  "in multibyte locales - "
519                  "use mbssep if you care about internationalization");
520 # endif
521 #elif defined GNULIB_POSIXCHECK
522 # undef strsep
523 # if HAVE_RAW_DECL_STRSEP
524 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
525                  "use gnulib module strsep for portability");
526 # endif
527 #endif
528
529 #if @GNULIB_STRSTR@
530 # if @REPLACE_STRSTR@
531 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
532 #   define strstr rpl_strstr
533 #  endif
534 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
535                                   _GL_ATTRIBUTE_PURE
536                                   _GL_ARG_NONNULL ((1, 2)));
537 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
538 # else
539   /* On some systems, this function is defined as an overloaded function:
540        extern "C++" { const char * strstr (const char *, const char *); }
541        extern "C++" { char * strstr (char *, const char *); }  */
542 _GL_CXXALIAS_SYS_CAST2 (strstr,
543                         char *, (const char *haystack, const char *needle),
544                         const char *, (const char *haystack, const char *needle));
545 # endif
546 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
547      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
548 _GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
549 _GL_CXXALIASWARN1 (strstr, const char *,
550                    (const char *haystack, const char *needle));
551 # else
552 _GL_CXXALIASWARN (strstr);
553 # endif
554 #elif defined GNULIB_POSIXCHECK
555 /* strstr() does not work with multibyte strings if the locale encoding is
556    different from UTF-8:
557    POSIX says that it operates on "strings", and "string" in POSIX is defined
558    as a sequence of bytes, not of characters.  */
559 # undef strstr
560 /* Assume strstr is always declared.  */
561 _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
562                  "work correctly on character strings in most "
563                  "multibyte locales - "
564                  "use mbsstr if you care about internationalization, "
565                  "or use strstr if you care about speed");
566 #endif
567
568 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
569    comparison.  */
570 #if @GNULIB_STRCASESTR@
571 # if @REPLACE_STRCASESTR@
572 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
573 #   define strcasestr rpl_strcasestr
574 #  endif
575 _GL_FUNCDECL_RPL (strcasestr, char *,
576                   (const char *haystack, const char *needle)
577                   _GL_ATTRIBUTE_PURE
578                   _GL_ARG_NONNULL ((1, 2)));
579 _GL_CXXALIAS_RPL (strcasestr, char *,
580                   (const char *haystack, const char *needle));
581 # else
582 #  if ! @HAVE_STRCASESTR@
583 _GL_FUNCDECL_SYS (strcasestr, char *,
584                   (const char *haystack, const char *needle)
585                   _GL_ATTRIBUTE_PURE
586                   _GL_ARG_NONNULL ((1, 2)));
587 #  endif
588   /* On some systems, this function is defined as an overloaded function:
589        extern "C++" { const char * strcasestr (const char *, const char *); }
590        extern "C++" { char * strcasestr (char *, const char *); }  */
591 _GL_CXXALIAS_SYS_CAST2 (strcasestr,
592                         char *, (const char *haystack, const char *needle),
593                         const char *, (const char *haystack, const char *needle));
594 # endif
595 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
596      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
597 _GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
598 _GL_CXXALIASWARN1 (strcasestr, const char *,
599                    (const char *haystack, const char *needle));
600 # else
601 _GL_CXXALIASWARN (strcasestr);
602 # endif
603 #elif defined GNULIB_POSIXCHECK
604 /* strcasestr() does not work with multibyte strings:
605    It is a glibc extension, and glibc implements it only for unibyte
606    locales.  */
607 # undef strcasestr
608 # if HAVE_RAW_DECL_STRCASESTR
609 _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
610                  "strings in multibyte locales - "
611                  "use mbscasestr if you care about "
612                  "internationalization, or use c-strcasestr if you want "
613                  "a locale independent function");
614 # endif
615 #endif
616
617 /* Parse S into tokens separated by characters in DELIM.
618    If S is NULL, the saved pointer in SAVE_PTR is used as
619    the next starting point.  For example:
620         char s[] = "-abc-=-def";
621         char *sp;
622         x = strtok_r(s, "-", &sp);      // x = "abc", sp = "=-def"
623         x = strtok_r(NULL, "-=", &sp);  // x = "def", sp = NULL
624         x = strtok_r(NULL, "=", &sp);   // x = NULL
625                 // s = "abc\0-def\0"
626
627    This is a variant of strtok() that is multithread-safe.
628
629    For the POSIX documentation for this function, see:
630    http://www.opengroup.org/susv3xsh/strtok.html
631
632    Caveat: It modifies the original string.
633    Caveat: These functions cannot be used on constant strings.
634    Caveat: The identity of the delimiting character is lost.
635    Caveat: It doesn't work with multibyte strings unless all of the delimiter
636            characters are ASCII characters < 0x30.
637
638    See also strsep().  */
639 #if @GNULIB_STRTOK_R@
640 # if @REPLACE_STRTOK_R@
641 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
642 #   undef strtok_r
643 #   define strtok_r rpl_strtok_r
644 #  endif
645 _GL_FUNCDECL_RPL (strtok_r, char *,
646                   (char *restrict s, char const *restrict delim,
647                    char **restrict save_ptr)
648                   _GL_ARG_NONNULL ((2, 3)));
649 _GL_CXXALIAS_RPL (strtok_r, char *,
650                   (char *restrict s, char const *restrict delim,
651                    char **restrict save_ptr));
652 # else
653 #  if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
654 #   undef strtok_r
655 #  endif
656 #  if ! @HAVE_DECL_STRTOK_R@
657 _GL_FUNCDECL_SYS (strtok_r, char *,
658                   (char *restrict s, char const *restrict delim,
659                    char **restrict save_ptr)
660                   _GL_ARG_NONNULL ((2, 3)));
661 #  endif
662 _GL_CXXALIAS_SYS (strtok_r, char *,
663                   (char *restrict s, char const *restrict delim,
664                    char **restrict save_ptr));
665 # endif
666 _GL_CXXALIASWARN (strtok_r);
667 # if defined GNULIB_POSIXCHECK
668 _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
669                  "strings in multibyte locales - "
670                  "use mbstok_r if you care about internationalization");
671 # endif
672 #elif defined GNULIB_POSIXCHECK
673 # undef strtok_r
674 # if HAVE_RAW_DECL_STRTOK_R
675 _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
676                  "use gnulib module strtok_r for portability");
677 # endif
678 #endif
679
680
681 /* The following functions are not specified by POSIX.  They are gnulib
682    extensions.  */
683
684 #if @GNULIB_MBSLEN@
685 /* Return the number of multibyte characters in the character string STRING.
686    This considers multibyte characters, unlike strlen, which counts bytes.  */
687 # ifdef __MirBSD__  /* MirBSD defines mbslen as a macro.  Override it.  */
688 #  undef mbslen
689 # endif
690 # if @HAVE_MBSLEN@  /* AIX, OSF/1, MirBSD define mbslen already in libc.  */
691 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
692 #   define mbslen rpl_mbslen
693 #  endif
694 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
695 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
696 # else
697 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
698 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
699 # endif
700 _GL_CXXALIASWARN (mbslen);
701 #endif
702
703 #if @GNULIB_MBSNLEN@
704 /* Return the number of multibyte characters in the character string starting
705    at STRING and ending at STRING + LEN.  */
706 _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
707      _GL_ARG_NONNULL ((1));
708 #endif
709
710 #if @GNULIB_MBSCHR@
711 /* Locate the first single-byte character C in the character string STRING,
712    and return a pointer to it.  Return NULL if C is not found in STRING.
713    Unlike strchr(), this function works correctly in multibyte locales with
714    encodings such as GB18030.  */
715 # if defined __hpux
716 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
717 #   define mbschr rpl_mbschr /* avoid collision with HP-UX function */
718 #  endif
719 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
720                                   _GL_ARG_NONNULL ((1)));
721 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
722 # else
723 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
724                                   _GL_ARG_NONNULL ((1)));
725 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
726 # endif
727 _GL_CXXALIASWARN (mbschr);
728 #endif
729
730 #if @GNULIB_MBSRCHR@
731 /* Locate the last single-byte character C in the character string STRING,
732    and return a pointer to it.  Return NULL if C is not found in STRING.
733    Unlike strrchr(), this function works correctly in multibyte locales with
734    encodings such as GB18030.  */
735 # if defined __hpux
736 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
737 #   define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
738 #  endif
739 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
740                                    _GL_ARG_NONNULL ((1)));
741 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
742 # else
743 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
744                                    _GL_ARG_NONNULL ((1)));
745 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
746 # endif
747 _GL_CXXALIASWARN (mbsrchr);
748 #endif
749
750 #if @GNULIB_MBSSTR@
751 /* Find the first occurrence of the character string NEEDLE in the character
752    string HAYSTACK.  Return NULL if NEEDLE is not found in HAYSTACK.
753    Unlike strstr(), this function works correctly in multibyte locales with
754    encodings different from UTF-8.  */
755 _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
756      _GL_ARG_NONNULL ((1, 2));
757 #endif
758
759 #if @GNULIB_MBSCASECMP@
760 /* Compare the character strings S1 and S2, ignoring case, returning less than,
761    equal to or greater than zero if S1 is lexicographically less than, equal to
762    or greater than S2.
763    Note: This function may, in multibyte locales, return 0 for strings of
764    different lengths!
765    Unlike strcasecmp(), this function works correctly in multibyte locales.  */
766 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
767      _GL_ARG_NONNULL ((1, 2));
768 #endif
769
770 #if @GNULIB_MBSNCASECMP@
771 /* Compare the initial segment of the character string S1 consisting of at most
772    N characters with the initial segment of the character string S2 consisting
773    of at most N characters, ignoring case, returning less than, equal to or
774    greater than zero if the initial segment of S1 is lexicographically less
775    than, equal to or greater than the initial segment of S2.
776    Note: This function may, in multibyte locales, return 0 for initial segments
777    of different lengths!
778    Unlike strncasecmp(), this function works correctly in multibyte locales.
779    But beware that N is not a byte count but a character count!  */
780 _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
781      _GL_ARG_NONNULL ((1, 2));
782 #endif
783
784 #if @GNULIB_MBSPCASECMP@
785 /* Compare the initial segment of the character string STRING consisting of
786    at most mbslen (PREFIX) characters with the character string PREFIX,
787    ignoring case.  If the two match, return a pointer to the first byte
788    after this prefix in STRING.  Otherwise, return NULL.
789    Note: This function may, in multibyte locales, return non-NULL if STRING
790    is of smaller length than PREFIX!
791    Unlike strncasecmp(), this function works correctly in multibyte
792    locales.  */
793 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
794      _GL_ARG_NONNULL ((1, 2));
795 #endif
796
797 #if @GNULIB_MBSCASESTR@
798 /* Find the first occurrence of the character string NEEDLE in the character
799    string HAYSTACK, using case-insensitive comparison.
800    Note: This function may, in multibyte locales, return success even if
801    strlen (haystack) < strlen (needle) !
802    Unlike strcasestr(), this function works correctly in multibyte locales.  */
803 _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
804      _GL_ARG_NONNULL ((1, 2));
805 #endif
806
807 #if @GNULIB_MBSCSPN@
808 /* Find the first occurrence in the character string STRING of any character
809    in the character string ACCEPT.  Return the number of bytes from the
810    beginning of the string to this occurrence, or to the end of the string
811    if none exists.
812    Unlike strcspn(), this function works correctly in multibyte locales.  */
813 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
814      _GL_ARG_NONNULL ((1, 2));
815 #endif
816
817 #if @GNULIB_MBSPBRK@
818 /* Find the first occurrence in the character string STRING of any character
819    in the character string ACCEPT.  Return the pointer to it, or NULL if none
820    exists.
821    Unlike strpbrk(), this function works correctly in multibyte locales.  */
822 # if defined __hpux
823 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
824 #   define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
825 #  endif
826 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
827                                    _GL_ARG_NONNULL ((1, 2)));
828 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
829 # else
830 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
831                                    _GL_ARG_NONNULL ((1, 2)));
832 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
833 # endif
834 _GL_CXXALIASWARN (mbspbrk);
835 #endif
836
837 #if @GNULIB_MBSSPN@
838 /* Find the first occurrence in the character string STRING of any character
839    not in the character string REJECT.  Return the number of bytes from the
840    beginning of the string to this occurrence, or to the end of the string
841    if none exists.
842    Unlike strspn(), this function works correctly in multibyte locales.  */
843 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
844      _GL_ARG_NONNULL ((1, 2));
845 #endif
846
847 #if @GNULIB_MBSSEP@
848 /* Search the next delimiter (multibyte character listed in the character
849    string DELIM) starting at the character string *STRINGP.
850    If one is found, overwrite it with a NUL, and advance *STRINGP to point
851    to the next multibyte character after it.  Otherwise, set *STRINGP to NULL.
852    If *STRINGP was already NULL, nothing happens.
853    Return the old value of *STRINGP.
854
855    This is a variant of mbstok_r() that supports empty fields.
856
857    Caveat: It modifies the original string.
858    Caveat: These functions cannot be used on constant strings.
859    Caveat: The identity of the delimiting character is lost.
860
861    See also mbstok_r().  */
862 _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
863      _GL_ARG_NONNULL ((1, 2));
864 #endif
865
866 #if @GNULIB_MBSTOK_R@
867 /* Parse the character string STRING into tokens separated by characters in
868    the character string DELIM.
869    If STRING is NULL, the saved pointer in SAVE_PTR is used as
870    the next starting point.  For example:
871         char s[] = "-abc-=-def";
872         char *sp;
873         x = mbstok_r(s, "-", &sp);      // x = "abc", sp = "=-def"
874         x = mbstok_r(NULL, "-=", &sp);  // x = "def", sp = NULL
875         x = mbstok_r(NULL, "=", &sp);   // x = NULL
876                 // s = "abc\0-def\0"
877
878    Caveat: It modifies the original string.
879    Caveat: These functions cannot be used on constant strings.
880    Caveat: The identity of the delimiting character is lost.
881
882    See also mbssep().  */
883 _GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr)
884      _GL_ARG_NONNULL ((2, 3));
885 #endif
886
887 /* Map any int, typically from errno, into an error message.  */
888 #if @GNULIB_STRERROR@
889 # if @REPLACE_STRERROR@
890 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
891 #   undef strerror
892 #   define strerror rpl_strerror
893 #  endif
894 _GL_FUNCDECL_RPL (strerror, char *, (int));
895 _GL_CXXALIAS_RPL (strerror, char *, (int));
896 # else
897 _GL_CXXALIAS_SYS (strerror, char *, (int));
898 # endif
899 _GL_CXXALIASWARN (strerror);
900 #elif defined GNULIB_POSIXCHECK
901 # undef strerror
902 /* Assume strerror is always declared.  */
903 _GL_WARN_ON_USE (strerror, "strerror is unportable - "
904                  "use gnulib module strerror to guarantee non-NULL result");
905 #endif
906
907 #if @GNULIB_STRSIGNAL@
908 # if @REPLACE_STRSIGNAL@
909 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
910 #   define strsignal rpl_strsignal
911 #  endif
912 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
913 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
914 # else
915 #  if ! @HAVE_DECL_STRSIGNAL@
916 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
917 #  endif
918 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
919    'const char *'.  */
920 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
921 # endif
922 _GL_CXXALIASWARN (strsignal);
923 #elif defined GNULIB_POSIXCHECK
924 # undef strsignal
925 # if HAVE_RAW_DECL_STRSIGNAL
926 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
927                  "use gnulib module strsignal for portability");
928 # endif
929 #endif
930
931 #if @GNULIB_STRVERSCMP@
932 # if !@HAVE_STRVERSCMP@
933 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
934                                    _GL_ARG_NONNULL ((1, 2)));
935 # endif
936 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
937 _GL_CXXALIASWARN (strverscmp);
938 #elif defined GNULIB_POSIXCHECK
939 # undef strverscmp
940 # if HAVE_RAW_DECL_STRVERSCMP
941 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
942                  "use gnulib module strverscmp for portability");
943 # endif
944 #endif
945
946
947 #endif /* _GL_STRING_H */
948 #endif /* _GL_STRING_H */