1
/* A GNU-like <string.h>.
3
Copyright (C) 1995-1996, 2001-2012 Free Software Foundation, Inc.
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 3, or (at your option)
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.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, see <http://www.gnu.org/licenses/>. */
18
#ifndef _@GUARD_PREFIX@_STRING_H
21
@PRAGMA_SYSTEM_HEADER@
25
/* The include_next requires a split double-inclusion guard. */
26
#@INCLUDE_NEXT@ @NEXT_STRING_H@
28
#ifndef _@GUARD_PREFIX@_STRING_H
29
#define _@GUARD_PREFIX@_STRING_H
31
/* NetBSD 5.0 mis-defines NULL. */
34
/* MirBSD defines mbslen as a macro. */
35
#if @GNULIB_MBSLEN@ && defined __MirBSD__
39
/* The __attribute__ feature is available in gcc versions 2.5 and later.
40
The attribute __pure__ was added in gcc 2.96. */
41
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
42
# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
44
# define _GL_ATTRIBUTE_PURE /* empty */
47
/* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
48
/* But in any case avoid namespace pollution on glibc systems. */
49
#if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
50
&& ! defined __GLIBC__
54
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
56
/* The definition of _GL_ARG_NONNULL is copied here. */
58
/* The definition of _GL_WARN_ON_USE is copied here. */
61
/* Find the index of the least-significant set bit. */
64
_GL_FUNCDECL_SYS (ffsl, int, (long int i));
66
_GL_CXXALIAS_SYS (ffsl, int, (long int i));
67
_GL_CXXALIASWARN (ffsl);
68
#elif defined GNULIB_POSIXCHECK
70
# if HAVE_RAW_DECL_FFSL
71
_GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
76
/* Find the index of the least-significant set bit. */
79
_GL_FUNCDECL_SYS (ffsll, int, (long long int i));
81
_GL_CXXALIAS_SYS (ffsll, int, (long long int i));
82
_GL_CXXALIASWARN (ffsll);
83
#elif defined GNULIB_POSIXCHECK
85
# if HAVE_RAW_DECL_FFSLL
86
_GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
91
/* Return the first instance of C within N bytes of S, or NULL. */
94
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
95
# define memchr rpl_memchr
97
_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
99
_GL_ARG_NONNULL ((1)));
100
_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
103
_GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
105
_GL_ARG_NONNULL ((1)));
107
/* On some systems, this function is defined as an overloaded function:
108
extern "C" { const void * std::memchr (const void *, int, size_t); }
109
extern "C++" { void * std::memchr (void *, int, size_t); } */
110
_GL_CXXALIAS_SYS_CAST2 (memchr,
111
void *, (void const *__s, int __c, size_t __n),
112
void const *, (void const *__s, int __c, size_t __n));
114
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
115
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
116
_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
117
_GL_CXXALIASWARN1 (memchr, void const *,
118
(void const *__s, int __c, size_t __n));
120
_GL_CXXALIASWARN (memchr);
122
#elif defined GNULIB_POSIXCHECK
124
/* Assume memchr is always declared. */
125
_GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
126
"use gnulib module memchr for portability" );
129
/* Return the first occurrence of NEEDLE in HAYSTACK. */
131
# if @REPLACE_MEMMEM@
132
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
133
# define memmem rpl_memmem
135
_GL_FUNCDECL_RPL (memmem, void *,
136
(void const *__haystack, size_t __haystack_len,
137
void const *__needle, size_t __needle_len)
139
_GL_ARG_NONNULL ((1, 3)));
140
_GL_CXXALIAS_RPL (memmem, void *,
141
(void const *__haystack, size_t __haystack_len,
142
void const *__needle, size_t __needle_len));
144
# if ! @HAVE_DECL_MEMMEM@
145
_GL_FUNCDECL_SYS (memmem, void *,
146
(void const *__haystack, size_t __haystack_len,
147
void const *__needle, size_t __needle_len)
149
_GL_ARG_NONNULL ((1, 3)));
151
_GL_CXXALIAS_SYS (memmem, void *,
152
(void const *__haystack, size_t __haystack_len,
153
void const *__needle, size_t __needle_len));
155
_GL_CXXALIASWARN (memmem);
156
#elif defined GNULIB_POSIXCHECK
158
# if HAVE_RAW_DECL_MEMMEM
159
_GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
160
"use gnulib module memmem-simple for portability, "
161
"and module memmem for speed" );
165
/* Copy N bytes of SRC to DEST, return pointer to bytes after the
166
last written byte. */
168
# if ! @HAVE_MEMPCPY@
169
_GL_FUNCDECL_SYS (mempcpy, void *,
170
(void *restrict __dest, void const *restrict __src,
172
_GL_ARG_NONNULL ((1, 2)));
174
_GL_CXXALIAS_SYS (mempcpy, void *,
175
(void *restrict __dest, void const *restrict __src,
177
_GL_CXXALIASWARN (mempcpy);
178
#elif defined GNULIB_POSIXCHECK
180
# if HAVE_RAW_DECL_MEMPCPY
181
_GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
182
"use gnulib module mempcpy for portability");
186
/* Search backwards through a block for a byte (specified as an int). */
188
# if ! @HAVE_DECL_MEMRCHR@
189
_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
191
_GL_ARG_NONNULL ((1)));
193
/* On some systems, this function is defined as an overloaded function:
194
extern "C++" { const void * std::memrchr (const void *, int, size_t); }
195
extern "C++" { void * std::memrchr (void *, int, size_t); } */
196
_GL_CXXALIAS_SYS_CAST2 (memrchr,
197
void *, (void const *, int, size_t),
198
void const *, (void const *, int, size_t));
199
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
200
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
201
_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t));
202
_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t));
204
_GL_CXXALIASWARN (memrchr);
206
#elif defined GNULIB_POSIXCHECK
208
# if HAVE_RAW_DECL_MEMRCHR
209
_GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
210
"use gnulib module memrchr for portability");
214
/* Find the first occurrence of C in S. More efficient than
215
memchr(S,C,N), at the expense of undefined behavior if C does not
216
occur within N bytes. */
217
#if @GNULIB_RAWMEMCHR@
218
# if ! @HAVE_RAWMEMCHR@
219
_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
221
_GL_ARG_NONNULL ((1)));
223
/* On some systems, this function is defined as an overloaded function:
224
extern "C++" { const void * std::rawmemchr (const void *, int); }
225
extern "C++" { void * std::rawmemchr (void *, int); } */
226
_GL_CXXALIAS_SYS_CAST2 (rawmemchr,
227
void *, (void const *__s, int __c_in),
228
void const *, (void const *__s, int __c_in));
229
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
230
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
231
_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in));
232
_GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in));
234
_GL_CXXALIASWARN (rawmemchr);
236
#elif defined GNULIB_POSIXCHECK
238
# if HAVE_RAW_DECL_RAWMEMCHR
239
_GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
240
"use gnulib module rawmemchr for portability");
244
/* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
247
_GL_FUNCDECL_SYS (stpcpy, char *,
248
(char *restrict __dst, char const *restrict __src)
249
_GL_ARG_NONNULL ((1, 2)));
251
_GL_CXXALIAS_SYS (stpcpy, char *,
252
(char *restrict __dst, char const *restrict __src));
253
_GL_CXXALIASWARN (stpcpy);
254
#elif defined GNULIB_POSIXCHECK
256
# if HAVE_RAW_DECL_STPCPY
257
_GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
258
"use gnulib module stpcpy for portability");
262
/* Copy no more than N bytes of SRC to DST, returning a pointer past the
263
last non-NUL byte written into DST. */
265
# if @REPLACE_STPNCPY@
266
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
268
# define stpncpy rpl_stpncpy
270
_GL_FUNCDECL_RPL (stpncpy, char *,
271
(char *restrict __dst, char const *restrict __src,
273
_GL_ARG_NONNULL ((1, 2)));
274
_GL_CXXALIAS_RPL (stpncpy, char *,
275
(char *restrict __dst, char const *restrict __src,
278
# if ! @HAVE_STPNCPY@
279
_GL_FUNCDECL_SYS (stpncpy, char *,
280
(char *restrict __dst, char const *restrict __src,
282
_GL_ARG_NONNULL ((1, 2)));
284
_GL_CXXALIAS_SYS (stpncpy, char *,
285
(char *restrict __dst, char const *restrict __src,
288
_GL_CXXALIASWARN (stpncpy);
289
#elif defined GNULIB_POSIXCHECK
291
# if HAVE_RAW_DECL_STPNCPY
292
_GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
293
"use gnulib module stpncpy for portability");
297
#if defined GNULIB_POSIXCHECK
298
/* strchr() does not work with multibyte strings if the locale encoding is
299
GB18030 and the character to be searched is a digit. */
301
/* Assume strchr is always declared. */
302
_GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
303
"in some multibyte locales - "
304
"use mbschr if you care about internationalization");
307
/* Find the first occurrence of C in S or the final NUL byte. */
308
#if @GNULIB_STRCHRNUL@
309
# if @REPLACE_STRCHRNUL@
310
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
311
# define strchrnul rpl_strchrnul
313
_GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in)
315
_GL_ARG_NONNULL ((1)));
316
_GL_CXXALIAS_RPL (strchrnul, char *,
317
(const char *str, int ch));
319
# if ! @HAVE_STRCHRNUL@
320
_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
322
_GL_ARG_NONNULL ((1)));
324
/* On some systems, this function is defined as an overloaded function:
325
extern "C++" { const char * std::strchrnul (const char *, int); }
326
extern "C++" { char * std::strchrnul (char *, int); } */
327
_GL_CXXALIAS_SYS_CAST2 (strchrnul,
328
char *, (char const *__s, int __c_in),
329
char const *, (char const *__s, int __c_in));
331
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
332
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
333
_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
334
_GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
336
_GL_CXXALIASWARN (strchrnul);
338
#elif defined GNULIB_POSIXCHECK
340
# if HAVE_RAW_DECL_STRCHRNUL
341
_GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
342
"use gnulib module strchrnul for portability");
346
/* Duplicate S, returning an identical malloc'd string. */
348
# if @REPLACE_STRDUP@
349
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
351
# define strdup rpl_strdup
353
_GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
354
_GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
356
# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
357
/* strdup exists as a function and as a macro. Get rid of the macro. */
360
# if !(@HAVE_DECL_STRDUP@ || defined strdup)
361
_GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
363
_GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
365
_GL_CXXALIASWARN (strdup);
366
#elif defined GNULIB_POSIXCHECK
368
# if HAVE_RAW_DECL_STRDUP
369
_GL_WARN_ON_USE (strdup, "strdup is unportable - "
370
"use gnulib module strdup for portability");
374
/* Append no more than N characters from SRC onto DEST. */
376
# if @REPLACE_STRNCAT@
377
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
379
# define strncat rpl_strncat
381
_GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n)
382
_GL_ARG_NONNULL ((1, 2)));
383
_GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n));
385
_GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n));
387
_GL_CXXALIASWARN (strncat);
388
#elif defined GNULIB_POSIXCHECK
390
# if HAVE_RAW_DECL_STRNCAT
391
_GL_WARN_ON_USE (strncat, "strncat is unportable - "
392
"use gnulib module strncat for portability");
396
/* Return a newly allocated copy of at most N bytes of STRING. */
398
# if @REPLACE_STRNDUP@
399
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
401
# define strndup rpl_strndup
403
_GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n)
404
_GL_ARG_NONNULL ((1)));
405
_GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n));
407
# if ! @HAVE_DECL_STRNDUP@
408
_GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n)
409
_GL_ARG_NONNULL ((1)));
411
_GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n));
413
_GL_CXXALIASWARN (strndup);
414
#elif defined GNULIB_POSIXCHECK
416
# if HAVE_RAW_DECL_STRNDUP
417
_GL_WARN_ON_USE (strndup, "strndup is unportable - "
418
"use gnulib module strndup for portability");
422
/* Find the length (number of bytes) of STRING, but scan at most
423
MAXLEN bytes. If no '\0' terminator is found in that many bytes,
426
# if @REPLACE_STRNLEN@
427
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
429
# define strnlen rpl_strnlen
431
_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
433
_GL_ARG_NONNULL ((1)));
434
_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
436
# if ! @HAVE_DECL_STRNLEN@
437
_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
439
_GL_ARG_NONNULL ((1)));
441
_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
443
_GL_CXXALIASWARN (strnlen);
444
#elif defined GNULIB_POSIXCHECK
446
# if HAVE_RAW_DECL_STRNLEN
447
_GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
448
"use gnulib module strnlen for portability");
452
#if defined GNULIB_POSIXCHECK
453
/* strcspn() assumes the second argument is a list of single-byte characters.
454
Even in this simple case, it does not work with multibyte strings if the
455
locale encoding is GB18030 and one of the characters to be searched is a
458
/* Assume strcspn is always declared. */
459
_GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
460
"in multibyte locales - "
461
"use mbscspn if you care about internationalization");
464
/* Find the first occurrence in S of any character in ACCEPT. */
466
# if ! @HAVE_STRPBRK@
467
_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
469
_GL_ARG_NONNULL ((1, 2)));
471
/* On some systems, this function is defined as an overloaded function:
472
extern "C" { const char * strpbrk (const char *, const char *); }
473
extern "C++" { char * strpbrk (char *, const char *); } */
474
_GL_CXXALIAS_SYS_CAST2 (strpbrk,
475
char *, (char const *__s, char const *__accept),
476
const char *, (char const *__s, char const *__accept));
477
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
478
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
479
_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
480
_GL_CXXALIASWARN1 (strpbrk, char const *,
481
(char const *__s, char const *__accept));
483
_GL_CXXALIASWARN (strpbrk);
485
# if defined GNULIB_POSIXCHECK
486
/* strpbrk() assumes the second argument is a list of single-byte characters.
487
Even in this simple case, it does not work with multibyte strings if the
488
locale encoding is GB18030 and one of the characters to be searched is a
491
_GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
492
"in multibyte locales - "
493
"use mbspbrk if you care about internationalization");
495
#elif defined GNULIB_POSIXCHECK
497
# if HAVE_RAW_DECL_STRPBRK
498
_GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
499
"use gnulib module strpbrk for portability");
503
#if defined GNULIB_POSIXCHECK
504
/* strspn() assumes the second argument is a list of single-byte characters.
505
Even in this simple case, it cannot work with multibyte strings. */
507
/* Assume strspn is always declared. */
508
_GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
509
"in multibyte locales - "
510
"use mbsspn if you care about internationalization");
513
#if defined GNULIB_POSIXCHECK
514
/* strrchr() does not work with multibyte strings if the locale encoding is
515
GB18030 and the character to be searched is a digit. */
517
/* Assume strrchr is always declared. */
518
_GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
519
"in some multibyte locales - "
520
"use mbsrchr if you care about internationalization");
523
/* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
524
If one is found, overwrite it with a NUL, and advance *STRINGP
525
to point to the next char after it. Otherwise, set *STRINGP to NULL.
526
If *STRINGP was already NULL, nothing happens.
527
Return the old value of *STRINGP.
529
This is a variant of strtok() that is multithread-safe and supports
532
Caveat: It modifies the original string.
533
Caveat: These functions cannot be used on constant strings.
534
Caveat: The identity of the delimiting character is lost.
535
Caveat: It doesn't work with multibyte strings unless all of the delimiter
536
characters are ASCII characters < 0x30.
538
See also strtok_r(). */
541
_GL_FUNCDECL_SYS (strsep, char *,
542
(char **restrict __stringp, char const *restrict __delim)
543
_GL_ARG_NONNULL ((1, 2)));
545
_GL_CXXALIAS_SYS (strsep, char *,
546
(char **restrict __stringp, char const *restrict __delim));
547
_GL_CXXALIASWARN (strsep);
548
# if defined GNULIB_POSIXCHECK
550
_GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
551
"in multibyte locales - "
552
"use mbssep if you care about internationalization");
554
#elif defined GNULIB_POSIXCHECK
556
# if HAVE_RAW_DECL_STRSEP
557
_GL_WARN_ON_USE (strsep, "strsep is unportable - "
558
"use gnulib module strsep for portability");
563
# if @REPLACE_STRSTR@
564
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
565
# define strstr rpl_strstr
567
_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
569
_GL_ARG_NONNULL ((1, 2)));
570
_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
572
/* On some systems, this function is defined as an overloaded function:
573
extern "C++" { const char * strstr (const char *, const char *); }
574
extern "C++" { char * strstr (char *, const char *); } */
575
_GL_CXXALIAS_SYS_CAST2 (strstr,
576
char *, (const char *haystack, const char *needle),
577
const char *, (const char *haystack, const char *needle));
579
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
580
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
581
_GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
582
_GL_CXXALIASWARN1 (strstr, const char *,
583
(const char *haystack, const char *needle));
585
_GL_CXXALIASWARN (strstr);
587
#elif defined GNULIB_POSIXCHECK
588
/* strstr() does not work with multibyte strings if the locale encoding is
589
different from UTF-8:
590
POSIX says that it operates on "strings", and "string" in POSIX is defined
591
as a sequence of bytes, not of characters. */
593
/* Assume strstr is always declared. */
594
_GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
595
"work correctly on character strings in most "
596
"multibyte locales - "
597
"use mbsstr if you care about internationalization, "
598
"or use strstr if you care about speed");
601
/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
603
#if @GNULIB_STRCASESTR@
604
# if @REPLACE_STRCASESTR@
605
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
606
# define strcasestr rpl_strcasestr
608
_GL_FUNCDECL_RPL (strcasestr, char *,
609
(const char *haystack, const char *needle)
611
_GL_ARG_NONNULL ((1, 2)));
612
_GL_CXXALIAS_RPL (strcasestr, char *,
613
(const char *haystack, const char *needle));
615
# if ! @HAVE_STRCASESTR@
616
_GL_FUNCDECL_SYS (strcasestr, char *,
617
(const char *haystack, const char *needle)
619
_GL_ARG_NONNULL ((1, 2)));
621
/* On some systems, this function is defined as an overloaded function:
622
extern "C++" { const char * strcasestr (const char *, const char *); }
623
extern "C++" { char * strcasestr (char *, const char *); } */
624
_GL_CXXALIAS_SYS_CAST2 (strcasestr,
625
char *, (const char *haystack, const char *needle),
626
const char *, (const char *haystack, const char *needle));
628
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
629
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
630
_GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
631
_GL_CXXALIASWARN1 (strcasestr, const char *,
632
(const char *haystack, const char *needle));
634
_GL_CXXALIASWARN (strcasestr);
636
#elif defined GNULIB_POSIXCHECK
637
/* strcasestr() does not work with multibyte strings:
638
It is a glibc extension, and glibc implements it only for unibyte
641
# if HAVE_RAW_DECL_STRCASESTR
642
_GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
643
"strings in multibyte locales - "
644
"use mbscasestr if you care about "
645
"internationalization, or use c-strcasestr if you want "
646
"a locale independent function");
650
/* Parse S into tokens separated by characters in DELIM.
651
If S is NULL, the saved pointer in SAVE_PTR is used as
652
the next starting point. For example:
653
char s[] = "-abc-=-def";
655
x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
656
x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
657
x = strtok_r(NULL, "=", &sp); // x = NULL
660
This is a variant of strtok() that is multithread-safe.
662
For the POSIX documentation for this function, see:
663
http://www.opengroup.org/susv3xsh/strtok.html
665
Caveat: It modifies the original string.
666
Caveat: These functions cannot be used on constant strings.
667
Caveat: The identity of the delimiting character is lost.
668
Caveat: It doesn't work with multibyte strings unless all of the delimiter
669
characters are ASCII characters < 0x30.
671
See also strsep(). */
672
#if @GNULIB_STRTOK_R@
673
# if @REPLACE_STRTOK_R@
674
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
676
# define strtok_r rpl_strtok_r
678
_GL_FUNCDECL_RPL (strtok_r, char *,
679
(char *restrict s, char const *restrict delim,
680
char **restrict save_ptr)
681
_GL_ARG_NONNULL ((2, 3)));
682
_GL_CXXALIAS_RPL (strtok_r, char *,
683
(char *restrict s, char const *restrict delim,
684
char **restrict save_ptr));
686
# if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
689
# if ! @HAVE_DECL_STRTOK_R@
690
_GL_FUNCDECL_SYS (strtok_r, char *,
691
(char *restrict s, char const *restrict delim,
692
char **restrict save_ptr)
693
_GL_ARG_NONNULL ((2, 3)));
695
_GL_CXXALIAS_SYS (strtok_r, char *,
696
(char *restrict s, char const *restrict delim,
697
char **restrict save_ptr));
699
_GL_CXXALIASWARN (strtok_r);
700
# if defined GNULIB_POSIXCHECK
701
_GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
702
"strings in multibyte locales - "
703
"use mbstok_r if you care about internationalization");
705
#elif defined GNULIB_POSIXCHECK
707
# if HAVE_RAW_DECL_STRTOK_R
708
_GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
709
"use gnulib module strtok_r for portability");
714
/* The following functions are not specified by POSIX. They are gnulib
718
/* Return the number of multibyte characters in the character string STRING.
719
This considers multibyte characters, unlike strlen, which counts bytes. */
720
# ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
723
# if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
724
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
725
# define mbslen rpl_mbslen
727
_GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
728
_GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
730
_GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
731
_GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
733
_GL_CXXALIASWARN (mbslen);
737
/* Return the number of multibyte characters in the character string starting
738
at STRING and ending at STRING + LEN. */
739
_GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
740
_GL_ARG_NONNULL ((1));
744
/* Locate the first single-byte character C in the character string STRING,
745
and return a pointer to it. Return NULL if C is not found in STRING.
746
Unlike strchr(), this function works correctly in multibyte locales with
747
encodings such as GB18030. */
749
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
750
# define mbschr rpl_mbschr /* avoid collision with HP-UX function */
752
_GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
753
_GL_ARG_NONNULL ((1)));
754
_GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
756
_GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
757
_GL_ARG_NONNULL ((1)));
758
_GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
760
_GL_CXXALIASWARN (mbschr);
764
/* Locate the last single-byte character C in the character string STRING,
765
and return a pointer to it. Return NULL if C is not found in STRING.
766
Unlike strrchr(), this function works correctly in multibyte locales with
767
encodings such as GB18030. */
768
# if defined __hpux || defined __INTERIX
769
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
770
# define mbsrchr rpl_mbsrchr /* avoid collision with system function */
772
_GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
773
_GL_ARG_NONNULL ((1)));
774
_GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
776
_GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
777
_GL_ARG_NONNULL ((1)));
778
_GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
780
_GL_CXXALIASWARN (mbsrchr);
784
/* Find the first occurrence of the character string NEEDLE in the character
785
string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
786
Unlike strstr(), this function works correctly in multibyte locales with
787
encodings different from UTF-8. */
788
_GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
789
_GL_ARG_NONNULL ((1, 2));
792
#if @GNULIB_MBSCASECMP@
793
/* Compare the character strings S1 and S2, ignoring case, returning less than,
794
equal to or greater than zero if S1 is lexicographically less than, equal to
796
Note: This function may, in multibyte locales, return 0 for strings of
798
Unlike strcasecmp(), this function works correctly in multibyte locales. */
799
_GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
800
_GL_ARG_NONNULL ((1, 2));
803
#if @GNULIB_MBSNCASECMP@
804
/* Compare the initial segment of the character string S1 consisting of at most
805
N characters with the initial segment of the character string S2 consisting
806
of at most N characters, ignoring case, returning less than, equal to or
807
greater than zero if the initial segment of S1 is lexicographically less
808
than, equal to or greater than the initial segment of S2.
809
Note: This function may, in multibyte locales, return 0 for initial segments
810
of different lengths!
811
Unlike strncasecmp(), this function works correctly in multibyte locales.
812
But beware that N is not a byte count but a character count! */
813
_GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
814
_GL_ARG_NONNULL ((1, 2));
817
#if @GNULIB_MBSPCASECMP@
818
/* Compare the initial segment of the character string STRING consisting of
819
at most mbslen (PREFIX) characters with the character string PREFIX,
820
ignoring case. If the two match, return a pointer to the first byte
821
after this prefix in STRING. Otherwise, return NULL.
822
Note: This function may, in multibyte locales, return non-NULL if STRING
823
is of smaller length than PREFIX!
824
Unlike strncasecmp(), this function works correctly in multibyte
826
_GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
827
_GL_ARG_NONNULL ((1, 2));
830
#if @GNULIB_MBSCASESTR@
831
/* Find the first occurrence of the character string NEEDLE in the character
832
string HAYSTACK, using case-insensitive comparison.
833
Note: This function may, in multibyte locales, return success even if
834
strlen (haystack) < strlen (needle) !
835
Unlike strcasestr(), this function works correctly in multibyte locales. */
836
_GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
837
_GL_ARG_NONNULL ((1, 2));
841
/* Find the first occurrence in the character string STRING of any character
842
in the character string ACCEPT. Return the number of bytes from the
843
beginning of the string to this occurrence, or to the end of the string
845
Unlike strcspn(), this function works correctly in multibyte locales. */
846
_GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
847
_GL_ARG_NONNULL ((1, 2));
851
/* Find the first occurrence in the character string STRING of any character
852
in the character string ACCEPT. Return the pointer to it, or NULL if none
854
Unlike strpbrk(), this function works correctly in multibyte locales. */
856
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
857
# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
859
_GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
860
_GL_ARG_NONNULL ((1, 2)));
861
_GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
863
_GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
864
_GL_ARG_NONNULL ((1, 2)));
865
_GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
867
_GL_CXXALIASWARN (mbspbrk);
871
/* Find the first occurrence in the character string STRING of any character
872
not in the character string REJECT. Return the number of bytes from the
873
beginning of the string to this occurrence, or to the end of the string
875
Unlike strspn(), this function works correctly in multibyte locales. */
876
_GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
877
_GL_ARG_NONNULL ((1, 2));
881
/* Search the next delimiter (multibyte character listed in the character
882
string DELIM) starting at the character string *STRINGP.
883
If one is found, overwrite it with a NUL, and advance *STRINGP to point
884
to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
885
If *STRINGP was already NULL, nothing happens.
886
Return the old value of *STRINGP.
888
This is a variant of mbstok_r() that supports empty fields.
890
Caveat: It modifies the original string.
891
Caveat: These functions cannot be used on constant strings.
892
Caveat: The identity of the delimiting character is lost.
894
See also mbstok_r(). */
895
_GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
896
_GL_ARG_NONNULL ((1, 2));
899
#if @GNULIB_MBSTOK_R@
900
/* Parse the character string STRING into tokens separated by characters in
901
the character string DELIM.
902
If STRING is NULL, the saved pointer in SAVE_PTR is used as
903
the next starting point. For example:
904
char s[] = "-abc-=-def";
906
x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
907
x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
908
x = mbstok_r(NULL, "=", &sp); // x = NULL
911
Caveat: It modifies the original string.
912
Caveat: These functions cannot be used on constant strings.
913
Caveat: The identity of the delimiting character is lost.
915
See also mbssep(). */
916
_GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr)
917
_GL_ARG_NONNULL ((2, 3));
920
/* Map any int, typically from errno, into an error message. */
921
#if @GNULIB_STRERROR@
922
# if @REPLACE_STRERROR@
923
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
925
# define strerror rpl_strerror
927
_GL_FUNCDECL_RPL (strerror, char *, (int));
928
_GL_CXXALIAS_RPL (strerror, char *, (int));
930
_GL_CXXALIAS_SYS (strerror, char *, (int));
932
_GL_CXXALIASWARN (strerror);
933
#elif defined GNULIB_POSIXCHECK
935
/* Assume strerror is always declared. */
936
_GL_WARN_ON_USE (strerror, "strerror is unportable - "
937
"use gnulib module strerror to guarantee non-NULL result");
940
/* Map any int, typically from errno, into an error message. Multithread-safe.
941
Uses the POSIX declaration, not the glibc declaration. */
942
#if @GNULIB_STRERROR_R@
943
# if @REPLACE_STRERROR_R@
944
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
946
# define strerror_r rpl_strerror_r
948
_GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)
949
_GL_ARG_NONNULL ((2)));
950
_GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
952
# if !@HAVE_DECL_STRERROR_R@
953
_GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)
954
_GL_ARG_NONNULL ((2)));
956
_GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
958
# if @HAVE_DECL_STRERROR_R@
959
_GL_CXXALIASWARN (strerror_r);
961
#elif defined GNULIB_POSIXCHECK
963
# if HAVE_RAW_DECL_STRERROR_R
964
_GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
965
"use gnulib module strerror_r-posix for portability");
969
#if @GNULIB_STRSIGNAL@
970
# if @REPLACE_STRSIGNAL@
971
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
972
# define strsignal rpl_strsignal
974
_GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
975
_GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
977
# if ! @HAVE_DECL_STRSIGNAL@
978
_GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
980
/* Need to cast, because on Cygwin 1.5.x systems, the return type is
982
_GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
984
_GL_CXXALIASWARN (strsignal);
985
#elif defined GNULIB_POSIXCHECK
987
# if HAVE_RAW_DECL_STRSIGNAL
988
_GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
989
"use gnulib module strsignal for portability");
993
#if @GNULIB_STRVERSCMP@
994
# if !@HAVE_STRVERSCMP@
995
_GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
996
_GL_ARG_NONNULL ((1, 2)));
998
_GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
999
_GL_CXXALIASWARN (strverscmp);
1000
#elif defined GNULIB_POSIXCHECK
1002
# if HAVE_RAW_DECL_STRVERSCMP
1003
_GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
1004
"use gnulib module strverscmp for portability");
1009
#endif /* _@GUARD_PREFIX@_STRING_H */
1010
#endif /* _@GUARD_PREFIX@_STRING_H */