1
1
/* A GNU-like <string.h>.
3
Copyright (C) 1995-1996, 2001-2010 Free Software Foundation, Inc.
3
Copyright (C) 1995-1996, 2001-2011 Free Software Foundation, Inc.
5
5
This program is free software; you can redistribute it and/or modify
6
6
it under the terms of the GNU Lesser General Public License as published by
16
16
along with this program; if not, write to the Free Software Foundation,
17
17
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
#ifndef _@GUARD_PREFIX@_STRING_H
22
22
@PRAGMA_SYSTEM_HEADER@
25
26
/* The include_next requires a split double-inclusion guard. */
26
27
#@INCLUDE_NEXT@ @NEXT_STRING_H@
29
#ifndef _@GUARD_PREFIX@_STRING_H
30
#define _@GUARD_PREFIX@_STRING_H
31
32
/* NetBSD 5.0 mis-defines NULL. */
32
33
#include <stddef.h>
36
37
# include <wchar.h>
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 */
44
/* The attribute __pure__ was added in gcc 2.96. */
45
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
46
# define __pure__ /* empty */
40
/* The __attribute__ feature is available in gcc versions 2.5 and later.
41
The attribute __pure__ was added in gcc 2.96. */
42
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
43
# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
45
# define _GL_ATTRIBUTE_PURE /* empty */
48
/* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
49
/* But in any case avoid namespace pollution on glibc systems. */
50
#if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
51
&& ! defined __GLIBC__
51
55
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
55
59
/* The definition of _GL_WARN_ON_USE is copied here. */
62
/* Find the index of the least-significant set bit. */
65
_GL_FUNCDECL_SYS (ffsl, int, (long int i));
67
_GL_CXXALIAS_SYS (ffsl, int, (long int i));
68
_GL_CXXALIASWARN (ffsl);
69
#elif defined GNULIB_POSIXCHECK
71
# if HAVE_RAW_DECL_FFSL
72
_GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
77
/* Find the index of the least-significant set bit. */
80
_GL_FUNCDECL_SYS (ffsll, int, (long long int i));
82
_GL_CXXALIAS_SYS (ffsll, int, (long long int i));
83
_GL_CXXALIASWARN (ffsll);
84
#elif defined GNULIB_POSIXCHECK
86
# if HAVE_RAW_DECL_FFSLL
87
_GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
58
92
/* Return the first instance of C within N bytes of S, or NULL. */
59
93
#if @GNULIB_MEMCHR@
60
94
# if @REPLACE_MEMCHR@
62
96
# define memchr rpl_memchr
64
98
_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
65
__attribute__ ((__pure__))
66
100
_GL_ARG_NONNULL ((1)));
67
101
_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
69
103
# if ! @HAVE_MEMCHR@
70
104
_GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
71
__attribute__ ((__pure__))
72
106
_GL_ARG_NONNULL ((1)));
74
108
/* On some systems, this function is defined as an overloaded function:
78
112
void *, (void const *__s, int __c, size_t __n),
79
113
void const *, (void const *__s, int __c, size_t __n));
81
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
115
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
82
116
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
83
117
_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
84
118
_GL_CXXALIASWARN1 (memchr, void const *,
102
136
_GL_FUNCDECL_RPL (memmem, void *,
103
137
(void const *__haystack, size_t __haystack_len,
104
138
void const *__needle, size_t __needle_len)
105
__attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
140
_GL_ARG_NONNULL ((1, 3)));
106
141
_GL_CXXALIAS_RPL (memmem, void *,
107
142
(void const *__haystack, size_t __haystack_len,
108
143
void const *__needle, size_t __needle_len));
111
146
_GL_FUNCDECL_SYS (memmem, void *,
112
147
(void const *__haystack, size_t __haystack_len,
113
148
void const *__needle, size_t __needle_len)
114
__attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
150
_GL_ARG_NONNULL ((1, 3)));
116
152
_GL_CXXALIAS_SYS (memmem, void *,
117
153
(void const *__haystack, size_t __haystack_len,
152
188
#if @GNULIB_MEMRCHR@
153
189
# if ! @HAVE_DECL_MEMRCHR@
154
190
_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
155
__attribute__ ((__pure__))
156
192
_GL_ARG_NONNULL ((1)));
158
194
/* On some systems, this function is defined as an overloaded function:
161
197
_GL_CXXALIAS_SYS_CAST2 (memrchr,
162
198
void *, (void const *, int, size_t),
163
199
void const *, (void const *, int, size_t));
164
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
200
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
165
201
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
166
202
_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t));
167
203
_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t));
182
218
#if @GNULIB_RAWMEMCHR@
183
219
# if ! @HAVE_RAWMEMCHR@
184
220
_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
185
__attribute__ ((__pure__))
186
222
_GL_ARG_NONNULL ((1)));
188
224
/* On some systems, this function is defined as an overloaded function:
191
227
_GL_CXXALIAS_SYS_CAST2 (rawmemchr,
192
228
void *, (void const *__s, int __c_in),
193
229
void const *, (void const *__s, int __c_in));
194
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
230
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
195
231
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
196
232
_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in));
197
233
_GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in));
271
308
/* Find the first occurrence of C in S or the final NUL byte. */
272
309
#if @GNULIB_STRCHRNUL@
273
# if ! @HAVE_STRCHRNUL@
310
# if @REPLACE_STRCHRNUL@
311
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
312
# define strchrnul rpl_strchrnul
314
_GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in)
316
_GL_ARG_NONNULL ((1)));
317
_GL_CXXALIAS_RPL (strchrnul, char *,
318
(const char *str, int ch));
320
# if ! @HAVE_STRCHRNUL@
274
321
_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
275
__attribute__ ((__pure__))
276
323
_GL_ARG_NONNULL ((1)));
278
325
/* On some systems, this function is defined as an overloaded function:
279
326
extern "C++" { const char * std::strchrnul (const char *, int); }
280
327
extern "C++" { char * std::strchrnul (char *, int); } */
281
328
_GL_CXXALIAS_SYS_CAST2 (strchrnul,
282
329
char *, (char const *__s, int __c_in),
283
330
char const *, (char const *__s, int __c_in));
284
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
332
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
285
333
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
286
334
_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
287
335
_GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
306
354
_GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
307
355
_GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
357
# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
358
/* strdup exists as a function and as a macro. Get rid of the macro. */
309
361
# if !(@HAVE_DECL_STRDUP@ || defined strdup)
310
362
_GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
378
430
# define strnlen rpl_strnlen
380
432
_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
381
__attribute__ ((__pure__))
382
434
_GL_ARG_NONNULL ((1)));
383
435
_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
385
437
# if ! @HAVE_DECL_STRNLEN@
386
438
_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
387
__attribute__ ((__pure__))
388
440
_GL_ARG_NONNULL ((1)));
390
442
_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
414
466
#if @GNULIB_STRPBRK@
415
467
# if ! @HAVE_STRPBRK@
416
468
_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
417
__attribute__ ((__pure__))
418
470
_GL_ARG_NONNULL ((1, 2)));
420
472
/* On some systems, this function is defined as an overloaded function:
423
475
_GL_CXXALIAS_SYS_CAST2 (strpbrk,
424
476
char *, (char const *__s, char const *__accept),
425
477
const char *, (char const *__s, char const *__accept));
426
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
478
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
427
479
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
428
480
_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
429
481
_GL_CXXALIASWARN1 (strpbrk, char const *,
514
566
# define strstr rpl_strstr
516
568
_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
517
__attribute__ ((__pure__))
518
570
_GL_ARG_NONNULL ((1, 2)));
519
571
_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
525
577
char *, (const char *haystack, const char *needle),
526
578
const char *, (const char *haystack, const char *needle));
528
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
580
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
529
581
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
530
582
_GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
531
583
_GL_CXXALIASWARN1 (strstr, const char *,
557
609
_GL_FUNCDECL_RPL (strcasestr, char *,
558
610
(const char *haystack, const char *needle)
559
__attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
612
_GL_ARG_NONNULL ((1, 2)));
560
613
_GL_CXXALIAS_RPL (strcasestr, char *,
561
614
(const char *haystack, const char *needle));
563
616
# if ! @HAVE_STRCASESTR@
564
617
_GL_FUNCDECL_SYS (strcasestr, char *,
565
618
(const char *haystack, const char *needle)
566
__attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
620
_GL_ARG_NONNULL ((1, 2)));
568
622
/* On some systems, this function is defined as an overloaded function:
569
623
extern "C++" { const char * strcasestr (const char *, const char *); }
572
626
char *, (const char *haystack, const char *needle),
573
627
const char *, (const char *haystack, const char *needle));
575
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
629
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
576
630
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
577
631
_GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
578
632
_GL_CXXALIASWARN1 (strcasestr, const char *,
712
766
and return a pointer to it. Return NULL if C is not found in STRING.
713
767
Unlike strrchr(), this function works correctly in multibyte locales with
714
768
encodings such as GB18030. */
769
# if defined __hpux || defined __INTERIX
716
770
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
717
# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
771
# define mbsrchr rpl_mbsrchr /* avoid collision with system function */
719
773
_GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
720
774
_GL_ARG_NONNULL ((1)));
764
818
#if @GNULIB_MBSPCASECMP@
765
819
/* Compare the initial segment of the character string STRING consisting of
766
820
at most mbslen (PREFIX) characters with the character string PREFIX,
767
ignoring case, returning less than, equal to or greater than zero if this
768
initial segment is lexicographically less than, equal to or greater than
770
Note: This function may, in multibyte locales, return 0 if STRING is of
771
smaller length than PREFIX!
821
ignoring case. If the two match, return a pointer to the first byte
822
after this prefix in STRING. Otherwise, return NULL.
823
Note: This function may, in multibyte locales, return non-NULL if STRING
824
is of smaller length than PREFIX!
772
825
Unlike strncasecmp(), this function works correctly in multibyte
774
827
_GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
885
938
"use gnulib module strerror to guarantee non-NULL result");
941
/* Map any int, typically from errno, into an error message. Multithread-safe.
942
Uses the POSIX declaration, not the glibc declaration. */
943
#if @GNULIB_STRERROR_R@
944
# if @REPLACE_STRERROR_R@
945
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
947
# define strerror_r rpl_strerror_r
949
_GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)
950
_GL_ARG_NONNULL ((2)));
951
_GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
953
# if !@HAVE_DECL_STRERROR_R@
954
_GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)
955
_GL_ARG_NONNULL ((2)));
957
_GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
959
# if @HAVE_DECL_STRERROR_R@
960
_GL_CXXALIASWARN (strerror_r);
962
#elif defined GNULIB_POSIXCHECK
964
# if HAVE_RAW_DECL_STRERROR_R
965
_GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
966
"use gnulib module strerror_r-posix for portability");
888
970
#if @GNULIB_STRSIGNAL@
889
971
# if @REPLACE_STRSIGNAL@
890
972
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)