1*fd82c4c4Schristos /* This file is automatically generated.  DO NOT EDIT! */
2*fd82c4c4Schristos /* Generated from: NetBSD: mknative-gdb,v 1.12 2020/09/17 16:54:31 christos Exp  */
3*fd82c4c4Schristos /* Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp  */
4*fd82c4c4Schristos 
5*fd82c4c4Schristos /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
6*fd82c4c4Schristos /* A GNU-like <string.h>.
7*fd82c4c4Schristos 
8*fd82c4c4Schristos    Copyright (C) 1995-1996, 2001-2020 Free Software Foundation, Inc.
9*fd82c4c4Schristos 
10*fd82c4c4Schristos    This program is free software; you can redistribute it and/or modify
11*fd82c4c4Schristos    it under the terms of the GNU General Public License as published by
12*fd82c4c4Schristos    the Free Software Foundation; either version 3, or (at your option)
13*fd82c4c4Schristos    any later version.
14*fd82c4c4Schristos 
15*fd82c4c4Schristos    This program is distributed in the hope that it will be useful,
16*fd82c4c4Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
17*fd82c4c4Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*fd82c4c4Schristos    GNU General Public License for more details.
19*fd82c4c4Schristos 
20*fd82c4c4Schristos    You should have received a copy of the GNU General Public License
21*fd82c4c4Schristos    along with this program; if not, see <https://www.gnu.org/licenses/>.  */
22*fd82c4c4Schristos 
23*fd82c4c4Schristos #if __GNUC__ >= 3
24*fd82c4c4Schristos #pragma GCC system_header
25*fd82c4c4Schristos #endif
26*fd82c4c4Schristos 
27*fd82c4c4Schristos 
28*fd82c4c4Schristos #if defined _GL_ALREADY_INCLUDING_STRING_H
29*fd82c4c4Schristos /* Special invocation convention:
30*fd82c4c4Schristos    - On OS X/NetBSD we have a sequence of nested includes
31*fd82c4c4Schristos        <string.h> -> <strings.h> -> "string.h"
32*fd82c4c4Schristos      In this situation system _chk variants due to -D_FORTIFY_SOURCE
33*fd82c4c4Schristos      might be used after any replacements defined here.  */
34*fd82c4c4Schristos 
35*fd82c4c4Schristos #include_next <string.h>
36*fd82c4c4Schristos 
37*fd82c4c4Schristos #else
38*fd82c4c4Schristos /* Normal invocation convention.  */
39*fd82c4c4Schristos 
40*fd82c4c4Schristos #ifndef _GL_STRING_H
41*fd82c4c4Schristos 
42*fd82c4c4Schristos #define _GL_ALREADY_INCLUDING_STRING_H
43*fd82c4c4Schristos 
44*fd82c4c4Schristos /* The include_next requires a split double-inclusion guard.  */
45*fd82c4c4Schristos #include_next <string.h>
46*fd82c4c4Schristos 
47*fd82c4c4Schristos #undef _GL_ALREADY_INCLUDING_STRING_H
48*fd82c4c4Schristos 
49*fd82c4c4Schristos #ifndef _GL_STRING_H
50*fd82c4c4Schristos #define _GL_STRING_H
51*fd82c4c4Schristos 
52*fd82c4c4Schristos /* NetBSD 5.0 mis-defines NULL.  */
53*fd82c4c4Schristos #include <stddef.h>
54*fd82c4c4Schristos 
55*fd82c4c4Schristos /* MirBSD defines mbslen as a macro.  */
56*fd82c4c4Schristos #if 0 && defined __MirBSD__
57*fd82c4c4Schristos # include <wchar.h>
58*fd82c4c4Schristos #endif
59*fd82c4c4Schristos 
60*fd82c4c4Schristos /* The __attribute__ feature is available in gcc versions 2.5 and later.
61*fd82c4c4Schristos    The attribute __pure__ was added in gcc 2.96.  */
62*fd82c4c4Schristos #ifndef _GL_ATTRIBUTE_PURE
63*fd82c4c4Schristos # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
64*fd82c4c4Schristos #  define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
65*fd82c4c4Schristos # else
66*fd82c4c4Schristos #  define _GL_ATTRIBUTE_PURE /* empty */
67*fd82c4c4Schristos # endif
68*fd82c4c4Schristos #endif
69*fd82c4c4Schristos 
70*fd82c4c4Schristos /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>.  */
71*fd82c4c4Schristos /* But in any case avoid namespace pollution on glibc systems.  */
72*fd82c4c4Schristos #if (0 || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
73*fd82c4c4Schristos     && ! defined __GLIBC__
74*fd82c4c4Schristos # include <unistd.h>
75*fd82c4c4Schristos #endif
76*fd82c4c4Schristos 
77*fd82c4c4Schristos /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
78*fd82c4c4Schristos /* C++ compatible function declaration macros.
79*fd82c4c4Schristos    Copyright (C) 2010-2020 Free Software Foundation, Inc.
80*fd82c4c4Schristos 
81*fd82c4c4Schristos    This program is free software: you can redistribute it and/or modify it
82*fd82c4c4Schristos    under the terms of the GNU General Public License as published
83*fd82c4c4Schristos    by the Free Software Foundation; either version 3 of the License, or
84*fd82c4c4Schristos    (at your option) any later version.
85*fd82c4c4Schristos 
86*fd82c4c4Schristos    This program is distributed in the hope that it will be useful,
87*fd82c4c4Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
88*fd82c4c4Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
89*fd82c4c4Schristos    General Public License for more details.
90*fd82c4c4Schristos 
91*fd82c4c4Schristos    You should have received a copy of the GNU General Public License
92*fd82c4c4Schristos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
93*fd82c4c4Schristos 
94*fd82c4c4Schristos #ifndef _GL_CXXDEFS_H
95*fd82c4c4Schristos #define _GL_CXXDEFS_H
96*fd82c4c4Schristos 
97*fd82c4c4Schristos /* Begin/end the GNULIB_NAMESPACE namespace.  */
98*fd82c4c4Schristos #if defined __cplusplus && defined GNULIB_NAMESPACE
99*fd82c4c4Schristos # define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
100*fd82c4c4Schristos # define _GL_END_NAMESPACE }
101*fd82c4c4Schristos #else
102*fd82c4c4Schristos # define _GL_BEGIN_NAMESPACE
103*fd82c4c4Schristos # define _GL_END_NAMESPACE
104*fd82c4c4Schristos #endif
105*fd82c4c4Schristos 
106*fd82c4c4Schristos /* The three most frequent use cases of these macros are:
107*fd82c4c4Schristos 
108*fd82c4c4Schristos    * For providing a substitute for a function that is missing on some
109*fd82c4c4Schristos      platforms, but is declared and works fine on the platforms on which
110*fd82c4c4Schristos      it exists:
111*fd82c4c4Schristos 
112*fd82c4c4Schristos        #if @GNULIB_FOO@
113*fd82c4c4Schristos        # if !@HAVE_FOO@
114*fd82c4c4Schristos        _GL_FUNCDECL_SYS (foo, ...);
115*fd82c4c4Schristos        # endif
116*fd82c4c4Schristos        _GL_CXXALIAS_SYS (foo, ...);
117*fd82c4c4Schristos        _GL_CXXALIASWARN (foo);
118*fd82c4c4Schristos        #elif defined GNULIB_POSIXCHECK
119*fd82c4c4Schristos        ...
120*fd82c4c4Schristos        #endif
121*fd82c4c4Schristos 
122*fd82c4c4Schristos    * For providing a replacement for a function that exists on all platforms,
123*fd82c4c4Schristos      but is broken/insufficient and needs to be replaced on some platforms:
124*fd82c4c4Schristos 
125*fd82c4c4Schristos        #if @GNULIB_FOO@
126*fd82c4c4Schristos        # if @REPLACE_FOO@
127*fd82c4c4Schristos        #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
128*fd82c4c4Schristos        #   undef foo
129*fd82c4c4Schristos        #   define foo rpl_foo
130*fd82c4c4Schristos        #  endif
131*fd82c4c4Schristos        _GL_FUNCDECL_RPL (foo, ...);
132*fd82c4c4Schristos        _GL_CXXALIAS_RPL (foo, ...);
133*fd82c4c4Schristos        # else
134*fd82c4c4Schristos        _GL_CXXALIAS_SYS (foo, ...);
135*fd82c4c4Schristos        # endif
136*fd82c4c4Schristos        _GL_CXXALIASWARN (foo);
137*fd82c4c4Schristos        #elif defined GNULIB_POSIXCHECK
138*fd82c4c4Schristos        ...
139*fd82c4c4Schristos        #endif
140*fd82c4c4Schristos 
141*fd82c4c4Schristos    * For providing a replacement for a function that exists on some platforms
142*fd82c4c4Schristos      but is broken/insufficient and needs to be replaced on some of them and
143*fd82c4c4Schristos      is additionally either missing or undeclared on some other platforms:
144*fd82c4c4Schristos 
145*fd82c4c4Schristos        #if @GNULIB_FOO@
146*fd82c4c4Schristos        # if @REPLACE_FOO@
147*fd82c4c4Schristos        #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
148*fd82c4c4Schristos        #   undef foo
149*fd82c4c4Schristos        #   define foo rpl_foo
150*fd82c4c4Schristos        #  endif
151*fd82c4c4Schristos        _GL_FUNCDECL_RPL (foo, ...);
152*fd82c4c4Schristos        _GL_CXXALIAS_RPL (foo, ...);
153*fd82c4c4Schristos        # else
154*fd82c4c4Schristos        #  if !@HAVE_FOO@   or   if !@HAVE_DECL_FOO@
155*fd82c4c4Schristos        _GL_FUNCDECL_SYS (foo, ...);
156*fd82c4c4Schristos        #  endif
157*fd82c4c4Schristos        _GL_CXXALIAS_SYS (foo, ...);
158*fd82c4c4Schristos        # endif
159*fd82c4c4Schristos        _GL_CXXALIASWARN (foo);
160*fd82c4c4Schristos        #elif defined GNULIB_POSIXCHECK
161*fd82c4c4Schristos        ...
162*fd82c4c4Schristos        #endif
163*fd82c4c4Schristos */
164*fd82c4c4Schristos 
165*fd82c4c4Schristos /* _GL_EXTERN_C declaration;
166*fd82c4c4Schristos    performs the declaration with C linkage.  */
167*fd82c4c4Schristos #if defined __cplusplus
168*fd82c4c4Schristos # define _GL_EXTERN_C extern "C"
169*fd82c4c4Schristos #else
170*fd82c4c4Schristos # define _GL_EXTERN_C extern
171*fd82c4c4Schristos #endif
172*fd82c4c4Schristos 
173*fd82c4c4Schristos /* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
174*fd82c4c4Schristos    declares a replacement function, named rpl_func, with the given prototype,
175*fd82c4c4Schristos    consisting of return type, parameters, and attributes.
176*fd82c4c4Schristos    Example:
177*fd82c4c4Schristos      _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
178*fd82c4c4Schristos                                   _GL_ARG_NONNULL ((1)));
179*fd82c4c4Schristos  */
180*fd82c4c4Schristos #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
181*fd82c4c4Schristos   _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
182*fd82c4c4Schristos #define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
183*fd82c4c4Schristos   _GL_EXTERN_C rettype rpl_func parameters_and_attributes
184*fd82c4c4Schristos 
185*fd82c4c4Schristos /* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
186*fd82c4c4Schristos    declares the system function, named func, with the given prototype,
187*fd82c4c4Schristos    consisting of return type, parameters, and attributes.
188*fd82c4c4Schristos    Example:
189*fd82c4c4Schristos      _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
190*fd82c4c4Schristos                                   _GL_ARG_NONNULL ((1)));
191*fd82c4c4Schristos  */
192*fd82c4c4Schristos #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
193*fd82c4c4Schristos   _GL_EXTERN_C rettype func parameters_and_attributes
194*fd82c4c4Schristos 
195*fd82c4c4Schristos /* _GL_CXXALIAS_RPL (func, rettype, parameters);
196*fd82c4c4Schristos    declares a C++ alias called GNULIB_NAMESPACE::func
197*fd82c4c4Schristos    that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
198*fd82c4c4Schristos    Example:
199*fd82c4c4Schristos      _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
200*fd82c4c4Schristos 
201*fd82c4c4Schristos    Wrapping rpl_func in an object with an inline conversion operator
202*fd82c4c4Schristos    avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
203*fd82c4c4Schristos    actually used in the program.  */
204*fd82c4c4Schristos #define _GL_CXXALIAS_RPL(func,rettype,parameters) \
205*fd82c4c4Schristos   _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
206*fd82c4c4Schristos #if defined __cplusplus && defined GNULIB_NAMESPACE
207*fd82c4c4Schristos # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
208*fd82c4c4Schristos     namespace GNULIB_NAMESPACE                                \
209*fd82c4c4Schristos     {                                                         \
210*fd82c4c4Schristos       static const struct _gl_ ## func ## _wrapper            \
211*fd82c4c4Schristos       {                                                       \
212*fd82c4c4Schristos         typedef rettype (*type) parameters;                   \
213*fd82c4c4Schristos                                                               \
214*fd82c4c4Schristos         inline operator type () const                         \
215*fd82c4c4Schristos         {                                                     \
216*fd82c4c4Schristos           return ::rpl_func;                                  \
217*fd82c4c4Schristos         }                                                     \
218*fd82c4c4Schristos       } func = {};                                            \
219*fd82c4c4Schristos     }                                                         \
220*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
221*fd82c4c4Schristos #else
222*fd82c4c4Schristos # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
223*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
224*fd82c4c4Schristos #endif
225*fd82c4c4Schristos 
226*fd82c4c4Schristos /* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
227*fd82c4c4Schristos    is like  _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
228*fd82c4c4Schristos    except that the C function rpl_func may have a slightly different
229*fd82c4c4Schristos    declaration.  A cast is used to silence the "invalid conversion" error
230*fd82c4c4Schristos    that would otherwise occur.  */
231*fd82c4c4Schristos #if defined __cplusplus && defined GNULIB_NAMESPACE
232*fd82c4c4Schristos # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
233*fd82c4c4Schristos     namespace GNULIB_NAMESPACE                                     \
234*fd82c4c4Schristos     {                                                              \
235*fd82c4c4Schristos       static const struct _gl_ ## func ## _wrapper                 \
236*fd82c4c4Schristos       {                                                            \
237*fd82c4c4Schristos         typedef rettype (*type) parameters;                        \
238*fd82c4c4Schristos                                                                    \
239*fd82c4c4Schristos         inline operator type () const                              \
240*fd82c4c4Schristos         {                                                          \
241*fd82c4c4Schristos           return reinterpret_cast<type>(::rpl_func);               \
242*fd82c4c4Schristos         }                                                          \
243*fd82c4c4Schristos       } func = {};                                                 \
244*fd82c4c4Schristos     }                                                              \
245*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
246*fd82c4c4Schristos #else
247*fd82c4c4Schristos # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
248*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
249*fd82c4c4Schristos #endif
250*fd82c4c4Schristos 
251*fd82c4c4Schristos /* _GL_CXXALIAS_SYS (func, rettype, parameters);
252*fd82c4c4Schristos    declares a C++ alias called GNULIB_NAMESPACE::func
253*fd82c4c4Schristos    that redirects to the system provided function func, if GNULIB_NAMESPACE
254*fd82c4c4Schristos    is defined.
255*fd82c4c4Schristos    Example:
256*fd82c4c4Schristos      _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
257*fd82c4c4Schristos 
258*fd82c4c4Schristos    Wrapping func in an object with an inline conversion operator
259*fd82c4c4Schristos    avoids a reference to func unless GNULIB_NAMESPACE::func is
260*fd82c4c4Schristos    actually used in the program.  */
261*fd82c4c4Schristos #if defined __cplusplus && defined GNULIB_NAMESPACE
262*fd82c4c4Schristos # define _GL_CXXALIAS_SYS(func,rettype,parameters)            \
263*fd82c4c4Schristos     namespace GNULIB_NAMESPACE                                \
264*fd82c4c4Schristos     {                                                         \
265*fd82c4c4Schristos       static const struct _gl_ ## func ## _wrapper            \
266*fd82c4c4Schristos       {                                                       \
267*fd82c4c4Schristos         typedef rettype (*type) parameters;                   \
268*fd82c4c4Schristos                                                               \
269*fd82c4c4Schristos         inline operator type () const                         \
270*fd82c4c4Schristos         {                                                     \
271*fd82c4c4Schristos           return ::func;                                      \
272*fd82c4c4Schristos         }                                                     \
273*fd82c4c4Schristos       } func = {};                                            \
274*fd82c4c4Schristos     }                                                         \
275*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
276*fd82c4c4Schristos #else
277*fd82c4c4Schristos # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
278*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
279*fd82c4c4Schristos #endif
280*fd82c4c4Schristos 
281*fd82c4c4Schristos /* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
282*fd82c4c4Schristos    is like  _GL_CXXALIAS_SYS (func, rettype, parameters);
283*fd82c4c4Schristos    except that the C function func may have a slightly different declaration.
284*fd82c4c4Schristos    A cast is used to silence the "invalid conversion" error that would
285*fd82c4c4Schristos    otherwise occur.  */
286*fd82c4c4Schristos #if defined __cplusplus && defined GNULIB_NAMESPACE
287*fd82c4c4Schristos # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
288*fd82c4c4Schristos     namespace GNULIB_NAMESPACE                          \
289*fd82c4c4Schristos     {                                                   \
290*fd82c4c4Schristos       static const struct _gl_ ## func ## _wrapper      \
291*fd82c4c4Schristos       {                                                 \
292*fd82c4c4Schristos         typedef rettype (*type) parameters;             \
293*fd82c4c4Schristos                                                         \
294*fd82c4c4Schristos         inline operator type () const                   \
295*fd82c4c4Schristos         {                                               \
296*fd82c4c4Schristos           return reinterpret_cast<type>(::func);        \
297*fd82c4c4Schristos         }                                               \
298*fd82c4c4Schristos       } func = {};                                      \
299*fd82c4c4Schristos     }                                                   \
300*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
301*fd82c4c4Schristos #else
302*fd82c4c4Schristos # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
303*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
304*fd82c4c4Schristos #endif
305*fd82c4c4Schristos 
306*fd82c4c4Schristos /* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
307*fd82c4c4Schristos    is like  _GL_CXXALIAS_SYS (func, rettype, parameters);
308*fd82c4c4Schristos    except that the C function is picked among a set of overloaded functions,
309*fd82c4c4Schristos    namely the one with rettype2 and parameters2.  Two consecutive casts
310*fd82c4c4Schristos    are used to silence the "cannot find a match" and "invalid conversion"
311*fd82c4c4Schristos    errors that would otherwise occur.  */
312*fd82c4c4Schristos #if defined __cplusplus && defined GNULIB_NAMESPACE
313*fd82c4c4Schristos   /* The outer cast must be a reinterpret_cast.
314*fd82c4c4Schristos      The inner cast: When the function is defined as a set of overloaded
315*fd82c4c4Schristos      functions, it works as a static_cast<>, choosing the designated variant.
316*fd82c4c4Schristos      When the function is defined as a single variant, it works as a
317*fd82c4c4Schristos      reinterpret_cast<>. The parenthesized cast syntax works both ways.  */
318*fd82c4c4Schristos # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
319*fd82c4c4Schristos     namespace GNULIB_NAMESPACE                                                \
320*fd82c4c4Schristos     {                                                                         \
321*fd82c4c4Schristos       static const struct _gl_ ## func ## _wrapper                            \
322*fd82c4c4Schristos       {                                                                       \
323*fd82c4c4Schristos         typedef rettype (*type) parameters;                                   \
324*fd82c4c4Schristos                                                                               \
325*fd82c4c4Schristos         inline operator type () const                                         \
326*fd82c4c4Schristos         {                                                                     \
327*fd82c4c4Schristos           return reinterpret_cast<type>((rettype2 (*) parameters2)(::func));  \
328*fd82c4c4Schristos         }                                                                     \
329*fd82c4c4Schristos       } func = {};                                                            \
330*fd82c4c4Schristos     }                                                                         \
331*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
332*fd82c4c4Schristos #else
333*fd82c4c4Schristos # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
334*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
335*fd82c4c4Schristos #endif
336*fd82c4c4Schristos 
337*fd82c4c4Schristos /* _GL_CXXALIASWARN (func);
338*fd82c4c4Schristos    causes a warning to be emitted when ::func is used but not when
339*fd82c4c4Schristos    GNULIB_NAMESPACE::func is used.  func must be defined without overloaded
340*fd82c4c4Schristos    variants.  */
341*fd82c4c4Schristos #if defined __cplusplus && defined GNULIB_NAMESPACE
342*fd82c4c4Schristos # define _GL_CXXALIASWARN(func) \
343*fd82c4c4Schristos    _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
344*fd82c4c4Schristos # define _GL_CXXALIASWARN_1(func,namespace) \
345*fd82c4c4Schristos    _GL_CXXALIASWARN_2 (func, namespace)
346*fd82c4c4Schristos /* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
347*fd82c4c4Schristos    we enable the warning only when not optimizing.  */
348*fd82c4c4Schristos # if !__OPTIMIZE__
349*fd82c4c4Schristos #  define _GL_CXXALIASWARN_2(func,namespace) \
350*fd82c4c4Schristos     _GL_WARN_ON_USE (func, \
351*fd82c4c4Schristos                      "The symbol ::" #func " refers to the system function. " \
352*fd82c4c4Schristos                      "Use " #namespace "::" #func " instead.")
353*fd82c4c4Schristos # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
354*fd82c4c4Schristos #  define _GL_CXXALIASWARN_2(func,namespace) \
355*fd82c4c4Schristos      extern __typeof__ (func) func
356*fd82c4c4Schristos # else
357*fd82c4c4Schristos #  define _GL_CXXALIASWARN_2(func,namespace) \
358*fd82c4c4Schristos      _GL_EXTERN_C int _gl_cxxalias_dummy
359*fd82c4c4Schristos # endif
360*fd82c4c4Schristos #else
361*fd82c4c4Schristos # define _GL_CXXALIASWARN(func) \
362*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
363*fd82c4c4Schristos #endif
364*fd82c4c4Schristos 
365*fd82c4c4Schristos /* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
366*fd82c4c4Schristos    causes a warning to be emitted when the given overloaded variant of ::func
367*fd82c4c4Schristos    is used but not when GNULIB_NAMESPACE::func is used.  */
368*fd82c4c4Schristos #if defined __cplusplus && defined GNULIB_NAMESPACE
369*fd82c4c4Schristos # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
370*fd82c4c4Schristos    _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
371*fd82c4c4Schristos                         GNULIB_NAMESPACE)
372*fd82c4c4Schristos # define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
373*fd82c4c4Schristos    _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
374*fd82c4c4Schristos /* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
375*fd82c4c4Schristos    we enable the warning only when not optimizing.  */
376*fd82c4c4Schristos # if !__OPTIMIZE__
377*fd82c4c4Schristos #  define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
378*fd82c4c4Schristos     _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
379*fd82c4c4Schristos                          "The symbol ::" #func " refers to the system function. " \
380*fd82c4c4Schristos                          "Use " #namespace "::" #func " instead.")
381*fd82c4c4Schristos # else
382*fd82c4c4Schristos #  define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
383*fd82c4c4Schristos      _GL_EXTERN_C int _gl_cxxalias_dummy
384*fd82c4c4Schristos # endif
385*fd82c4c4Schristos #else
386*fd82c4c4Schristos # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
387*fd82c4c4Schristos     _GL_EXTERN_C int _gl_cxxalias_dummy
388*fd82c4c4Schristos #endif
389*fd82c4c4Schristos 
390*fd82c4c4Schristos #endif /* _GL_CXXDEFS_H */
391*fd82c4c4Schristos 
392*fd82c4c4Schristos /* The definition of _GL_ARG_NONNULL is copied here.  */
393*fd82c4c4Schristos /* A C macro for declaring that specific arguments must not be NULL.
394*fd82c4c4Schristos    Copyright (C) 2009-2020 Free Software Foundation, Inc.
395*fd82c4c4Schristos 
396*fd82c4c4Schristos    This program is free software: you can redistribute it and/or modify it
397*fd82c4c4Schristos    under the terms of the GNU General Public License as published
398*fd82c4c4Schristos    by the Free Software Foundation; either version 3 of the License, or
399*fd82c4c4Schristos    (at your option) any later version.
400*fd82c4c4Schristos 
401*fd82c4c4Schristos    This program is distributed in the hope that it will be useful,
402*fd82c4c4Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
403*fd82c4c4Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
404*fd82c4c4Schristos    General Public License for more details.
405*fd82c4c4Schristos 
406*fd82c4c4Schristos    You should have received a copy of the GNU General Public License
407*fd82c4c4Schristos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
408*fd82c4c4Schristos 
409*fd82c4c4Schristos /* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
410*fd82c4c4Schristos    that the values passed as arguments n, ..., m must be non-NULL pointers.
411*fd82c4c4Schristos    n = 1 stands for the first argument, n = 2 for the second argument etc.  */
412*fd82c4c4Schristos #ifndef _GL_ARG_NONNULL
413*fd82c4c4Schristos # if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
414*fd82c4c4Schristos #  define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
415*fd82c4c4Schristos # else
416*fd82c4c4Schristos #  define _GL_ARG_NONNULL(params)
417*fd82c4c4Schristos # endif
418*fd82c4c4Schristos #endif
419*fd82c4c4Schristos 
420*fd82c4c4Schristos /* The definition of _GL_WARN_ON_USE is copied here.  */
421*fd82c4c4Schristos /* A C macro for emitting warnings if a function is used.
422*fd82c4c4Schristos    Copyright (C) 2010-2020 Free Software Foundation, Inc.
423*fd82c4c4Schristos 
424*fd82c4c4Schristos    This program is free software: you can redistribute it and/or modify it
425*fd82c4c4Schristos    under the terms of the GNU General Public License as published
426*fd82c4c4Schristos    by the Free Software Foundation; either version 3 of the License, or
427*fd82c4c4Schristos    (at your option) any later version.
428*fd82c4c4Schristos 
429*fd82c4c4Schristos    This program is distributed in the hope that it will be useful,
430*fd82c4c4Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
431*fd82c4c4Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
432*fd82c4c4Schristos    General Public License for more details.
433*fd82c4c4Schristos 
434*fd82c4c4Schristos    You should have received a copy of the GNU General Public License
435*fd82c4c4Schristos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
436*fd82c4c4Schristos 
437*fd82c4c4Schristos /* _GL_WARN_ON_USE (function, "literal string") issues a declaration
438*fd82c4c4Schristos    for FUNCTION which will then trigger a compiler warning containing
439*fd82c4c4Schristos    the text of "literal string" anywhere that function is called, if
440*fd82c4c4Schristos    supported by the compiler.  If the compiler does not support this
441*fd82c4c4Schristos    feature, the macro expands to an unused extern declaration.
442*fd82c4c4Schristos 
443*fd82c4c4Schristos    _GL_WARN_ON_USE_ATTRIBUTE ("literal string") expands to the
444*fd82c4c4Schristos    attribute used in _GL_WARN_ON_USE.  If the compiler does not support
445*fd82c4c4Schristos    this feature, it expands to empty.
446*fd82c4c4Schristos 
447*fd82c4c4Schristos    These macros are useful for marking a function as a potential
448*fd82c4c4Schristos    portability trap, with the intent that "literal string" include
449*fd82c4c4Schristos    instructions on the replacement function that should be used
450*fd82c4c4Schristos    instead.
451*fd82c4c4Schristos    _GL_WARN_ON_USE is for functions with 'extern' linkage.
452*fd82c4c4Schristos    _GL_WARN_ON_USE_ATTRIBUTE is for functions with 'static' or 'inline'
453*fd82c4c4Schristos    linkage.
454*fd82c4c4Schristos 
455*fd82c4c4Schristos    However, one of the reasons that a function is a portability trap is
456*fd82c4c4Schristos    if it has the wrong signature.  Declaring FUNCTION with a different
457*fd82c4c4Schristos    signature in C is a compilation error, so this macro must use the
458*fd82c4c4Schristos    same type as any existing declaration so that programs that avoid
459*fd82c4c4Schristos    the problematic FUNCTION do not fail to compile merely because they
460*fd82c4c4Schristos    included a header that poisoned the function.  But this implies that
461*fd82c4c4Schristos    _GL_WARN_ON_USE is only safe to use if FUNCTION is known to already
462*fd82c4c4Schristos    have a declaration.  Use of this macro implies that there must not
463*fd82c4c4Schristos    be any other macro hiding the declaration of FUNCTION; but
464*fd82c4c4Schristos    undefining FUNCTION first is part of the poisoning process anyway
465*fd82c4c4Schristos    (although for symbols that are provided only via a macro, the result
466*fd82c4c4Schristos    is a compilation error rather than a warning containing
467*fd82c4c4Schristos    "literal string").  Also note that in C++, it is only safe to use if
468*fd82c4c4Schristos    FUNCTION has no overloads.
469*fd82c4c4Schristos 
470*fd82c4c4Schristos    For an example, it is possible to poison 'getline' by:
471*fd82c4c4Schristos    - adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
472*fd82c4c4Schristos      [getline]) in configure.ac, which potentially defines
473*fd82c4c4Schristos      HAVE_RAW_DECL_GETLINE
474*fd82c4c4Schristos    - adding this code to a header that wraps the system <stdio.h>:
475*fd82c4c4Schristos      #undef getline
476*fd82c4c4Schristos      #if HAVE_RAW_DECL_GETLINE
477*fd82c4c4Schristos      _GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
478*fd82c4c4Schristos        "not universally present; use the gnulib module getline");
479*fd82c4c4Schristos      #endif
480*fd82c4c4Schristos 
481*fd82c4c4Schristos    It is not possible to directly poison global variables.  But it is
482*fd82c4c4Schristos    possible to write a wrapper accessor function, and poison that
483*fd82c4c4Schristos    (less common usage, like &environ, will cause a compilation error
484*fd82c4c4Schristos    rather than issue the nice warning, but the end result of informing
485*fd82c4c4Schristos    the developer about their portability problem is still achieved):
486*fd82c4c4Schristos      #if HAVE_RAW_DECL_ENVIRON
487*fd82c4c4Schristos      static char ***
488*fd82c4c4Schristos      rpl_environ (void) { return &environ; }
489*fd82c4c4Schristos      _GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
490*fd82c4c4Schristos      # undef environ
491*fd82c4c4Schristos      # define environ (*rpl_environ ())
492*fd82c4c4Schristos      #endif
493*fd82c4c4Schristos    or better (avoiding contradictory use of 'static' and 'extern'):
494*fd82c4c4Schristos      #if HAVE_RAW_DECL_ENVIRON
495*fd82c4c4Schristos      static char ***
496*fd82c4c4Schristos      _GL_WARN_ON_USE_ATTRIBUTE ("environ is not always properly declared")
497*fd82c4c4Schristos      rpl_environ (void) { return &environ; }
498*fd82c4c4Schristos      # undef environ
499*fd82c4c4Schristos      # define environ (*rpl_environ ())
500*fd82c4c4Schristos      #endif
501*fd82c4c4Schristos    */
502*fd82c4c4Schristos #ifndef _GL_WARN_ON_USE
503*fd82c4c4Schristos 
504*fd82c4c4Schristos # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
505*fd82c4c4Schristos /* A compiler attribute is available in gcc versions 4.3.0 and later.  */
506*fd82c4c4Schristos #  define _GL_WARN_ON_USE(function, message) \
507*fd82c4c4Schristos extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
508*fd82c4c4Schristos #  define _GL_WARN_ON_USE_ATTRIBUTE(message) \
509*fd82c4c4Schristos   __attribute__ ((__warning__ (message)))
510*fd82c4c4Schristos # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
511*fd82c4c4Schristos /* Verify the existence of the function.  */
512*fd82c4c4Schristos #  define _GL_WARN_ON_USE(function, message) \
513*fd82c4c4Schristos extern __typeof__ (function) function
514*fd82c4c4Schristos #  define _GL_WARN_ON_USE_ATTRIBUTE(message)
515*fd82c4c4Schristos # else /* Unsupported.  */
516*fd82c4c4Schristos #  define _GL_WARN_ON_USE(function, message) \
517*fd82c4c4Schristos _GL_WARN_EXTERN_C int _gl_warn_on_use
518*fd82c4c4Schristos #  define _GL_WARN_ON_USE_ATTRIBUTE(message)
519*fd82c4c4Schristos # endif
520*fd82c4c4Schristos #endif
521*fd82c4c4Schristos 
522*fd82c4c4Schristos /* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
523*fd82c4c4Schristos    is like _GL_WARN_ON_USE (function, "string"), except that in C++ mode the
524*fd82c4c4Schristos    function is declared with the given prototype, consisting of return type,
525*fd82c4c4Schristos    parameters, and attributes.
526*fd82c4c4Schristos    This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
527*fd82c4c4Schristos    not work in this case.  */
528*fd82c4c4Schristos #ifndef _GL_WARN_ON_USE_CXX
529*fd82c4c4Schristos # if !defined __cplusplus
530*fd82c4c4Schristos #  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
531*fd82c4c4Schristos      _GL_WARN_ON_USE (function, msg)
532*fd82c4c4Schristos # else
533*fd82c4c4Schristos #  if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
534*fd82c4c4Schristos #   define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
535*fd82c4c4Schristos extern rettype function parameters_and_attributes \
536*fd82c4c4Schristos      __attribute__ ((__warning__ (msg)))
537*fd82c4c4Schristos #  elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
538*fd82c4c4Schristos /* Verify the existence of the function.  */
539*fd82c4c4Schristos #   define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
540*fd82c4c4Schristos extern rettype function parameters_and_attributes
541*fd82c4c4Schristos #  else /* Unsupported.  */
542*fd82c4c4Schristos #   define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
543*fd82c4c4Schristos _GL_WARN_EXTERN_C int _gl_warn_on_use
544*fd82c4c4Schristos #  endif
545*fd82c4c4Schristos # endif
546*fd82c4c4Schristos #endif
547*fd82c4c4Schristos 
548*fd82c4c4Schristos /* _GL_WARN_EXTERN_C declaration;
549*fd82c4c4Schristos    performs the declaration with C linkage.  */
550*fd82c4c4Schristos #ifndef _GL_WARN_EXTERN_C
551*fd82c4c4Schristos # if defined __cplusplus
552*fd82c4c4Schristos #  define _GL_WARN_EXTERN_C extern "C"
553*fd82c4c4Schristos # else
554*fd82c4c4Schristos #  define _GL_WARN_EXTERN_C extern
555*fd82c4c4Schristos # endif
556*fd82c4c4Schristos #endif
557*fd82c4c4Schristos 
558*fd82c4c4Schristos 
559*fd82c4c4Schristos /* Clear a block of memory.  The compiler will not delete a call to
560*fd82c4c4Schristos    this function, even if the block is dead after the call.  */
561*fd82c4c4Schristos #if 0
562*fd82c4c4Schristos # if ! 1
563*fd82c4c4Schristos _GL_FUNCDECL_SYS (explicit_bzero, void,
564*fd82c4c4Schristos                   (void *__dest, size_t __n) _GL_ARG_NONNULL ((1)));
565*fd82c4c4Schristos # endif
566*fd82c4c4Schristos _GL_CXXALIAS_SYS (explicit_bzero, void, (void *__dest, size_t __n));
567*fd82c4c4Schristos _GL_CXXALIASWARN (explicit_bzero);
568*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
569*fd82c4c4Schristos # undef explicit_bzero
570*fd82c4c4Schristos # if HAVE_RAW_DECL_EXPLICIT_BZERO
571*fd82c4c4Schristos _GL_WARN_ON_USE (explicit_bzero, "explicit_bzero is unportable - "
572*fd82c4c4Schristos                  "use gnulib module explicit_bzero for portability");
573*fd82c4c4Schristos # endif
574*fd82c4c4Schristos #endif
575*fd82c4c4Schristos 
576*fd82c4c4Schristos /* Find the index of the least-significant set bit.  */
577*fd82c4c4Schristos #if 0
578*fd82c4c4Schristos # if !1
579*fd82c4c4Schristos _GL_FUNCDECL_SYS (ffsl, int, (long int i));
580*fd82c4c4Schristos # endif
581*fd82c4c4Schristos _GL_CXXALIAS_SYS (ffsl, int, (long int i));
582*fd82c4c4Schristos _GL_CXXALIASWARN (ffsl);
583*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
584*fd82c4c4Schristos # undef ffsl
585*fd82c4c4Schristos # if HAVE_RAW_DECL_FFSL
586*fd82c4c4Schristos _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
587*fd82c4c4Schristos # endif
588*fd82c4c4Schristos #endif
589*fd82c4c4Schristos 
590*fd82c4c4Schristos 
591*fd82c4c4Schristos /* Find the index of the least-significant set bit.  */
592*fd82c4c4Schristos #if 0
593*fd82c4c4Schristos # if !1
594*fd82c4c4Schristos _GL_FUNCDECL_SYS (ffsll, int, (long long int i));
595*fd82c4c4Schristos # endif
596*fd82c4c4Schristos _GL_CXXALIAS_SYS (ffsll, int, (long long int i));
597*fd82c4c4Schristos _GL_CXXALIASWARN (ffsll);
598*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
599*fd82c4c4Schristos # undef ffsll
600*fd82c4c4Schristos # if HAVE_RAW_DECL_FFSLL
601*fd82c4c4Schristos _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
602*fd82c4c4Schristos # endif
603*fd82c4c4Schristos #endif
604*fd82c4c4Schristos 
605*fd82c4c4Schristos 
606*fd82c4c4Schristos /* Return the first instance of C within N bytes of S, or NULL.  */
607*fd82c4c4Schristos #if 1
608*fd82c4c4Schristos # if 0
609*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
610*fd82c4c4Schristos #   define memchr rpl_memchr
611*fd82c4c4Schristos #  endif
612*fd82c4c4Schristos _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
613*fd82c4c4Schristos                                   _GL_ATTRIBUTE_PURE
614*fd82c4c4Schristos                                   _GL_ARG_NONNULL ((1)));
615*fd82c4c4Schristos _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
616*fd82c4c4Schristos # else
617*fd82c4c4Schristos #  if ! 1
618*fd82c4c4Schristos _GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
619*fd82c4c4Schristos                                   _GL_ATTRIBUTE_PURE
620*fd82c4c4Schristos                                   _GL_ARG_NONNULL ((1)));
621*fd82c4c4Schristos #  endif
622*fd82c4c4Schristos   /* On some systems, this function is defined as an overloaded function:
623*fd82c4c4Schristos        extern "C" { const void * std::memchr (const void *, int, size_t); }
624*fd82c4c4Schristos        extern "C++" { void * std::memchr (void *, int, size_t); }  */
625*fd82c4c4Schristos _GL_CXXALIAS_SYS_CAST2 (memchr,
626*fd82c4c4Schristos                         void *, (void const *__s, int __c, size_t __n),
627*fd82c4c4Schristos                         void const *, (void const *__s, int __c, size_t __n));
628*fd82c4c4Schristos # endif
629*fd82c4c4Schristos # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
630*fd82c4c4Schristos      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
631*fd82c4c4Schristos _GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
632*fd82c4c4Schristos _GL_CXXALIASWARN1 (memchr, void const *,
633*fd82c4c4Schristos                    (void const *__s, int __c, size_t __n));
634*fd82c4c4Schristos # elif __GLIBC__ >= 2
635*fd82c4c4Schristos _GL_CXXALIASWARN (memchr);
636*fd82c4c4Schristos # endif
637*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
638*fd82c4c4Schristos # undef memchr
639*fd82c4c4Schristos /* Assume memchr is always declared.  */
640*fd82c4c4Schristos _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
641*fd82c4c4Schristos                  "use gnulib module memchr for portability" );
642*fd82c4c4Schristos #endif
643*fd82c4c4Schristos 
644*fd82c4c4Schristos /* Return the first occurrence of NEEDLE in HAYSTACK.  */
645*fd82c4c4Schristos #if 1
646*fd82c4c4Schristos # if 1
647*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
648*fd82c4c4Schristos #   define memmem rpl_memmem
649*fd82c4c4Schristos #  endif
650*fd82c4c4Schristos _GL_FUNCDECL_RPL (memmem, void *,
651*fd82c4c4Schristos                   (void const *__haystack, size_t __haystack_len,
652*fd82c4c4Schristos                    void const *__needle, size_t __needle_len)
653*fd82c4c4Schristos                   _GL_ATTRIBUTE_PURE
654*fd82c4c4Schristos                   _GL_ARG_NONNULL ((1, 3)));
655*fd82c4c4Schristos _GL_CXXALIAS_RPL (memmem, void *,
656*fd82c4c4Schristos                   (void const *__haystack, size_t __haystack_len,
657*fd82c4c4Schristos                    void const *__needle, size_t __needle_len));
658*fd82c4c4Schristos # else
659*fd82c4c4Schristos #  if ! 1
660*fd82c4c4Schristos _GL_FUNCDECL_SYS (memmem, void *,
661*fd82c4c4Schristos                   (void const *__haystack, size_t __haystack_len,
662*fd82c4c4Schristos                    void const *__needle, size_t __needle_len)
663*fd82c4c4Schristos                   _GL_ATTRIBUTE_PURE
664*fd82c4c4Schristos                   _GL_ARG_NONNULL ((1, 3)));
665*fd82c4c4Schristos #  endif
666*fd82c4c4Schristos _GL_CXXALIAS_SYS (memmem, void *,
667*fd82c4c4Schristos                   (void const *__haystack, size_t __haystack_len,
668*fd82c4c4Schristos                    void const *__needle, size_t __needle_len));
669*fd82c4c4Schristos # endif
670*fd82c4c4Schristos _GL_CXXALIASWARN (memmem);
671*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
672*fd82c4c4Schristos # undef memmem
673*fd82c4c4Schristos # if HAVE_RAW_DECL_MEMMEM
674*fd82c4c4Schristos _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
675*fd82c4c4Schristos                  "use gnulib module memmem-simple for portability, "
676*fd82c4c4Schristos                  "and module memmem for speed" );
677*fd82c4c4Schristos # endif
678*fd82c4c4Schristos #endif
679*fd82c4c4Schristos 
680*fd82c4c4Schristos /* Copy N bytes of SRC to DEST, return pointer to bytes after the
681*fd82c4c4Schristos    last written byte.  */
682*fd82c4c4Schristos #if 1
683*fd82c4c4Schristos # if ! 0
684*fd82c4c4Schristos _GL_FUNCDECL_SYS (mempcpy, void *,
685*fd82c4c4Schristos                   (void *restrict __dest, void const *restrict __src,
686*fd82c4c4Schristos                    size_t __n)
687*fd82c4c4Schristos                   _GL_ARG_NONNULL ((1, 2)));
688*fd82c4c4Schristos # endif
689*fd82c4c4Schristos _GL_CXXALIAS_SYS (mempcpy, void *,
690*fd82c4c4Schristos                   (void *restrict __dest, void const *restrict __src,
691*fd82c4c4Schristos                    size_t __n));
692*fd82c4c4Schristos _GL_CXXALIASWARN (mempcpy);
693*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
694*fd82c4c4Schristos # undef mempcpy
695*fd82c4c4Schristos # if HAVE_RAW_DECL_MEMPCPY
696*fd82c4c4Schristos _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
697*fd82c4c4Schristos                  "use gnulib module mempcpy for portability");
698*fd82c4c4Schristos # endif
699*fd82c4c4Schristos #endif
700*fd82c4c4Schristos 
701*fd82c4c4Schristos /* Search backwards through a block for a byte (specified as an int).  */
702*fd82c4c4Schristos #if 1
703*fd82c4c4Schristos # if ! 1
704*fd82c4c4Schristos _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
705*fd82c4c4Schristos                                    _GL_ATTRIBUTE_PURE
706*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1)));
707*fd82c4c4Schristos # endif
708*fd82c4c4Schristos   /* On some systems, this function is defined as an overloaded function:
709*fd82c4c4Schristos        extern "C++" { const void * std::memrchr (const void *, int, size_t); }
710*fd82c4c4Schristos        extern "C++" { void * std::memrchr (void *, int, size_t); }  */
711*fd82c4c4Schristos _GL_CXXALIAS_SYS_CAST2 (memrchr,
712*fd82c4c4Schristos                         void *, (void const *, int, size_t),
713*fd82c4c4Schristos                         void const *, (void const *, int, size_t));
714*fd82c4c4Schristos # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
715*fd82c4c4Schristos      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
716*fd82c4c4Schristos _GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t));
717*fd82c4c4Schristos _GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t));
718*fd82c4c4Schristos # else
719*fd82c4c4Schristos _GL_CXXALIASWARN (memrchr);
720*fd82c4c4Schristos # endif
721*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
722*fd82c4c4Schristos # undef memrchr
723*fd82c4c4Schristos # if HAVE_RAW_DECL_MEMRCHR
724*fd82c4c4Schristos _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
725*fd82c4c4Schristos                  "use gnulib module memrchr for portability");
726*fd82c4c4Schristos # endif
727*fd82c4c4Schristos #endif
728*fd82c4c4Schristos 
729*fd82c4c4Schristos /* Find the first occurrence of C in S.  More efficient than
730*fd82c4c4Schristos    memchr(S,C,N), at the expense of undefined behavior if C does not
731*fd82c4c4Schristos    occur within N bytes.  */
732*fd82c4c4Schristos #if 1
733*fd82c4c4Schristos # if ! 0
734*fd82c4c4Schristos _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
735*fd82c4c4Schristos                                      _GL_ATTRIBUTE_PURE
736*fd82c4c4Schristos                                      _GL_ARG_NONNULL ((1)));
737*fd82c4c4Schristos # endif
738*fd82c4c4Schristos   /* On some systems, this function is defined as an overloaded function:
739*fd82c4c4Schristos        extern "C++" { const void * std::rawmemchr (const void *, int); }
740*fd82c4c4Schristos        extern "C++" { void * std::rawmemchr (void *, int); }  */
741*fd82c4c4Schristos _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
742*fd82c4c4Schristos                         void *, (void const *__s, int __c_in),
743*fd82c4c4Schristos                         void const *, (void const *__s, int __c_in));
744*fd82c4c4Schristos # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
745*fd82c4c4Schristos      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
746*fd82c4c4Schristos _GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in));
747*fd82c4c4Schristos _GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in));
748*fd82c4c4Schristos # else
749*fd82c4c4Schristos _GL_CXXALIASWARN (rawmemchr);
750*fd82c4c4Schristos # endif
751*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
752*fd82c4c4Schristos # undef rawmemchr
753*fd82c4c4Schristos # if HAVE_RAW_DECL_RAWMEMCHR
754*fd82c4c4Schristos _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
755*fd82c4c4Schristos                  "use gnulib module rawmemchr for portability");
756*fd82c4c4Schristos # endif
757*fd82c4c4Schristos #endif
758*fd82c4c4Schristos 
759*fd82c4c4Schristos /* Copy SRC to DST, returning the address of the terminating '\0' in DST.  */
760*fd82c4c4Schristos #if 0
761*fd82c4c4Schristos # if ! 1
762*fd82c4c4Schristos _GL_FUNCDECL_SYS (stpcpy, char *,
763*fd82c4c4Schristos                   (char *restrict __dst, char const *restrict __src)
764*fd82c4c4Schristos                   _GL_ARG_NONNULL ((1, 2)));
765*fd82c4c4Schristos # endif
766*fd82c4c4Schristos _GL_CXXALIAS_SYS (stpcpy, char *,
767*fd82c4c4Schristos                   (char *restrict __dst, char const *restrict __src));
768*fd82c4c4Schristos _GL_CXXALIASWARN (stpcpy);
769*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
770*fd82c4c4Schristos # undef stpcpy
771*fd82c4c4Schristos # if HAVE_RAW_DECL_STPCPY
772*fd82c4c4Schristos _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
773*fd82c4c4Schristos                  "use gnulib module stpcpy for portability");
774*fd82c4c4Schristos # endif
775*fd82c4c4Schristos #endif
776*fd82c4c4Schristos 
777*fd82c4c4Schristos /* Copy no more than N bytes of SRC to DST, returning a pointer past the
778*fd82c4c4Schristos    last non-NUL byte written into DST.  */
779*fd82c4c4Schristos #if 0
780*fd82c4c4Schristos # if 0
781*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
782*fd82c4c4Schristos #   undef stpncpy
783*fd82c4c4Schristos #   define stpncpy rpl_stpncpy
784*fd82c4c4Schristos #  endif
785*fd82c4c4Schristos _GL_FUNCDECL_RPL (stpncpy, char *,
786*fd82c4c4Schristos                   (char *restrict __dst, char const *restrict __src,
787*fd82c4c4Schristos                    size_t __n)
788*fd82c4c4Schristos                   _GL_ARG_NONNULL ((1, 2)));
789*fd82c4c4Schristos _GL_CXXALIAS_RPL (stpncpy, char *,
790*fd82c4c4Schristos                   (char *restrict __dst, char const *restrict __src,
791*fd82c4c4Schristos                    size_t __n));
792*fd82c4c4Schristos # else
793*fd82c4c4Schristos #  if ! 1
794*fd82c4c4Schristos _GL_FUNCDECL_SYS (stpncpy, char *,
795*fd82c4c4Schristos                   (char *restrict __dst, char const *restrict __src,
796*fd82c4c4Schristos                    size_t __n)
797*fd82c4c4Schristos                   _GL_ARG_NONNULL ((1, 2)));
798*fd82c4c4Schristos #  endif
799*fd82c4c4Schristos _GL_CXXALIAS_SYS (stpncpy, char *,
800*fd82c4c4Schristos                   (char *restrict __dst, char const *restrict __src,
801*fd82c4c4Schristos                    size_t __n));
802*fd82c4c4Schristos # endif
803*fd82c4c4Schristos _GL_CXXALIASWARN (stpncpy);
804*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
805*fd82c4c4Schristos # undef stpncpy
806*fd82c4c4Schristos # if HAVE_RAW_DECL_STPNCPY
807*fd82c4c4Schristos _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
808*fd82c4c4Schristos                  "use gnulib module stpncpy for portability");
809*fd82c4c4Schristos # endif
810*fd82c4c4Schristos #endif
811*fd82c4c4Schristos 
812*fd82c4c4Schristos #if defined GNULIB_POSIXCHECK
813*fd82c4c4Schristos /* strchr() does not work with multibyte strings if the locale encoding is
814*fd82c4c4Schristos    GB18030 and the character to be searched is a digit.  */
815*fd82c4c4Schristos # undef strchr
816*fd82c4c4Schristos /* Assume strchr is always declared.  */
817*fd82c4c4Schristos _GL_WARN_ON_USE_CXX (strchr, const char *, (const char *, int),
818*fd82c4c4Schristos                      "strchr cannot work correctly on character strings "
819*fd82c4c4Schristos                      "in some multibyte locales - "
820*fd82c4c4Schristos                      "use mbschr if you care about internationalization");
821*fd82c4c4Schristos #endif
822*fd82c4c4Schristos 
823*fd82c4c4Schristos /* Find the first occurrence of C in S or the final NUL byte.  */
824*fd82c4c4Schristos #if 1
825*fd82c4c4Schristos # if 0
826*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
827*fd82c4c4Schristos #   define strchrnul rpl_strchrnul
828*fd82c4c4Schristos #  endif
829*fd82c4c4Schristos _GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in)
830*fd82c4c4Schristos                                      _GL_ATTRIBUTE_PURE
831*fd82c4c4Schristos                                      _GL_ARG_NONNULL ((1)));
832*fd82c4c4Schristos _GL_CXXALIAS_RPL (strchrnul, char *,
833*fd82c4c4Schristos                   (const char *str, int ch));
834*fd82c4c4Schristos # else
835*fd82c4c4Schristos #  if ! 1
836*fd82c4c4Schristos _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
837*fd82c4c4Schristos                                      _GL_ATTRIBUTE_PURE
838*fd82c4c4Schristos                                      _GL_ARG_NONNULL ((1)));
839*fd82c4c4Schristos #  endif
840*fd82c4c4Schristos   /* On some systems, this function is defined as an overloaded function:
841*fd82c4c4Schristos        extern "C++" { const char * std::strchrnul (const char *, int); }
842*fd82c4c4Schristos        extern "C++" { char * std::strchrnul (char *, int); }  */
843*fd82c4c4Schristos _GL_CXXALIAS_SYS_CAST2 (strchrnul,
844*fd82c4c4Schristos                         char *, (char const *__s, int __c_in),
845*fd82c4c4Schristos                         char const *, (char const *__s, int __c_in));
846*fd82c4c4Schristos # endif
847*fd82c4c4Schristos # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
848*fd82c4c4Schristos      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
849*fd82c4c4Schristos _GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
850*fd82c4c4Schristos _GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
851*fd82c4c4Schristos # else
852*fd82c4c4Schristos _GL_CXXALIASWARN (strchrnul);
853*fd82c4c4Schristos # endif
854*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
855*fd82c4c4Schristos # undef strchrnul
856*fd82c4c4Schristos # if HAVE_RAW_DECL_STRCHRNUL
857*fd82c4c4Schristos _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
858*fd82c4c4Schristos                  "use gnulib module strchrnul for portability");
859*fd82c4c4Schristos # endif
860*fd82c4c4Schristos #endif
861*fd82c4c4Schristos 
862*fd82c4c4Schristos /* Duplicate S, returning an identical malloc'd string.  */
863*fd82c4c4Schristos #if 1
864*fd82c4c4Schristos # if 0
865*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
866*fd82c4c4Schristos #   undef strdup
867*fd82c4c4Schristos #   define strdup rpl_strdup
868*fd82c4c4Schristos #  endif
869*fd82c4c4Schristos _GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
870*fd82c4c4Schristos _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
871*fd82c4c4Schristos # else
872*fd82c4c4Schristos #  if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
873*fd82c4c4Schristos     /* strdup exists as a function and as a macro.  Get rid of the macro.  */
874*fd82c4c4Schristos #   undef strdup
875*fd82c4c4Schristos #  endif
876*fd82c4c4Schristos #  if !(1 || defined strdup)
877*fd82c4c4Schristos _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
878*fd82c4c4Schristos #  endif
879*fd82c4c4Schristos _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
880*fd82c4c4Schristos # endif
881*fd82c4c4Schristos _GL_CXXALIASWARN (strdup);
882*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
883*fd82c4c4Schristos # undef strdup
884*fd82c4c4Schristos # if HAVE_RAW_DECL_STRDUP
885*fd82c4c4Schristos _GL_WARN_ON_USE (strdup, "strdup is unportable - "
886*fd82c4c4Schristos                  "use gnulib module strdup for portability");
887*fd82c4c4Schristos # endif
888*fd82c4c4Schristos #endif
889*fd82c4c4Schristos 
890*fd82c4c4Schristos /* Append no more than N characters from SRC onto DEST.  */
891*fd82c4c4Schristos #if 0
892*fd82c4c4Schristos # if 0
893*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
894*fd82c4c4Schristos #   undef strncat
895*fd82c4c4Schristos #   define strncat rpl_strncat
896*fd82c4c4Schristos #  endif
897*fd82c4c4Schristos _GL_FUNCDECL_RPL (strncat, char *,
898*fd82c4c4Schristos                   (char *restrict dest, const char *restrict src, size_t n)
899*fd82c4c4Schristos                   _GL_ARG_NONNULL ((1, 2)));
900*fd82c4c4Schristos _GL_CXXALIAS_RPL (strncat, char *,
901*fd82c4c4Schristos                   (char *restrict dest, const char *restrict src, size_t n));
902*fd82c4c4Schristos # else
903*fd82c4c4Schristos _GL_CXXALIAS_SYS (strncat, char *,
904*fd82c4c4Schristos                   (char *restrict dest, const char *restrict src, size_t n));
905*fd82c4c4Schristos # endif
906*fd82c4c4Schristos # if __GLIBC__ >= 2
907*fd82c4c4Schristos _GL_CXXALIASWARN (strncat);
908*fd82c4c4Schristos # endif
909*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
910*fd82c4c4Schristos # undef strncat
911*fd82c4c4Schristos # if HAVE_RAW_DECL_STRNCAT
912*fd82c4c4Schristos _GL_WARN_ON_USE (strncat, "strncat is unportable - "
913*fd82c4c4Schristos                  "use gnulib module strncat for portability");
914*fd82c4c4Schristos # endif
915*fd82c4c4Schristos #endif
916*fd82c4c4Schristos 
917*fd82c4c4Schristos /* Return a newly allocated copy of at most N bytes of STRING.  */
918*fd82c4c4Schristos #if 0
919*fd82c4c4Schristos # if 0
920*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
921*fd82c4c4Schristos #   undef strndup
922*fd82c4c4Schristos #   define strndup rpl_strndup
923*fd82c4c4Schristos #  endif
924*fd82c4c4Schristos _GL_FUNCDECL_RPL (strndup, char *, (char const *__s, size_t __n)
925*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1)));
926*fd82c4c4Schristos _GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n));
927*fd82c4c4Schristos # else
928*fd82c4c4Schristos #  if ! 1
929*fd82c4c4Schristos _GL_FUNCDECL_SYS (strndup, char *, (char const *__s, size_t __n)
930*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1)));
931*fd82c4c4Schristos #  endif
932*fd82c4c4Schristos _GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n));
933*fd82c4c4Schristos # endif
934*fd82c4c4Schristos _GL_CXXALIASWARN (strndup);
935*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
936*fd82c4c4Schristos # undef strndup
937*fd82c4c4Schristos # if HAVE_RAW_DECL_STRNDUP
938*fd82c4c4Schristos _GL_WARN_ON_USE (strndup, "strndup is unportable - "
939*fd82c4c4Schristos                  "use gnulib module strndup for portability");
940*fd82c4c4Schristos # endif
941*fd82c4c4Schristos #endif
942*fd82c4c4Schristos 
943*fd82c4c4Schristos /* Find the length (number of bytes) of STRING, but scan at most
944*fd82c4c4Schristos    MAXLEN bytes.  If no '\0' terminator is found in that many bytes,
945*fd82c4c4Schristos    return MAXLEN.  */
946*fd82c4c4Schristos #if 1
947*fd82c4c4Schristos # if 0
948*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
949*fd82c4c4Schristos #   undef strnlen
950*fd82c4c4Schristos #   define strnlen rpl_strnlen
951*fd82c4c4Schristos #  endif
952*fd82c4c4Schristos _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__s, size_t __maxlen)
953*fd82c4c4Schristos                                    _GL_ATTRIBUTE_PURE
954*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1)));
955*fd82c4c4Schristos _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__s, size_t __maxlen));
956*fd82c4c4Schristos # else
957*fd82c4c4Schristos #  if ! 1
958*fd82c4c4Schristos _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__s, size_t __maxlen)
959*fd82c4c4Schristos                                    _GL_ATTRIBUTE_PURE
960*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1)));
961*fd82c4c4Schristos #  endif
962*fd82c4c4Schristos _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__s, size_t __maxlen));
963*fd82c4c4Schristos # endif
964*fd82c4c4Schristos _GL_CXXALIASWARN (strnlen);
965*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
966*fd82c4c4Schristos # undef strnlen
967*fd82c4c4Schristos # if HAVE_RAW_DECL_STRNLEN
968*fd82c4c4Schristos _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
969*fd82c4c4Schristos                  "use gnulib module strnlen for portability");
970*fd82c4c4Schristos # endif
971*fd82c4c4Schristos #endif
972*fd82c4c4Schristos 
973*fd82c4c4Schristos #if defined GNULIB_POSIXCHECK
974*fd82c4c4Schristos /* strcspn() assumes the second argument is a list of single-byte characters.
975*fd82c4c4Schristos    Even in this simple case, it does not work with multibyte strings if the
976*fd82c4c4Schristos    locale encoding is GB18030 and one of the characters to be searched is a
977*fd82c4c4Schristos    digit.  */
978*fd82c4c4Schristos # undef strcspn
979*fd82c4c4Schristos /* Assume strcspn is always declared.  */
980*fd82c4c4Schristos _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
981*fd82c4c4Schristos                  "in multibyte locales - "
982*fd82c4c4Schristos                  "use mbscspn if you care about internationalization");
983*fd82c4c4Schristos #endif
984*fd82c4c4Schristos 
985*fd82c4c4Schristos /* Find the first occurrence in S of any character in ACCEPT.  */
986*fd82c4c4Schristos #if 0
987*fd82c4c4Schristos # if ! 1
988*fd82c4c4Schristos _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
989*fd82c4c4Schristos                                    _GL_ATTRIBUTE_PURE
990*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1, 2)));
991*fd82c4c4Schristos # endif
992*fd82c4c4Schristos   /* On some systems, this function is defined as an overloaded function:
993*fd82c4c4Schristos        extern "C" { const char * strpbrk (const char *, const char *); }
994*fd82c4c4Schristos        extern "C++" { char * strpbrk (char *, const char *); }  */
995*fd82c4c4Schristos _GL_CXXALIAS_SYS_CAST2 (strpbrk,
996*fd82c4c4Schristos                         char *, (char const *__s, char const *__accept),
997*fd82c4c4Schristos                         const char *, (char const *__s, char const *__accept));
998*fd82c4c4Schristos # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
999*fd82c4c4Schristos      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1000*fd82c4c4Schristos _GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
1001*fd82c4c4Schristos _GL_CXXALIASWARN1 (strpbrk, char const *,
1002*fd82c4c4Schristos                    (char const *__s, char const *__accept));
1003*fd82c4c4Schristos # elif __GLIBC__ >= 2
1004*fd82c4c4Schristos _GL_CXXALIASWARN (strpbrk);
1005*fd82c4c4Schristos # endif
1006*fd82c4c4Schristos # if defined GNULIB_POSIXCHECK
1007*fd82c4c4Schristos /* strpbrk() assumes the second argument is a list of single-byte characters.
1008*fd82c4c4Schristos    Even in this simple case, it does not work with multibyte strings if the
1009*fd82c4c4Schristos    locale encoding is GB18030 and one of the characters to be searched is a
1010*fd82c4c4Schristos    digit.  */
1011*fd82c4c4Schristos #  undef strpbrk
1012*fd82c4c4Schristos _GL_WARN_ON_USE_CXX (strpbrk, const char *, (const char *, const char *),
1013*fd82c4c4Schristos                      "strpbrk cannot work correctly on character strings "
1014*fd82c4c4Schristos                      "in multibyte locales - "
1015*fd82c4c4Schristos                      "use mbspbrk if you care about internationalization");
1016*fd82c4c4Schristos # endif
1017*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
1018*fd82c4c4Schristos # undef strpbrk
1019*fd82c4c4Schristos # if HAVE_RAW_DECL_STRPBRK
1020*fd82c4c4Schristos _GL_WARN_ON_USE_CXX (strpbrk, const char *, (const char *, const char *),
1021*fd82c4c4Schristos                      "strpbrk is unportable - "
1022*fd82c4c4Schristos                      "use gnulib module strpbrk for portability");
1023*fd82c4c4Schristos # endif
1024*fd82c4c4Schristos #endif
1025*fd82c4c4Schristos 
1026*fd82c4c4Schristos #if defined GNULIB_POSIXCHECK
1027*fd82c4c4Schristos /* strspn() assumes the second argument is a list of single-byte characters.
1028*fd82c4c4Schristos    Even in this simple case, it cannot work with multibyte strings.  */
1029*fd82c4c4Schristos # undef strspn
1030*fd82c4c4Schristos /* Assume strspn is always declared.  */
1031*fd82c4c4Schristos _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
1032*fd82c4c4Schristos                  "in multibyte locales - "
1033*fd82c4c4Schristos                  "use mbsspn if you care about internationalization");
1034*fd82c4c4Schristos #endif
1035*fd82c4c4Schristos 
1036*fd82c4c4Schristos #if defined GNULIB_POSIXCHECK
1037*fd82c4c4Schristos /* strrchr() does not work with multibyte strings if the locale encoding is
1038*fd82c4c4Schristos    GB18030 and the character to be searched is a digit.  */
1039*fd82c4c4Schristos # undef strrchr
1040*fd82c4c4Schristos /* Assume strrchr is always declared.  */
1041*fd82c4c4Schristos _GL_WARN_ON_USE_CXX (strrchr, const char *, (const char *, int),
1042*fd82c4c4Schristos                      "strrchr cannot work correctly on character strings "
1043*fd82c4c4Schristos                      "in some multibyte locales - "
1044*fd82c4c4Schristos                      "use mbsrchr if you care about internationalization");
1045*fd82c4c4Schristos #endif
1046*fd82c4c4Schristos 
1047*fd82c4c4Schristos /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
1048*fd82c4c4Schristos    If one is found, overwrite it with a NUL, and advance *STRINGP
1049*fd82c4c4Schristos    to point to the next char after it.  Otherwise, set *STRINGP to NULL.
1050*fd82c4c4Schristos    If *STRINGP was already NULL, nothing happens.
1051*fd82c4c4Schristos    Return the old value of *STRINGP.
1052*fd82c4c4Schristos 
1053*fd82c4c4Schristos    This is a variant of strtok() that is multithread-safe and supports
1054*fd82c4c4Schristos    empty fields.
1055*fd82c4c4Schristos 
1056*fd82c4c4Schristos    Caveat: It modifies the original string.
1057*fd82c4c4Schristos    Caveat: These functions cannot be used on constant strings.
1058*fd82c4c4Schristos    Caveat: The identity of the delimiting character is lost.
1059*fd82c4c4Schristos    Caveat: It doesn't work with multibyte strings unless all of the delimiter
1060*fd82c4c4Schristos            characters are ASCII characters < 0x30.
1061*fd82c4c4Schristos 
1062*fd82c4c4Schristos    See also strtok_r().  */
1063*fd82c4c4Schristos #if 0
1064*fd82c4c4Schristos # if ! 1
1065*fd82c4c4Schristos _GL_FUNCDECL_SYS (strsep, char *,
1066*fd82c4c4Schristos                   (char **restrict __stringp, char const *restrict __delim)
1067*fd82c4c4Schristos                   _GL_ARG_NONNULL ((1, 2)));
1068*fd82c4c4Schristos # endif
1069*fd82c4c4Schristos _GL_CXXALIAS_SYS (strsep, char *,
1070*fd82c4c4Schristos                   (char **restrict __stringp, char const *restrict __delim));
1071*fd82c4c4Schristos _GL_CXXALIASWARN (strsep);
1072*fd82c4c4Schristos # if defined GNULIB_POSIXCHECK
1073*fd82c4c4Schristos #  undef strsep
1074*fd82c4c4Schristos _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
1075*fd82c4c4Schristos                  "in multibyte locales - "
1076*fd82c4c4Schristos                  "use mbssep if you care about internationalization");
1077*fd82c4c4Schristos # endif
1078*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
1079*fd82c4c4Schristos # undef strsep
1080*fd82c4c4Schristos # if HAVE_RAW_DECL_STRSEP
1081*fd82c4c4Schristos _GL_WARN_ON_USE (strsep, "strsep is unportable - "
1082*fd82c4c4Schristos                  "use gnulib module strsep for portability");
1083*fd82c4c4Schristos # endif
1084*fd82c4c4Schristos #endif
1085*fd82c4c4Schristos 
1086*fd82c4c4Schristos #if 1
1087*fd82c4c4Schristos # if 1
1088*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1089*fd82c4c4Schristos #   define strstr rpl_strstr
1090*fd82c4c4Schristos #  endif
1091*fd82c4c4Schristos _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
1092*fd82c4c4Schristos                                   _GL_ATTRIBUTE_PURE
1093*fd82c4c4Schristos                                   _GL_ARG_NONNULL ((1, 2)));
1094*fd82c4c4Schristos _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
1095*fd82c4c4Schristos # else
1096*fd82c4c4Schristos   /* On some systems, this function is defined as an overloaded function:
1097*fd82c4c4Schristos        extern "C++" { const char * strstr (const char *, const char *); }
1098*fd82c4c4Schristos        extern "C++" { char * strstr (char *, const char *); }  */
1099*fd82c4c4Schristos _GL_CXXALIAS_SYS_CAST2 (strstr,
1100*fd82c4c4Schristos                         char *, (const char *haystack, const char *needle),
1101*fd82c4c4Schristos                         const char *, (const char *haystack, const char *needle));
1102*fd82c4c4Schristos # endif
1103*fd82c4c4Schristos # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
1104*fd82c4c4Schristos      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1105*fd82c4c4Schristos _GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
1106*fd82c4c4Schristos _GL_CXXALIASWARN1 (strstr, const char *,
1107*fd82c4c4Schristos                    (const char *haystack, const char *needle));
1108*fd82c4c4Schristos # elif __GLIBC__ >= 2
1109*fd82c4c4Schristos _GL_CXXALIASWARN (strstr);
1110*fd82c4c4Schristos # endif
1111*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
1112*fd82c4c4Schristos /* strstr() does not work with multibyte strings if the locale encoding is
1113*fd82c4c4Schristos    different from UTF-8:
1114*fd82c4c4Schristos    POSIX says that it operates on "strings", and "string" in POSIX is defined
1115*fd82c4c4Schristos    as a sequence of bytes, not of characters.  */
1116*fd82c4c4Schristos # undef strstr
1117*fd82c4c4Schristos /* Assume strstr is always declared.  */
1118*fd82c4c4Schristos _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
1119*fd82c4c4Schristos                  "work correctly on character strings in most "
1120*fd82c4c4Schristos                  "multibyte locales - "
1121*fd82c4c4Schristos                  "use mbsstr if you care about internationalization, "
1122*fd82c4c4Schristos                  "or use strstr if you care about speed");
1123*fd82c4c4Schristos #endif
1124*fd82c4c4Schristos 
1125*fd82c4c4Schristos /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
1126*fd82c4c4Schristos    comparison.  */
1127*fd82c4c4Schristos #if 0
1128*fd82c4c4Schristos # if 0
1129*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1130*fd82c4c4Schristos #   define strcasestr rpl_strcasestr
1131*fd82c4c4Schristos #  endif
1132*fd82c4c4Schristos _GL_FUNCDECL_RPL (strcasestr, char *,
1133*fd82c4c4Schristos                   (const char *haystack, const char *needle)
1134*fd82c4c4Schristos                   _GL_ATTRIBUTE_PURE
1135*fd82c4c4Schristos                   _GL_ARG_NONNULL ((1, 2)));
1136*fd82c4c4Schristos _GL_CXXALIAS_RPL (strcasestr, char *,
1137*fd82c4c4Schristos                   (const char *haystack, const char *needle));
1138*fd82c4c4Schristos # else
1139*fd82c4c4Schristos #  if ! 1
1140*fd82c4c4Schristos _GL_FUNCDECL_SYS (strcasestr, char *,
1141*fd82c4c4Schristos                   (const char *haystack, const char *needle)
1142*fd82c4c4Schristos                   _GL_ATTRIBUTE_PURE
1143*fd82c4c4Schristos                   _GL_ARG_NONNULL ((1, 2)));
1144*fd82c4c4Schristos #  endif
1145*fd82c4c4Schristos   /* On some systems, this function is defined as an overloaded function:
1146*fd82c4c4Schristos        extern "C++" { const char * strcasestr (const char *, const char *); }
1147*fd82c4c4Schristos        extern "C++" { char * strcasestr (char *, const char *); }  */
1148*fd82c4c4Schristos _GL_CXXALIAS_SYS_CAST2 (strcasestr,
1149*fd82c4c4Schristos                         char *, (const char *haystack, const char *needle),
1150*fd82c4c4Schristos                         const char *, (const char *haystack, const char *needle));
1151*fd82c4c4Schristos # endif
1152*fd82c4c4Schristos # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
1153*fd82c4c4Schristos      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1154*fd82c4c4Schristos _GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
1155*fd82c4c4Schristos _GL_CXXALIASWARN1 (strcasestr, const char *,
1156*fd82c4c4Schristos                    (const char *haystack, const char *needle));
1157*fd82c4c4Schristos # else
1158*fd82c4c4Schristos _GL_CXXALIASWARN (strcasestr);
1159*fd82c4c4Schristos # endif
1160*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
1161*fd82c4c4Schristos /* strcasestr() does not work with multibyte strings:
1162*fd82c4c4Schristos    It is a glibc extension, and glibc implements it only for unibyte
1163*fd82c4c4Schristos    locales.  */
1164*fd82c4c4Schristos # undef strcasestr
1165*fd82c4c4Schristos # if HAVE_RAW_DECL_STRCASESTR
1166*fd82c4c4Schristos _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
1167*fd82c4c4Schristos                  "strings in multibyte locales - "
1168*fd82c4c4Schristos                  "use mbscasestr if you care about "
1169*fd82c4c4Schristos                  "internationalization, or use c-strcasestr if you want "
1170*fd82c4c4Schristos                  "a locale independent function");
1171*fd82c4c4Schristos # endif
1172*fd82c4c4Schristos #endif
1173*fd82c4c4Schristos 
1174*fd82c4c4Schristos /* Parse S into tokens separated by characters in DELIM.
1175*fd82c4c4Schristos    If S is NULL, the saved pointer in SAVE_PTR is used as
1176*fd82c4c4Schristos    the next starting point.  For example:
1177*fd82c4c4Schristos         char s[] = "-abc-=-def";
1178*fd82c4c4Schristos         char *sp;
1179*fd82c4c4Schristos         x = strtok_r(s, "-", &sp);      // x = "abc", sp = "=-def"
1180*fd82c4c4Schristos         x = strtok_r(NULL, "-=", &sp);  // x = "def", sp = NULL
1181*fd82c4c4Schristos         x = strtok_r(NULL, "=", &sp);   // x = NULL
1182*fd82c4c4Schristos                 // s = "abc\0-def\0"
1183*fd82c4c4Schristos 
1184*fd82c4c4Schristos    This is a variant of strtok() that is multithread-safe.
1185*fd82c4c4Schristos 
1186*fd82c4c4Schristos    For the POSIX documentation for this function, see:
1187*fd82c4c4Schristos    https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok.html
1188*fd82c4c4Schristos 
1189*fd82c4c4Schristos    Caveat: It modifies the original string.
1190*fd82c4c4Schristos    Caveat: These functions cannot be used on constant strings.
1191*fd82c4c4Schristos    Caveat: The identity of the delimiting character is lost.
1192*fd82c4c4Schristos    Caveat: It doesn't work with multibyte strings unless all of the delimiter
1193*fd82c4c4Schristos            characters are ASCII characters < 0x30.
1194*fd82c4c4Schristos 
1195*fd82c4c4Schristos    See also strsep().  */
1196*fd82c4c4Schristos #if 1
1197*fd82c4c4Schristos # if 0
1198*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1199*fd82c4c4Schristos #   undef strtok_r
1200*fd82c4c4Schristos #   define strtok_r rpl_strtok_r
1201*fd82c4c4Schristos #  endif
1202*fd82c4c4Schristos _GL_FUNCDECL_RPL (strtok_r, char *,
1203*fd82c4c4Schristos                   (char *restrict s, char const *restrict delim,
1204*fd82c4c4Schristos                    char **restrict save_ptr)
1205*fd82c4c4Schristos                   _GL_ARG_NONNULL ((2, 3)));
1206*fd82c4c4Schristos _GL_CXXALIAS_RPL (strtok_r, char *,
1207*fd82c4c4Schristos                   (char *restrict s, char const *restrict delim,
1208*fd82c4c4Schristos                    char **restrict save_ptr));
1209*fd82c4c4Schristos # else
1210*fd82c4c4Schristos #  if 0 || defined GNULIB_POSIXCHECK
1211*fd82c4c4Schristos #   undef strtok_r
1212*fd82c4c4Schristos #  endif
1213*fd82c4c4Schristos #  if ! 1
1214*fd82c4c4Schristos _GL_FUNCDECL_SYS (strtok_r, char *,
1215*fd82c4c4Schristos                   (char *restrict s, char const *restrict delim,
1216*fd82c4c4Schristos                    char **restrict save_ptr)
1217*fd82c4c4Schristos                   _GL_ARG_NONNULL ((2, 3)));
1218*fd82c4c4Schristos #  endif
1219*fd82c4c4Schristos _GL_CXXALIAS_SYS (strtok_r, char *,
1220*fd82c4c4Schristos                   (char *restrict s, char const *restrict delim,
1221*fd82c4c4Schristos                    char **restrict save_ptr));
1222*fd82c4c4Schristos # endif
1223*fd82c4c4Schristos _GL_CXXALIASWARN (strtok_r);
1224*fd82c4c4Schristos # if defined GNULIB_POSIXCHECK
1225*fd82c4c4Schristos _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
1226*fd82c4c4Schristos                  "strings in multibyte locales - "
1227*fd82c4c4Schristos                  "use mbstok_r if you care about internationalization");
1228*fd82c4c4Schristos # endif
1229*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
1230*fd82c4c4Schristos # undef strtok_r
1231*fd82c4c4Schristos # if HAVE_RAW_DECL_STRTOK_R
1232*fd82c4c4Schristos _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
1233*fd82c4c4Schristos                  "use gnulib module strtok_r for portability");
1234*fd82c4c4Schristos # endif
1235*fd82c4c4Schristos #endif
1236*fd82c4c4Schristos 
1237*fd82c4c4Schristos 
1238*fd82c4c4Schristos /* The following functions are not specified by POSIX.  They are gnulib
1239*fd82c4c4Schristos    extensions.  */
1240*fd82c4c4Schristos 
1241*fd82c4c4Schristos #if 0
1242*fd82c4c4Schristos /* Return the number of multibyte characters in the character string STRING.
1243*fd82c4c4Schristos    This considers multibyte characters, unlike strlen, which counts bytes.  */
1244*fd82c4c4Schristos # ifdef __MirBSD__  /* MirBSD defines mbslen as a macro.  Override it.  */
1245*fd82c4c4Schristos #  undef mbslen
1246*fd82c4c4Schristos # endif
1247*fd82c4c4Schristos # if 0  /* AIX, OSF/1, MirBSD define mbslen already in libc.  */
1248*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1249*fd82c4c4Schristos #   define mbslen rpl_mbslen
1250*fd82c4c4Schristos #  endif
1251*fd82c4c4Schristos _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string)
1252*fd82c4c4Schristos                                   _GL_ATTRIBUTE_PURE
1253*fd82c4c4Schristos                                   _GL_ARG_NONNULL ((1)));
1254*fd82c4c4Schristos _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
1255*fd82c4c4Schristos # else
1256*fd82c4c4Schristos _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string)
1257*fd82c4c4Schristos                                   _GL_ATTRIBUTE_PURE
1258*fd82c4c4Schristos                                   _GL_ARG_NONNULL ((1)));
1259*fd82c4c4Schristos _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
1260*fd82c4c4Schristos # endif
1261*fd82c4c4Schristos _GL_CXXALIASWARN (mbslen);
1262*fd82c4c4Schristos #endif
1263*fd82c4c4Schristos 
1264*fd82c4c4Schristos #if 0
1265*fd82c4c4Schristos /* Return the number of multibyte characters in the character string starting
1266*fd82c4c4Schristos    at STRING and ending at STRING + LEN.  */
1267*fd82c4c4Schristos _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
1268*fd82c4c4Schristos      _GL_ATTRIBUTE_PURE
1269*fd82c4c4Schristos      _GL_ARG_NONNULL ((1));
1270*fd82c4c4Schristos #endif
1271*fd82c4c4Schristos 
1272*fd82c4c4Schristos #if 0
1273*fd82c4c4Schristos /* Locate the first single-byte character C in the character string STRING,
1274*fd82c4c4Schristos    and return a pointer to it.  Return NULL if C is not found in STRING.
1275*fd82c4c4Schristos    Unlike strchr(), this function works correctly in multibyte locales with
1276*fd82c4c4Schristos    encodings such as GB18030.  */
1277*fd82c4c4Schristos # if defined __hpux
1278*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1279*fd82c4c4Schristos #   define mbschr rpl_mbschr /* avoid collision with HP-UX function */
1280*fd82c4c4Schristos #  endif
1281*fd82c4c4Schristos _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
1282*fd82c4c4Schristos                                   _GL_ATTRIBUTE_PURE
1283*fd82c4c4Schristos                                   _GL_ARG_NONNULL ((1)));
1284*fd82c4c4Schristos _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
1285*fd82c4c4Schristos # else
1286*fd82c4c4Schristos _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
1287*fd82c4c4Schristos                                   _GL_ATTRIBUTE_PURE
1288*fd82c4c4Schristos                                   _GL_ARG_NONNULL ((1)));
1289*fd82c4c4Schristos _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
1290*fd82c4c4Schristos # endif
1291*fd82c4c4Schristos _GL_CXXALIASWARN (mbschr);
1292*fd82c4c4Schristos #endif
1293*fd82c4c4Schristos 
1294*fd82c4c4Schristos #if 0
1295*fd82c4c4Schristos /* Locate the last single-byte character C in the character string STRING,
1296*fd82c4c4Schristos    and return a pointer to it.  Return NULL if C is not found in STRING.
1297*fd82c4c4Schristos    Unlike strrchr(), this function works correctly in multibyte locales with
1298*fd82c4c4Schristos    encodings such as GB18030.  */
1299*fd82c4c4Schristos # if defined __hpux || defined __INTERIX
1300*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1301*fd82c4c4Schristos #   define mbsrchr rpl_mbsrchr /* avoid collision with system function */
1302*fd82c4c4Schristos #  endif
1303*fd82c4c4Schristos _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
1304*fd82c4c4Schristos                                    _GL_ATTRIBUTE_PURE
1305*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1)));
1306*fd82c4c4Schristos _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
1307*fd82c4c4Schristos # else
1308*fd82c4c4Schristos _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
1309*fd82c4c4Schristos                                    _GL_ATTRIBUTE_PURE
1310*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1)));
1311*fd82c4c4Schristos _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
1312*fd82c4c4Schristos # endif
1313*fd82c4c4Schristos _GL_CXXALIASWARN (mbsrchr);
1314*fd82c4c4Schristos #endif
1315*fd82c4c4Schristos 
1316*fd82c4c4Schristos #if 0
1317*fd82c4c4Schristos /* Find the first occurrence of the character string NEEDLE in the character
1318*fd82c4c4Schristos    string HAYSTACK.  Return NULL if NEEDLE is not found in HAYSTACK.
1319*fd82c4c4Schristos    Unlike strstr(), this function works correctly in multibyte locales with
1320*fd82c4c4Schristos    encodings different from UTF-8.  */
1321*fd82c4c4Schristos _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
1322*fd82c4c4Schristos      _GL_ATTRIBUTE_PURE
1323*fd82c4c4Schristos      _GL_ARG_NONNULL ((1, 2));
1324*fd82c4c4Schristos #endif
1325*fd82c4c4Schristos 
1326*fd82c4c4Schristos #if 0
1327*fd82c4c4Schristos /* Compare the character strings S1 and S2, ignoring case, returning less than,
1328*fd82c4c4Schristos    equal to or greater than zero if S1 is lexicographically less than, equal to
1329*fd82c4c4Schristos    or greater than S2.
1330*fd82c4c4Schristos    Note: This function may, in multibyte locales, return 0 for strings of
1331*fd82c4c4Schristos    different lengths!
1332*fd82c4c4Schristos    Unlike strcasecmp(), this function works correctly in multibyte locales.  */
1333*fd82c4c4Schristos _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
1334*fd82c4c4Schristos      _GL_ATTRIBUTE_PURE
1335*fd82c4c4Schristos      _GL_ARG_NONNULL ((1, 2));
1336*fd82c4c4Schristos #endif
1337*fd82c4c4Schristos 
1338*fd82c4c4Schristos #if 0
1339*fd82c4c4Schristos /* Compare the initial segment of the character string S1 consisting of at most
1340*fd82c4c4Schristos    N characters with the initial segment of the character string S2 consisting
1341*fd82c4c4Schristos    of at most N characters, ignoring case, returning less than, equal to or
1342*fd82c4c4Schristos    greater than zero if the initial segment of S1 is lexicographically less
1343*fd82c4c4Schristos    than, equal to or greater than the initial segment of S2.
1344*fd82c4c4Schristos    Note: This function may, in multibyte locales, return 0 for initial segments
1345*fd82c4c4Schristos    of different lengths!
1346*fd82c4c4Schristos    Unlike strncasecmp(), this function works correctly in multibyte locales.
1347*fd82c4c4Schristos    But beware that N is not a byte count but a character count!  */
1348*fd82c4c4Schristos _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
1349*fd82c4c4Schristos      _GL_ATTRIBUTE_PURE
1350*fd82c4c4Schristos      _GL_ARG_NONNULL ((1, 2));
1351*fd82c4c4Schristos #endif
1352*fd82c4c4Schristos 
1353*fd82c4c4Schristos #if 0
1354*fd82c4c4Schristos /* Compare the initial segment of the character string STRING consisting of
1355*fd82c4c4Schristos    at most mbslen (PREFIX) characters with the character string PREFIX,
1356*fd82c4c4Schristos    ignoring case.  If the two match, return a pointer to the first byte
1357*fd82c4c4Schristos    after this prefix in STRING.  Otherwise, return NULL.
1358*fd82c4c4Schristos    Note: This function may, in multibyte locales, return non-NULL if STRING
1359*fd82c4c4Schristos    is of smaller length than PREFIX!
1360*fd82c4c4Schristos    Unlike strncasecmp(), this function works correctly in multibyte
1361*fd82c4c4Schristos    locales.  */
1362*fd82c4c4Schristos _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
1363*fd82c4c4Schristos      _GL_ATTRIBUTE_PURE
1364*fd82c4c4Schristos      _GL_ARG_NONNULL ((1, 2));
1365*fd82c4c4Schristos #endif
1366*fd82c4c4Schristos 
1367*fd82c4c4Schristos #if 0
1368*fd82c4c4Schristos /* Find the first occurrence of the character string NEEDLE in the character
1369*fd82c4c4Schristos    string HAYSTACK, using case-insensitive comparison.
1370*fd82c4c4Schristos    Note: This function may, in multibyte locales, return success even if
1371*fd82c4c4Schristos    strlen (haystack) < strlen (needle) !
1372*fd82c4c4Schristos    Unlike strcasestr(), this function works correctly in multibyte locales.  */
1373*fd82c4c4Schristos _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
1374*fd82c4c4Schristos      _GL_ATTRIBUTE_PURE
1375*fd82c4c4Schristos      _GL_ARG_NONNULL ((1, 2));
1376*fd82c4c4Schristos #endif
1377*fd82c4c4Schristos 
1378*fd82c4c4Schristos #if 0
1379*fd82c4c4Schristos /* Find the first occurrence in the character string STRING of any character
1380*fd82c4c4Schristos    in the character string ACCEPT.  Return the number of bytes from the
1381*fd82c4c4Schristos    beginning of the string to this occurrence, or to the end of the string
1382*fd82c4c4Schristos    if none exists.
1383*fd82c4c4Schristos    Unlike strcspn(), this function works correctly in multibyte locales.  */
1384*fd82c4c4Schristos _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
1385*fd82c4c4Schristos      _GL_ATTRIBUTE_PURE
1386*fd82c4c4Schristos      _GL_ARG_NONNULL ((1, 2));
1387*fd82c4c4Schristos #endif
1388*fd82c4c4Schristos 
1389*fd82c4c4Schristos #if 0
1390*fd82c4c4Schristos /* Find the first occurrence in the character string STRING of any character
1391*fd82c4c4Schristos    in the character string ACCEPT.  Return the pointer to it, or NULL if none
1392*fd82c4c4Schristos    exists.
1393*fd82c4c4Schristos    Unlike strpbrk(), this function works correctly in multibyte locales.  */
1394*fd82c4c4Schristos # if defined __hpux
1395*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1396*fd82c4c4Schristos #   define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
1397*fd82c4c4Schristos #  endif
1398*fd82c4c4Schristos _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
1399*fd82c4c4Schristos                                    _GL_ATTRIBUTE_PURE
1400*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1, 2)));
1401*fd82c4c4Schristos _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
1402*fd82c4c4Schristos # else
1403*fd82c4c4Schristos _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
1404*fd82c4c4Schristos                                    _GL_ATTRIBUTE_PURE
1405*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1, 2)));
1406*fd82c4c4Schristos _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
1407*fd82c4c4Schristos # endif
1408*fd82c4c4Schristos _GL_CXXALIASWARN (mbspbrk);
1409*fd82c4c4Schristos #endif
1410*fd82c4c4Schristos 
1411*fd82c4c4Schristos #if 0
1412*fd82c4c4Schristos /* Find the first occurrence in the character string STRING of any character
1413*fd82c4c4Schristos    not in the character string REJECT.  Return the number of bytes from the
1414*fd82c4c4Schristos    beginning of the string to this occurrence, or to the end of the string
1415*fd82c4c4Schristos    if none exists.
1416*fd82c4c4Schristos    Unlike strspn(), this function works correctly in multibyte locales.  */
1417*fd82c4c4Schristos _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
1418*fd82c4c4Schristos      _GL_ATTRIBUTE_PURE
1419*fd82c4c4Schristos      _GL_ARG_NONNULL ((1, 2));
1420*fd82c4c4Schristos #endif
1421*fd82c4c4Schristos 
1422*fd82c4c4Schristos #if 0
1423*fd82c4c4Schristos /* Search the next delimiter (multibyte character listed in the character
1424*fd82c4c4Schristos    string DELIM) starting at the character string *STRINGP.
1425*fd82c4c4Schristos    If one is found, overwrite it with a NUL, and advance *STRINGP to point
1426*fd82c4c4Schristos    to the next multibyte character after it.  Otherwise, set *STRINGP to NULL.
1427*fd82c4c4Schristos    If *STRINGP was already NULL, nothing happens.
1428*fd82c4c4Schristos    Return the old value of *STRINGP.
1429*fd82c4c4Schristos 
1430*fd82c4c4Schristos    This is a variant of mbstok_r() that supports empty fields.
1431*fd82c4c4Schristos 
1432*fd82c4c4Schristos    Caveat: It modifies the original string.
1433*fd82c4c4Schristos    Caveat: These functions cannot be used on constant strings.
1434*fd82c4c4Schristos    Caveat: The identity of the delimiting character is lost.
1435*fd82c4c4Schristos 
1436*fd82c4c4Schristos    See also mbstok_r().  */
1437*fd82c4c4Schristos _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
1438*fd82c4c4Schristos      _GL_ARG_NONNULL ((1, 2));
1439*fd82c4c4Schristos #endif
1440*fd82c4c4Schristos 
1441*fd82c4c4Schristos #if 0
1442*fd82c4c4Schristos /* Parse the character string STRING into tokens separated by characters in
1443*fd82c4c4Schristos    the character string DELIM.
1444*fd82c4c4Schristos    If STRING is NULL, the saved pointer in SAVE_PTR is used as
1445*fd82c4c4Schristos    the next starting point.  For example:
1446*fd82c4c4Schristos         char s[] = "-abc-=-def";
1447*fd82c4c4Schristos         char *sp;
1448*fd82c4c4Schristos         x = mbstok_r(s, "-", &sp);      // x = "abc", sp = "=-def"
1449*fd82c4c4Schristos         x = mbstok_r(NULL, "-=", &sp);  // x = "def", sp = NULL
1450*fd82c4c4Schristos         x = mbstok_r(NULL, "=", &sp);   // x = NULL
1451*fd82c4c4Schristos                 // s = "abc\0-def\0"
1452*fd82c4c4Schristos 
1453*fd82c4c4Schristos    Caveat: It modifies the original string.
1454*fd82c4c4Schristos    Caveat: These functions cannot be used on constant strings.
1455*fd82c4c4Schristos    Caveat: The identity of the delimiting character is lost.
1456*fd82c4c4Schristos 
1457*fd82c4c4Schristos    See also mbssep().  */
1458*fd82c4c4Schristos _GL_EXTERN_C char * mbstok_r (char *restrict string, const char *delim,
1459*fd82c4c4Schristos                               char **save_ptr)
1460*fd82c4c4Schristos      _GL_ARG_NONNULL ((2, 3));
1461*fd82c4c4Schristos #endif
1462*fd82c4c4Schristos 
1463*fd82c4c4Schristos /* Map any int, typically from errno, into an error message.  */
1464*fd82c4c4Schristos #if 1
1465*fd82c4c4Schristos # if 1
1466*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1467*fd82c4c4Schristos #   undef strerror
1468*fd82c4c4Schristos #   define strerror rpl_strerror
1469*fd82c4c4Schristos #  endif
1470*fd82c4c4Schristos _GL_FUNCDECL_RPL (strerror, char *, (int));
1471*fd82c4c4Schristos _GL_CXXALIAS_RPL (strerror, char *, (int));
1472*fd82c4c4Schristos # else
1473*fd82c4c4Schristos _GL_CXXALIAS_SYS (strerror, char *, (int));
1474*fd82c4c4Schristos # endif
1475*fd82c4c4Schristos # if __GLIBC__ >= 2
1476*fd82c4c4Schristos _GL_CXXALIASWARN (strerror);
1477*fd82c4c4Schristos # endif
1478*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
1479*fd82c4c4Schristos # undef strerror
1480*fd82c4c4Schristos /* Assume strerror is always declared.  */
1481*fd82c4c4Schristos _GL_WARN_ON_USE (strerror, "strerror is unportable - "
1482*fd82c4c4Schristos                  "use gnulib module strerror to guarantee non-NULL result");
1483*fd82c4c4Schristos #endif
1484*fd82c4c4Schristos 
1485*fd82c4c4Schristos /* Map any int, typically from errno, into an error message.  Multithread-safe.
1486*fd82c4c4Schristos    Uses the POSIX declaration, not the glibc declaration.  */
1487*fd82c4c4Schristos #if 1
1488*fd82c4c4Schristos # if 1
1489*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1490*fd82c4c4Schristos #   undef strerror_r
1491*fd82c4c4Schristos #   define strerror_r rpl_strerror_r
1492*fd82c4c4Schristos #  endif
1493*fd82c4c4Schristos _GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)
1494*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((2)));
1495*fd82c4c4Schristos _GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
1496*fd82c4c4Schristos # else
1497*fd82c4c4Schristos #  if !1
1498*fd82c4c4Schristos _GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)
1499*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((2)));
1500*fd82c4c4Schristos #  endif
1501*fd82c4c4Schristos _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
1502*fd82c4c4Schristos # endif
1503*fd82c4c4Schristos # if 1
1504*fd82c4c4Schristos _GL_CXXALIASWARN (strerror_r);
1505*fd82c4c4Schristos # endif
1506*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
1507*fd82c4c4Schristos # undef strerror_r
1508*fd82c4c4Schristos # if HAVE_RAW_DECL_STRERROR_R
1509*fd82c4c4Schristos _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
1510*fd82c4c4Schristos                  "use gnulib module strerror_r-posix for portability");
1511*fd82c4c4Schristos # endif
1512*fd82c4c4Schristos #endif
1513*fd82c4c4Schristos 
1514*fd82c4c4Schristos #if 0
1515*fd82c4c4Schristos # if 0
1516*fd82c4c4Schristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1517*fd82c4c4Schristos #   define strsignal rpl_strsignal
1518*fd82c4c4Schristos #  endif
1519*fd82c4c4Schristos _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
1520*fd82c4c4Schristos _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
1521*fd82c4c4Schristos # else
1522*fd82c4c4Schristos #  if ! 1
1523*fd82c4c4Schristos _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
1524*fd82c4c4Schristos #  endif
1525*fd82c4c4Schristos /* Need to cast, because on Cygwin 1.5.x systems, the return type is
1526*fd82c4c4Schristos    'const char *'.  */
1527*fd82c4c4Schristos _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
1528*fd82c4c4Schristos # endif
1529*fd82c4c4Schristos _GL_CXXALIASWARN (strsignal);
1530*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
1531*fd82c4c4Schristos # undef strsignal
1532*fd82c4c4Schristos # if HAVE_RAW_DECL_STRSIGNAL
1533*fd82c4c4Schristos _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
1534*fd82c4c4Schristos                  "use gnulib module strsignal for portability");
1535*fd82c4c4Schristos # endif
1536*fd82c4c4Schristos #endif
1537*fd82c4c4Schristos 
1538*fd82c4c4Schristos #if 0
1539*fd82c4c4Schristos # if !1
1540*fd82c4c4Schristos _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
1541*fd82c4c4Schristos                                    _GL_ATTRIBUTE_PURE
1542*fd82c4c4Schristos                                    _GL_ARG_NONNULL ((1, 2)));
1543*fd82c4c4Schristos # endif
1544*fd82c4c4Schristos _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
1545*fd82c4c4Schristos _GL_CXXALIASWARN (strverscmp);
1546*fd82c4c4Schristos #elif defined GNULIB_POSIXCHECK
1547*fd82c4c4Schristos # undef strverscmp
1548*fd82c4c4Schristos # if HAVE_RAW_DECL_STRVERSCMP
1549*fd82c4c4Schristos _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
1550*fd82c4c4Schristos                  "use gnulib module strverscmp for portability");
1551*fd82c4c4Schristos # endif
1552*fd82c4c4Schristos #endif
1553*fd82c4c4Schristos 
1554*fd82c4c4Schristos 
1555*fd82c4c4Schristos #endif /* _GL_STRING_H */
1556*fd82c4c4Schristos #endif /* _GL_STRING_H */
1557*fd82c4c4Schristos #endif
1558