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