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