Add `%null-pointer' to `(system foreign)'.
[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
44/* The attribute __pure__ was added in gcc 2.96. */
45# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
46# define __pure__ /* empty */
47# endif
48#endif
49
50
1cd4fffc
LC
51/* The definition of _GL_ARG_NONNULL is copied here. */
52
61cd9dc9
LC
53/* The definition of _GL_WARN_ON_USE is copied here. */
54
24d56127
LC
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60
ffca4c22
AW
61/* Return the first instance of C within N bytes of S, or NULL. */
62#if @GNULIB_MEMCHR@
63# if @REPLACE_MEMCHR@
64# define memchr rpl_memchr
65extern void *memchr (void const *__s, int __c, size_t __n)
1cd4fffc 66 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1));
ffca4c22
AW
67# endif
68#elif defined GNULIB_POSIXCHECK
69# undef memchr
61cd9dc9
LC
70/* Assume memchr is always declared. */
71_GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
72 "use gnulib module memchr for portability" );
ffca4c22
AW
73#endif
74
24d56127
LC
75/* Return the first occurrence of NEEDLE in HAYSTACK. */
76#if @GNULIB_MEMMEM@
77# if @REPLACE_MEMMEM@
78# define memmem rpl_memmem
79# endif
80# if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@
81extern void *memmem (void const *__haystack, size_t __haystack_len,
1cd4fffc
LC
82 void const *__needle, size_t __needle_len)
83 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3));
24d56127
LC
84# endif
85#elif defined GNULIB_POSIXCHECK
86# undef memmem
61cd9dc9
LC
87# if HAVE_RAW_DECL_MEMMEM
88_GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
89 "use gnulib module memmem-simple for portability, "
90 "and module memmem for speed" );
91# endif
24d56127
LC
92#endif
93
94/* Copy N bytes of SRC to DEST, return pointer to bytes after the
95 last written byte. */
96#if @GNULIB_MEMPCPY@
97# if ! @HAVE_MEMPCPY@
98extern void *mempcpy (void *restrict __dest, void const *restrict __src,
1cd4fffc
LC
99 size_t __n)
100 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
101# endif
102#elif defined GNULIB_POSIXCHECK
103# undef mempcpy
61cd9dc9
LC
104# if HAVE_RAW_DECL_MEMPCPY
105_GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
106 "use gnulib module mempcpy for portability");
107# endif
24d56127
LC
108#endif
109
110/* Search backwards through a block for a byte (specified as an int). */
111#if @GNULIB_MEMRCHR@
112# if ! @HAVE_DECL_MEMRCHR@
113extern void *memrchr (void const *, int, size_t)
1cd4fffc 114 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1));
24d56127
LC
115# endif
116#elif defined GNULIB_POSIXCHECK
117# undef memrchr
61cd9dc9
LC
118# if HAVE_RAW_DECL_MEMRCHR
119_GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
120 "use gnulib module memrchr for portability");
121# endif
24d56127
LC
122#endif
123
124/* Find the first occurrence of C in S. More efficient than
125 memchr(S,C,N), at the expense of undefined behavior if C does not
126 occur within N bytes. */
127#if @GNULIB_RAWMEMCHR@
128# if ! @HAVE_RAWMEMCHR@
129extern void *rawmemchr (void const *__s, int __c_in)
1cd4fffc 130 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1));
24d56127
LC
131# endif
132#elif defined GNULIB_POSIXCHECK
133# undef rawmemchr
61cd9dc9
LC
134# if HAVE_RAW_DECL_RAWMEMCHR
135_GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
136 "use gnulib module rawmemchr for portability");
137# endif
24d56127
LC
138#endif
139
140/* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
141#if @GNULIB_STPCPY@
142# if ! @HAVE_STPCPY@
1cd4fffc
LC
143extern char *stpcpy (char *restrict __dst, char const *restrict __src)
144 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
145# endif
146#elif defined GNULIB_POSIXCHECK
147# undef stpcpy
61cd9dc9
LC
148# if HAVE_RAW_DECL_STPCPY
149_GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
150 "use gnulib module stpcpy for portability");
151# endif
24d56127
LC
152#endif
153
154/* Copy no more than N bytes of SRC to DST, returning a pointer past the
155 last non-NUL byte written into DST. */
156#if @GNULIB_STPNCPY@
157# if ! @HAVE_STPNCPY@
158# define stpncpy gnu_stpncpy
159extern char *stpncpy (char *restrict __dst, char const *restrict __src,
1cd4fffc
LC
160 size_t __n)
161 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
162# endif
163#elif defined GNULIB_POSIXCHECK
164# undef stpncpy
61cd9dc9
LC
165# if HAVE_RAW_DECL_STPNCPY
166_GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
167 "use gnulib module stpncpy for portability");
168# endif
24d56127
LC
169#endif
170
171#if defined GNULIB_POSIXCHECK
172/* strchr() does not work with multibyte strings if the locale encoding is
173 GB18030 and the character to be searched is a digit. */
174# undef strchr
61cd9dc9
LC
175/* Assume strchr is always declared. */
176_GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
177 "in some multibyte locales - "
178 "use mbschr if you care about internationalization");
24d56127
LC
179#endif
180
181/* Find the first occurrence of C in S or the final NUL byte. */
182#if @GNULIB_STRCHRNUL@
183# if ! @HAVE_STRCHRNUL@
184extern char *strchrnul (char const *__s, int __c_in)
1cd4fffc 185 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1));
24d56127
LC
186# endif
187#elif defined GNULIB_POSIXCHECK
188# undef strchrnul
61cd9dc9
LC
189# if HAVE_RAW_DECL_STRCHRNUL
190_GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
191 "use gnulib module strchrnul for portability");
192# endif
24d56127
LC
193#endif
194
195/* Duplicate S, returning an identical malloc'd string. */
196#if @GNULIB_STRDUP@
197# if @REPLACE_STRDUP@
198# undef strdup
199# define strdup rpl_strdup
200# endif
201# if !(@HAVE_DECL_STRDUP@ || defined strdup) || @REPLACE_STRDUP@
1cd4fffc 202extern char *strdup (char const *__s) _GL_ARG_NONNULL ((1));
24d56127
LC
203# endif
204#elif defined GNULIB_POSIXCHECK
205# undef strdup
61cd9dc9
LC
206# if HAVE_RAW_DECL_STRDUP
207_GL_WARN_ON_USE (strdup, "strdup is unportable - "
208 "use gnulib module strdup for portability");
209# endif
24d56127
LC
210#endif
211
212/* Return a newly allocated copy of at most N bytes of STRING. */
213#if @GNULIB_STRNDUP@
8912421c 214# if @REPLACE_STRNDUP@
24d56127
LC
215# undef strndup
216# define strndup rpl_strndup
217# endif
8912421c 218# if @REPLACE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@
1cd4fffc 219extern char *strndup (char const *__string, size_t __n) _GL_ARG_NONNULL ((1));
24d56127
LC
220# endif
221#elif defined GNULIB_POSIXCHECK
222# undef strndup
61cd9dc9
LC
223# if HAVE_RAW_DECL_STRNDUP
224_GL_WARN_ON_USE (strndup, "strndup is unportable - "
225 "use gnulib module strndup for portability");
226# endif
24d56127
LC
227#endif
228
229/* Find the length (number of bytes) of STRING, but scan at most
230 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
231 return MAXLEN. */
232#if @GNULIB_STRNLEN@
233# if ! @HAVE_DECL_STRNLEN@
234extern size_t strnlen (char const *__string, size_t __maxlen)
1cd4fffc 235 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1));
24d56127
LC
236# endif
237#elif defined GNULIB_POSIXCHECK
238# undef strnlen
61cd9dc9
LC
239# if HAVE_RAW_DECL_STRNLEN
240_GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
241 "use gnulib module strnlen for portability");
242# endif
24d56127
LC
243#endif
244
245#if defined GNULIB_POSIXCHECK
246/* strcspn() assumes the second argument is a list of single-byte characters.
247 Even in this simple case, it does not work with multibyte strings if the
248 locale encoding is GB18030 and one of the characters to be searched is a
249 digit. */
250# undef strcspn
61cd9dc9
LC
251/* Assume strcspn is always declared. */
252_GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
253 "in multibyte locales - "
254 "use mbscspn if you care about internationalization");
24d56127
LC
255#endif
256
257/* Find the first occurrence in S of any character in ACCEPT. */
258#if @GNULIB_STRPBRK@
259# if ! @HAVE_STRPBRK@
260extern char *strpbrk (char const *__s, char const *__accept)
1cd4fffc 261 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2));
24d56127
LC
262# endif
263# if defined GNULIB_POSIXCHECK
264/* strpbrk() assumes the second argument is a list of single-byte characters.
265 Even in this simple case, it does not work with multibyte strings if the
266 locale encoding is GB18030 and one of the characters to be searched is a
267 digit. */
268# undef strpbrk
61cd9dc9
LC
269_GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
270 "in multibyte locales - "
271 "use mbspbrk if you care about internationalization");
24d56127
LC
272# endif
273#elif defined GNULIB_POSIXCHECK
274# undef strpbrk
61cd9dc9
LC
275# if HAVE_RAW_DECL_STRPBRK
276_GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
277 "use gnulib module strpbrk for portability");
278# endif
24d56127
LC
279#endif
280
281#if defined GNULIB_POSIXCHECK
282/* strspn() assumes the second argument is a list of single-byte characters.
283 Even in this simple case, it cannot work with multibyte strings. */
284# undef strspn
61cd9dc9
LC
285/* Assume strspn is always declared. */
286_GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
287 "in multibyte locales - "
288 "use mbsspn if you care about internationalization");
24d56127
LC
289#endif
290
291#if defined GNULIB_POSIXCHECK
292/* strrchr() does not work with multibyte strings if the locale encoding is
293 GB18030 and the character to be searched is a digit. */
294# undef strrchr
61cd9dc9
LC
295/* Assume strrchr is always declared. */
296_GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
297 "in some multibyte locales - "
298 "use mbsrchr if you care about internationalization");
24d56127
LC
299#endif
300
301/* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
302 If one is found, overwrite it with a NUL, and advance *STRINGP
303 to point to the next char after it. Otherwise, set *STRINGP to NULL.
304 If *STRINGP was already NULL, nothing happens.
305 Return the old value of *STRINGP.
306
307 This is a variant of strtok() that is multithread-safe and supports
308 empty fields.
309
310 Caveat: It modifies the original string.
311 Caveat: These functions cannot be used on constant strings.
312 Caveat: The identity of the delimiting character is lost.
313 Caveat: It doesn't work with multibyte strings unless all of the delimiter
314 characters are ASCII characters < 0x30.
315
316 See also strtok_r(). */
317#if @GNULIB_STRSEP@
318# if ! @HAVE_STRSEP@
1cd4fffc
LC
319extern char *strsep (char **restrict __stringp, char const *restrict __delim)
320 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
321# endif
322# if defined GNULIB_POSIXCHECK
323# undef strsep
61cd9dc9
LC
324_GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
325 "in multibyte locales - "
326 "use mbssep if you care about internationalization");
24d56127
LC
327# endif
328#elif defined GNULIB_POSIXCHECK
329# undef strsep
61cd9dc9
LC
330# if HAVE_RAW_DECL_STRSEP
331_GL_WARN_ON_USE (strsep, "strsep is unportable - "
332 "use gnulib module strsep for portability");
333# endif
24d56127
LC
334#endif
335
336#if @GNULIB_STRSTR@
337# if @REPLACE_STRSTR@
338# define strstr rpl_strstr
1cd4fffc
LC
339extern char *strstr (const char *haystack, const char *needle)
340 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2));
24d56127
LC
341# endif
342#elif defined GNULIB_POSIXCHECK
343/* strstr() does not work with multibyte strings if the locale encoding is
344 different from UTF-8:
345 POSIX says that it operates on "strings", and "string" in POSIX is defined
346 as a sequence of bytes, not of characters. */
347# undef strstr
61cd9dc9
LC
348/* Assume strstr is always declared. */
349_GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
350 "work correctly on character strings in most "
351 "multibyte locales - "
352 "use mbsstr if you care about internationalization, "
353 "or use strstr if you care about speed");
24d56127
LC
354#endif
355
356/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
357 comparison. */
358#if @GNULIB_STRCASESTR@
359# if @REPLACE_STRCASESTR@
360# define strcasestr rpl_strcasestr
361# endif
362# if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@
363extern char *strcasestr (const char *haystack, const char *needle)
1cd4fffc 364 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2));
24d56127
LC
365# endif
366#elif defined GNULIB_POSIXCHECK
367/* strcasestr() does not work with multibyte strings:
368 It is a glibc extension, and glibc implements it only for unibyte
369 locales. */
370# undef strcasestr
61cd9dc9
LC
371# if HAVE_RAW_DECL_STRCASESTR
372_GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
373 "strings in multibyte locales - "
374 "use mbscasestr if you care about "
375 "internationalization, or use c-strcasestr if you want "
376 "a locale independent function");
377# endif
24d56127
LC
378#endif
379
380/* Parse S into tokens separated by characters in DELIM.
381 If S is NULL, the saved pointer in SAVE_PTR is used as
382 the next starting point. For example:
1cd4fffc
LC
383 char s[] = "-abc-=-def";
384 char *sp;
385 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
386 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
387 x = strtok_r(NULL, "=", &sp); // x = NULL
388 // s = "abc\0-def\0"
24d56127
LC
389
390 This is a variant of strtok() that is multithread-safe.
391
392 For the POSIX documentation for this function, see:
393 http://www.opengroup.org/susv3xsh/strtok.html
394
395 Caveat: It modifies the original string.
396 Caveat: These functions cannot be used on constant strings.
397 Caveat: The identity of the delimiting character is lost.
398 Caveat: It doesn't work with multibyte strings unless all of the delimiter
399 characters are ASCII characters < 0x30.
400
401 See also strsep(). */
402#if @GNULIB_STRTOK_R@
8912421c
LC
403# if @REPLACE_STRTOK_R@
404# undef strtok_r
405# define strtok_r rpl_strtok_r
61cd9dc9 406# elif @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
8912421c
LC
407# undef strtok_r
408# endif
409# if ! @HAVE_DECL_STRTOK_R@ || @REPLACE_STRTOK_R@
24d56127 410extern char *strtok_r (char *restrict s, char const *restrict delim,
1cd4fffc
LC
411 char **restrict save_ptr)
412 _GL_ARG_NONNULL ((2, 3));
24d56127
LC
413# endif
414# if defined GNULIB_POSIXCHECK
61cd9dc9
LC
415_GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
416 "strings in multibyte locales - "
417 "use mbstok_r if you care about internationalization");
24d56127
LC
418# endif
419#elif defined GNULIB_POSIXCHECK
420# undef strtok_r
61cd9dc9
LC
421# if HAVE_RAW_DECL_STRTOK_R
422_GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
423 "use gnulib module strtok_r for portability");
424# endif
24d56127
LC
425#endif
426
427
428/* The following functions are not specified by POSIX. They are gnulib
429 extensions. */
430
431#if @GNULIB_MBSLEN@
432/* Return the number of multibyte characters in the character string STRING.
433 This considers multibyte characters, unlike strlen, which counts bytes. */
61cd9dc9
LC
434# ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
435# undef mbslen
436# endif
437# if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
438# define mbslen rpl_mbslen
439# endif
1cd4fffc 440extern size_t mbslen (const char *string) _GL_ARG_NONNULL ((1));
24d56127
LC
441#endif
442
443#if @GNULIB_MBSNLEN@
444/* Return the number of multibyte characters in the character string starting
445 at STRING and ending at STRING + LEN. */
1cd4fffc 446extern size_t mbsnlen (const char *string, size_t len) _GL_ARG_NONNULL ((1));
24d56127
LC
447#endif
448
449#if @GNULIB_MBSCHR@
450/* Locate the first single-byte character C in the character string STRING,
451 and return a pointer to it. Return NULL if C is not found in STRING.
452 Unlike strchr(), this function works correctly in multibyte locales with
453 encodings such as GB18030. */
454# define mbschr rpl_mbschr /* avoid collision with HP-UX function */
1cd4fffc 455extern char * mbschr (const char *string, int c) _GL_ARG_NONNULL ((1));
24d56127
LC
456#endif
457
458#if @GNULIB_MBSRCHR@
459/* Locate the last single-byte character C in the character string STRING,
460 and return a pointer to it. Return NULL if C is not found in STRING.
461 Unlike strrchr(), this function works correctly in multibyte locales with
462 encodings such as GB18030. */
463# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
1cd4fffc 464extern char * mbsrchr (const char *string, int c) _GL_ARG_NONNULL ((1));
24d56127
LC
465#endif
466
467#if @GNULIB_MBSSTR@
468/* Find the first occurrence of the character string NEEDLE in the character
469 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
470 Unlike strstr(), this function works correctly in multibyte locales with
471 encodings different from UTF-8. */
1cd4fffc
LC
472extern char * mbsstr (const char *haystack, const char *needle)
473 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
474#endif
475
476#if @GNULIB_MBSCASECMP@
477/* Compare the character strings S1 and S2, ignoring case, returning less than,
478 equal to or greater than zero if S1 is lexicographically less than, equal to
479 or greater than S2.
480 Note: This function may, in multibyte locales, return 0 for strings of
481 different lengths!
482 Unlike strcasecmp(), this function works correctly in multibyte locales. */
1cd4fffc
LC
483extern int mbscasecmp (const char *s1, const char *s2)
484 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
485#endif
486
487#if @GNULIB_MBSNCASECMP@
488/* Compare the initial segment of the character string S1 consisting of at most
489 N characters with the initial segment of the character string S2 consisting
490 of at most N characters, ignoring case, returning less than, equal to or
491 greater than zero if the initial segment of S1 is lexicographically less
492 than, equal to or greater than the initial segment of S2.
493 Note: This function may, in multibyte locales, return 0 for initial segments
494 of different lengths!
495 Unlike strncasecmp(), this function works correctly in multibyte locales.
496 But beware that N is not a byte count but a character count! */
1cd4fffc
LC
497extern int mbsncasecmp (const char *s1, const char *s2, size_t n)
498 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
499#endif
500
501#if @GNULIB_MBSPCASECMP@
502/* Compare the initial segment of the character string STRING consisting of
503 at most mbslen (PREFIX) characters with the character string PREFIX,
504 ignoring case, returning less than, equal to or greater than zero if this
505 initial segment is lexicographically less than, equal to or greater than
506 PREFIX.
507 Note: This function may, in multibyte locales, return 0 if STRING is of
508 smaller length than PREFIX!
509 Unlike strncasecmp(), this function works correctly in multibyte
510 locales. */
1cd4fffc
LC
511extern char * mbspcasecmp (const char *string, const char *prefix)
512 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
513#endif
514
515#if @GNULIB_MBSCASESTR@
516/* Find the first occurrence of the character string NEEDLE in the character
517 string HAYSTACK, using case-insensitive comparison.
518 Note: This function may, in multibyte locales, return success even if
519 strlen (haystack) < strlen (needle) !
520 Unlike strcasestr(), this function works correctly in multibyte locales. */
1cd4fffc
LC
521extern char * mbscasestr (const char *haystack, const char *needle)
522 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
523#endif
524
525#if @GNULIB_MBSCSPN@
526/* Find the first occurrence in the character string STRING of any character
527 in the character string ACCEPT. Return the number of bytes from the
528 beginning of the string to this occurrence, or to the end of the string
529 if none exists.
530 Unlike strcspn(), this function works correctly in multibyte locales. */
1cd4fffc
LC
531extern size_t mbscspn (const char *string, const char *accept)
532 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
533#endif
534
535#if @GNULIB_MBSPBRK@
536/* Find the first occurrence in the character string STRING of any character
537 in the character string ACCEPT. Return the pointer to it, or NULL if none
538 exists.
539 Unlike strpbrk(), this function works correctly in multibyte locales. */
540# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
1cd4fffc
LC
541extern char * mbspbrk (const char *string, const char *accept)
542 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
543#endif
544
545#if @GNULIB_MBSSPN@
546/* Find the first occurrence in the character string STRING of any character
547 not in the character string REJECT. Return the number of bytes from the
548 beginning of the string to this occurrence, or to the end of the string
549 if none exists.
550 Unlike strspn(), this function works correctly in multibyte locales. */
1cd4fffc
LC
551extern size_t mbsspn (const char *string, const char *reject)
552 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
553#endif
554
555#if @GNULIB_MBSSEP@
556/* Search the next delimiter (multibyte character listed in the character
557 string DELIM) starting at the character string *STRINGP.
558 If one is found, overwrite it with a NUL, and advance *STRINGP to point
559 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
560 If *STRINGP was already NULL, nothing happens.
561 Return the old value of *STRINGP.
562
563 This is a variant of mbstok_r() that supports empty fields.
564
565 Caveat: It modifies the original string.
566 Caveat: These functions cannot be used on constant strings.
567 Caveat: The identity of the delimiting character is lost.
568
569 See also mbstok_r(). */
1cd4fffc
LC
570extern char * mbssep (char **stringp, const char *delim)
571 _GL_ARG_NONNULL ((1, 2));
24d56127
LC
572#endif
573
574#if @GNULIB_MBSTOK_R@
575/* Parse the character string STRING into tokens separated by characters in
576 the character string DELIM.
577 If STRING is NULL, the saved pointer in SAVE_PTR is used as
578 the next starting point. For example:
1cd4fffc
LC
579 char s[] = "-abc-=-def";
580 char *sp;
581 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
582 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
583 x = mbstok_r(NULL, "=", &sp); // x = NULL
584 // s = "abc\0-def\0"
24d56127
LC
585
586 Caveat: It modifies the original string.
587 Caveat: These functions cannot be used on constant strings.
588 Caveat: The identity of the delimiting character is lost.
589
590 See also mbssep(). */
1cd4fffc
LC
591extern char * mbstok_r (char *string, const char *delim, char **save_ptr)
592 _GL_ARG_NONNULL ((2, 3));
24d56127
LC
593#endif
594
595/* Map any int, typically from errno, into an error message. */
596#if @GNULIB_STRERROR@
597# if @REPLACE_STRERROR@
598# undef strerror
599# define strerror rpl_strerror
600extern char *strerror (int);
601# endif
602#elif defined GNULIB_POSIXCHECK
603# undef strerror
61cd9dc9
LC
604/* Assume strerror is always declared. */
605_GL_WARN_ON_USE (strerror, "strerror is unportable - "
606 "use gnulib module strerror to guarantee non-NULL result");
24d56127
LC
607#endif
608
609#if @GNULIB_STRSIGNAL@
610# if @REPLACE_STRSIGNAL@
611# define strsignal rpl_strsignal
612# endif
613# if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@
614extern char *strsignal (int __sig);
615# endif
616#elif defined GNULIB_POSIXCHECK
617# undef strsignal
61cd9dc9
LC
618# if HAVE_RAW_DECL_STRSIGNAL
619_GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
620 "use gnulib module strsignal for portability");
621# endif
24d56127
LC
622#endif
623
624#if @GNULIB_STRVERSCMP@
625# if !@HAVE_STRVERSCMP@
1cd4fffc 626extern int strverscmp (const char *, const char *) _GL_ARG_NONNULL ((1, 2));
24d56127
LC
627# endif
628#elif defined GNULIB_POSIXCHECK
629# undef strverscmp
61cd9dc9
LC
630# if HAVE_RAW_DECL_STRVERSCMP
631_GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
632 "use gnulib module strverscmp for portability");
633# endif
24d56127
LC
634#endif
635
636
637#ifdef __cplusplus
638}
639#endif
640
641#endif /* _GL_STRING_H */
642#endif /* _GL_STRING_H */