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 General Public License as published by
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. */
62
66
# define memchr rpl_memchr
64
68
_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
65
__attribute__ ((__pure__))
66
70
_GL_ARG_NONNULL ((1)));
67
71
_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
69
73
# if ! @HAVE_MEMCHR@
70
74
_GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
71
__attribute__ ((__pure__))
72
76
_GL_ARG_NONNULL ((1)));
74
78
/* On some systems, this function is defined as an overloaded function:
78
82
void *, (void const *__s, int __c, size_t __n),
79
83
void const *, (void const *__s, int __c, size_t __n));
81
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
85
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
82
86
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
83
87
_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
84
88
_GL_CXXALIASWARN1 (memchr, void const *,
102
106
_GL_FUNCDECL_RPL (memmem, void *,
103
107
(void const *__haystack, size_t __haystack_len,
104
108
void const *__needle, size_t __needle_len)
105
__attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
110
_GL_ARG_NONNULL ((1, 3)));
106
111
_GL_CXXALIAS_RPL (memmem, void *,
107
112
(void const *__haystack, size_t __haystack_len,
108
113
void const *__needle, size_t __needle_len));
111
116
_GL_FUNCDECL_SYS (memmem, void *,
112
117
(void const *__haystack, size_t __haystack_len,
113
118
void const *__needle, size_t __needle_len)
114
__attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
120
_GL_ARG_NONNULL ((1, 3)));
116
122
_GL_CXXALIAS_SYS (memmem, void *,
117
123
(void const *__haystack, size_t __haystack_len,
152
158
#if @GNULIB_MEMRCHR@
153
159
# if ! @HAVE_DECL_MEMRCHR@
154
160
_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
155
__attribute__ ((__pure__))
156
162
_GL_ARG_NONNULL ((1)));
158
164
/* On some systems, this function is defined as an overloaded function:
161
167
_GL_CXXALIAS_SYS_CAST2 (memrchr,
162
168
void *, (void const *, int, size_t),
163
169
void const *, (void const *, int, size_t));
164
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
170
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
165
171
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
166
172
_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t));
167
173
_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t));
182
188
#if @GNULIB_RAWMEMCHR@
183
189
# if ! @HAVE_RAWMEMCHR@
184
190
_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
185
__attribute__ ((__pure__))
186
192
_GL_ARG_NONNULL ((1)));
188
194
/* On some systems, this function is defined as an overloaded function:
191
197
_GL_CXXALIAS_SYS_CAST2 (rawmemchr,
192
198
void *, (void const *__s, int __c_in),
193
199
void const *, (void const *__s, int __c_in));
194
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
200
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
195
201
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
196
202
_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in));
197
203
_GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in));
272
279
#if @GNULIB_STRCHRNUL@
273
280
# if ! @HAVE_STRCHRNUL@
274
281
_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
275
__attribute__ ((__pure__))
276
283
_GL_ARG_NONNULL ((1)));
278
285
/* On some systems, this function is defined as an overloaded function:
281
288
_GL_CXXALIAS_SYS_CAST2 (strchrnul,
282
289
char *, (char const *__s, int __c_in),
283
290
char const *, (char const *__s, int __c_in));
284
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
291
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
285
292
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
286
293
_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
287
294
_GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
306
313
_GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
307
314
_GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
316
# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
317
/* strdup exists as a function and as a macro. Get rid of the macro. */
309
320
# if !(@HAVE_DECL_STRDUP@ || defined strdup)
310
321
_GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
378
389
# define strnlen rpl_strnlen
380
391
_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
381
__attribute__ ((__pure__))
382
393
_GL_ARG_NONNULL ((1)));
383
394
_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
385
396
# if ! @HAVE_DECL_STRNLEN@
386
397
_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
387
__attribute__ ((__pure__))
388
399
_GL_ARG_NONNULL ((1)));
390
401
_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
414
425
#if @GNULIB_STRPBRK@
415
426
# if ! @HAVE_STRPBRK@
416
427
_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
417
__attribute__ ((__pure__))
418
429
_GL_ARG_NONNULL ((1, 2)));
420
431
/* On some systems, this function is defined as an overloaded function:
423
434
_GL_CXXALIAS_SYS_CAST2 (strpbrk,
424
435
char *, (char const *__s, char const *__accept),
425
436
const char *, (char const *__s, char const *__accept));
426
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
437
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
427
438
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
428
439
_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
429
440
_GL_CXXALIASWARN1 (strpbrk, char const *,
514
525
# define strstr rpl_strstr
516
527
_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
517
__attribute__ ((__pure__))
518
529
_GL_ARG_NONNULL ((1, 2)));
519
530
_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
525
536
char *, (const char *haystack, const char *needle),
526
537
const char *, (const char *haystack, const char *needle));
528
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
539
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
529
540
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
530
541
_GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
531
542
_GL_CXXALIASWARN1 (strstr, const char *,
557
568
_GL_FUNCDECL_RPL (strcasestr, char *,
558
569
(const char *haystack, const char *needle)
559
__attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
571
_GL_ARG_NONNULL ((1, 2)));
560
572
_GL_CXXALIAS_RPL (strcasestr, char *,
561
573
(const char *haystack, const char *needle));
563
575
# if ! @HAVE_STRCASESTR@
564
576
_GL_FUNCDECL_SYS (strcasestr, char *,
565
577
(const char *haystack, const char *needle)
566
__attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
579
_GL_ARG_NONNULL ((1, 2)));
568
581
/* On some systems, this function is defined as an overloaded function:
569
582
extern "C++" { const char * strcasestr (const char *, const char *); }
572
585
char *, (const char *haystack, const char *needle),
573
586
const char *, (const char *haystack, const char *needle));
575
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
588
# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
576
589
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
577
590
_GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
578
591
_GL_CXXALIASWARN1 (strcasestr, const char *,
764
777
#if @GNULIB_MBSPCASECMP@
765
778
/* Compare the initial segment of the character string STRING consisting of
766
779
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!
780
ignoring case. If the two match, return a pointer to the first byte
781
after this prefix in STRING. Otherwise, return NULL.
782
Note: This function may, in multibyte locales, return non-NULL if STRING
783
is of smaller length than PREFIX!
772
784
Unlike strncasecmp(), this function works correctly in multibyte
774
786
_GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
885
897
"use gnulib module strerror to guarantee non-NULL result");
900
/* Map any int, typically from errno, into an error message. Multithread-safe.
901
Uses the POSIX declaration, not the glibc declaration. */
902
#if @GNULIB_STRERROR_R@
903
# if @REPLACE_STRERROR_R@
904
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
906
# define strerror_r rpl_strerror_r
908
_GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)
909
_GL_ARG_NONNULL ((2)));
910
_GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
912
# if !@HAVE_DECL_STRERROR_R@
913
_GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)
914
_GL_ARG_NONNULL ((2)));
916
_GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
918
# if @HAVE_DECL_STRERROR_R@
919
_GL_CXXALIASWARN (strerror_r);
921
#elif defined GNULIB_POSIXCHECK
923
# if HAVE_RAW_DECL_STRERROR_R
924
_GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
925
"use gnulib module strerror_r-posix for portability");
888
929
#if @GNULIB_STRSIGNAL@
889
930
# if @REPLACE_STRSIGNAL@
890
931
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)