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