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