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