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