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