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