151ddd709SJohn Marino /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ 251ddd709SJohn Marino /* A GNU-like <string.h>. 351ddd709SJohn Marino 4*4ce1b016SDaniel Fojt Copyright (C) 1995-1996, 2001-2020 Free Software Foundation, Inc. 551ddd709SJohn Marino 651ddd709SJohn Marino This program is free software; you can redistribute it and/or modify 751ddd709SJohn Marino it under the terms of the GNU General Public License as published by 851ddd709SJohn Marino the Free Software Foundation; either version 3, or (at your option) 951ddd709SJohn Marino any later version. 1051ddd709SJohn Marino 1151ddd709SJohn Marino This program is distributed in the hope that it will be useful, 1251ddd709SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 1351ddd709SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1451ddd709SJohn Marino GNU General Public License for more details. 1551ddd709SJohn Marino 1651ddd709SJohn Marino You should have received a copy of the GNU General Public License 17*4ce1b016SDaniel Fojt along with this program; if not, see <https://www.gnu.org/licenses/>. */ 1851ddd709SJohn Marino 1951ddd709SJohn Marino #if __GNUC__ >= 3 2051ddd709SJohn Marino #pragma GCC system_header 2151ddd709SJohn Marino #endif 2251ddd709SJohn Marino 2351ddd709SJohn Marino 24cf51209aSJohn Marino #if defined _GL_ALREADY_INCLUDING_STRING_H 25cf51209aSJohn Marino /* Special invocation convention: 26cf51209aSJohn Marino - On OS X/NetBSD we have a sequence of nested includes 27cf51209aSJohn Marino <string.h> -> <strings.h> -> "string.h" 28cf51209aSJohn Marino In this situation system _chk variants due to -D_FORTIFY_SOURCE 29cf51209aSJohn Marino might be used after any replacements defined here. */ 30cf51209aSJohn Marino 31cf51209aSJohn Marino #include_next <string.h> 32cf51209aSJohn Marino 33cf51209aSJohn Marino #else 34cf51209aSJohn Marino /* Normal invocation convention. */ 35cf51209aSJohn Marino 36cf51209aSJohn Marino #ifndef _GL_STRING_H 37cf51209aSJohn Marino 38cf51209aSJohn Marino #define _GL_ALREADY_INCLUDING_STRING_H 39cf51209aSJohn Marino 4051ddd709SJohn Marino /* The include_next requires a split double-inclusion guard. */ 4151ddd709SJohn Marino #include_next <string.h> 4251ddd709SJohn Marino 43cf51209aSJohn Marino #undef _GL_ALREADY_INCLUDING_STRING_H 44cf51209aSJohn Marino 4551ddd709SJohn Marino #ifndef _GL_STRING_H 4651ddd709SJohn Marino #define _GL_STRING_H 4751ddd709SJohn Marino 4851ddd709SJohn Marino /* NetBSD 5.0 mis-defines NULL. */ 4951ddd709SJohn Marino #include <stddef.h> 5051ddd709SJohn Marino 5151ddd709SJohn Marino /* MirBSD defines mbslen as a macro. */ 5251ddd709SJohn Marino #if 1 && defined __MirBSD__ 5351ddd709SJohn Marino # include <wchar.h> 5451ddd709SJohn Marino #endif 5551ddd709SJohn Marino 5651ddd709SJohn Marino /* The __attribute__ feature is available in gcc versions 2.5 and later. 5751ddd709SJohn Marino The attribute __pure__ was added in gcc 2.96. */ 5851ddd709SJohn Marino #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) 5951ddd709SJohn Marino # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) 6051ddd709SJohn Marino #else 6151ddd709SJohn Marino # define _GL_ATTRIBUTE_PURE /* empty */ 6251ddd709SJohn Marino #endif 6351ddd709SJohn Marino 6451ddd709SJohn Marino /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */ 6551ddd709SJohn Marino /* But in any case avoid namespace pollution on glibc systems. */ 6651ddd709SJohn Marino #if (0 || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \ 6751ddd709SJohn Marino && ! defined __GLIBC__ 6851ddd709SJohn Marino # include <unistd.h> 6951ddd709SJohn Marino #endif 7051ddd709SJohn Marino 7151ddd709SJohn Marino /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 72*4ce1b016SDaniel Fojt /* C++ compatible function declaration macros. 73*4ce1b016SDaniel Fojt Copyright (C) 2010-2020 Free Software Foundation, Inc. 74*4ce1b016SDaniel Fojt 75*4ce1b016SDaniel Fojt This program is free software: you can redistribute it and/or modify it 76*4ce1b016SDaniel Fojt under the terms of the GNU General Public License as published 77*4ce1b016SDaniel Fojt by the Free Software Foundation; either version 3 of the License, or 78*4ce1b016SDaniel Fojt (at your option) any later version. 79*4ce1b016SDaniel Fojt 80*4ce1b016SDaniel Fojt This program is distributed in the hope that it will be useful, 81*4ce1b016SDaniel Fojt but WITHOUT ANY WARRANTY; without even the implied warranty of 82*4ce1b016SDaniel Fojt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 83*4ce1b016SDaniel Fojt General Public License for more details. 84*4ce1b016SDaniel Fojt 85*4ce1b016SDaniel Fojt You should have received a copy of the GNU General Public License 86*4ce1b016SDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 87*4ce1b016SDaniel Fojt 8851ddd709SJohn Marino #ifndef _GL_CXXDEFS_H 8951ddd709SJohn Marino #define _GL_CXXDEFS_H 9051ddd709SJohn Marino 91*4ce1b016SDaniel Fojt /* Begin/end the GNULIB_NAMESPACE namespace. */ 92*4ce1b016SDaniel Fojt #if defined __cplusplus && defined GNULIB_NAMESPACE 93*4ce1b016SDaniel Fojt # define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE { 94*4ce1b016SDaniel Fojt # define _GL_END_NAMESPACE } 95*4ce1b016SDaniel Fojt #else 96*4ce1b016SDaniel Fojt # define _GL_BEGIN_NAMESPACE 97*4ce1b016SDaniel Fojt # define _GL_END_NAMESPACE 98*4ce1b016SDaniel Fojt #endif 99*4ce1b016SDaniel Fojt 10051ddd709SJohn Marino /* The three most frequent use cases of these macros are: 10151ddd709SJohn Marino 10251ddd709SJohn Marino * For providing a substitute for a function that is missing on some 10351ddd709SJohn Marino platforms, but is declared and works fine on the platforms on which 10451ddd709SJohn Marino it exists: 10551ddd709SJohn Marino 10651ddd709SJohn Marino #if @GNULIB_FOO@ 10751ddd709SJohn Marino # if !@HAVE_FOO@ 10851ddd709SJohn Marino _GL_FUNCDECL_SYS (foo, ...); 10951ddd709SJohn Marino # endif 11051ddd709SJohn Marino _GL_CXXALIAS_SYS (foo, ...); 11151ddd709SJohn Marino _GL_CXXALIASWARN (foo); 11251ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 11351ddd709SJohn Marino ... 11451ddd709SJohn Marino #endif 11551ddd709SJohn Marino 11651ddd709SJohn Marino * For providing a replacement for a function that exists on all platforms, 11751ddd709SJohn Marino but is broken/insufficient and needs to be replaced on some platforms: 11851ddd709SJohn Marino 11951ddd709SJohn Marino #if @GNULIB_FOO@ 12051ddd709SJohn Marino # if @REPLACE_FOO@ 12151ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 12251ddd709SJohn Marino # undef foo 12351ddd709SJohn Marino # define foo rpl_foo 12451ddd709SJohn Marino # endif 12551ddd709SJohn Marino _GL_FUNCDECL_RPL (foo, ...); 12651ddd709SJohn Marino _GL_CXXALIAS_RPL (foo, ...); 12751ddd709SJohn Marino # else 12851ddd709SJohn Marino _GL_CXXALIAS_SYS (foo, ...); 12951ddd709SJohn Marino # endif 13051ddd709SJohn Marino _GL_CXXALIASWARN (foo); 13151ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 13251ddd709SJohn Marino ... 13351ddd709SJohn Marino #endif 13451ddd709SJohn Marino 13551ddd709SJohn Marino * For providing a replacement for a function that exists on some platforms 13651ddd709SJohn Marino but is broken/insufficient and needs to be replaced on some of them and 13751ddd709SJohn Marino is additionally either missing or undeclared on some other platforms: 13851ddd709SJohn Marino 13951ddd709SJohn Marino #if @GNULIB_FOO@ 14051ddd709SJohn Marino # if @REPLACE_FOO@ 14151ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 14251ddd709SJohn Marino # undef foo 14351ddd709SJohn Marino # define foo rpl_foo 14451ddd709SJohn Marino # endif 14551ddd709SJohn Marino _GL_FUNCDECL_RPL (foo, ...); 14651ddd709SJohn Marino _GL_CXXALIAS_RPL (foo, ...); 14751ddd709SJohn Marino # else 14851ddd709SJohn Marino # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@ 14951ddd709SJohn Marino _GL_FUNCDECL_SYS (foo, ...); 15051ddd709SJohn Marino # endif 15151ddd709SJohn Marino _GL_CXXALIAS_SYS (foo, ...); 15251ddd709SJohn Marino # endif 15351ddd709SJohn Marino _GL_CXXALIASWARN (foo); 15451ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 15551ddd709SJohn Marino ... 15651ddd709SJohn Marino #endif 15751ddd709SJohn Marino */ 15851ddd709SJohn Marino 15951ddd709SJohn Marino /* _GL_EXTERN_C declaration; 16051ddd709SJohn Marino performs the declaration with C linkage. */ 16151ddd709SJohn Marino #if defined __cplusplus 16251ddd709SJohn Marino # define _GL_EXTERN_C extern "C" 16351ddd709SJohn Marino #else 16451ddd709SJohn Marino # define _GL_EXTERN_C extern 16551ddd709SJohn Marino #endif 16651ddd709SJohn Marino 16751ddd709SJohn Marino /* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes); 16851ddd709SJohn Marino declares a replacement function, named rpl_func, with the given prototype, 16951ddd709SJohn Marino consisting of return type, parameters, and attributes. 17051ddd709SJohn Marino Example: 17151ddd709SJohn Marino _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...) 17251ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 17351ddd709SJohn Marino */ 17451ddd709SJohn Marino #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \ 17551ddd709SJohn Marino _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes) 17651ddd709SJohn Marino #define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \ 17751ddd709SJohn Marino _GL_EXTERN_C rettype rpl_func parameters_and_attributes 17851ddd709SJohn Marino 17951ddd709SJohn Marino /* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes); 18051ddd709SJohn Marino declares the system function, named func, with the given prototype, 18151ddd709SJohn Marino consisting of return type, parameters, and attributes. 18251ddd709SJohn Marino Example: 18351ddd709SJohn Marino _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...) 18451ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 18551ddd709SJohn Marino */ 18651ddd709SJohn Marino #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \ 18751ddd709SJohn Marino _GL_EXTERN_C rettype func parameters_and_attributes 18851ddd709SJohn Marino 18951ddd709SJohn Marino /* _GL_CXXALIAS_RPL (func, rettype, parameters); 19051ddd709SJohn Marino declares a C++ alias called GNULIB_NAMESPACE::func 19151ddd709SJohn Marino that redirects to rpl_func, if GNULIB_NAMESPACE is defined. 19251ddd709SJohn Marino Example: 19351ddd709SJohn Marino _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...)); 194*4ce1b016SDaniel Fojt 195*4ce1b016SDaniel Fojt Wrapping rpl_func in an object with an inline conversion operator 196*4ce1b016SDaniel Fojt avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is 197*4ce1b016SDaniel Fojt actually used in the program. */ 19851ddd709SJohn Marino #define _GL_CXXALIAS_RPL(func,rettype,parameters) \ 19951ddd709SJohn Marino _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters) 20051ddd709SJohn Marino #if defined __cplusplus && defined GNULIB_NAMESPACE 20151ddd709SJohn Marino # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ 20251ddd709SJohn Marino namespace GNULIB_NAMESPACE \ 20351ddd709SJohn Marino { \ 204*4ce1b016SDaniel Fojt static const struct _gl_ ## func ## _wrapper \ 205*4ce1b016SDaniel Fojt { \ 206*4ce1b016SDaniel Fojt typedef rettype (*type) parameters; \ 207*4ce1b016SDaniel Fojt \ 208*4ce1b016SDaniel Fojt inline operator type () const \ 209*4ce1b016SDaniel Fojt { \ 210*4ce1b016SDaniel Fojt return ::rpl_func; \ 211*4ce1b016SDaniel Fojt } \ 212*4ce1b016SDaniel Fojt } func = {}; \ 21351ddd709SJohn Marino } \ 21451ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 21551ddd709SJohn Marino #else 21651ddd709SJohn Marino # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ 21751ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 21851ddd709SJohn Marino #endif 21951ddd709SJohn Marino 22051ddd709SJohn Marino /* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters); 22151ddd709SJohn Marino is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters); 22251ddd709SJohn Marino except that the C function rpl_func may have a slightly different 22351ddd709SJohn Marino declaration. A cast is used to silence the "invalid conversion" error 22451ddd709SJohn Marino that would otherwise occur. */ 22551ddd709SJohn Marino #if defined __cplusplus && defined GNULIB_NAMESPACE 22651ddd709SJohn Marino # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ 22751ddd709SJohn Marino namespace GNULIB_NAMESPACE \ 22851ddd709SJohn Marino { \ 229*4ce1b016SDaniel Fojt static const struct _gl_ ## func ## _wrapper \ 230*4ce1b016SDaniel Fojt { \ 231*4ce1b016SDaniel Fojt typedef rettype (*type) parameters; \ 232*4ce1b016SDaniel Fojt \ 233*4ce1b016SDaniel Fojt inline operator type () const \ 234*4ce1b016SDaniel Fojt { \ 235*4ce1b016SDaniel Fojt return reinterpret_cast<type>(::rpl_func); \ 236*4ce1b016SDaniel Fojt } \ 237*4ce1b016SDaniel Fojt } func = {}; \ 23851ddd709SJohn Marino } \ 23951ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 24051ddd709SJohn Marino #else 24151ddd709SJohn Marino # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ 24251ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 24351ddd709SJohn Marino #endif 24451ddd709SJohn Marino 24551ddd709SJohn Marino /* _GL_CXXALIAS_SYS (func, rettype, parameters); 24651ddd709SJohn Marino declares a C++ alias called GNULIB_NAMESPACE::func 24751ddd709SJohn Marino that redirects to the system provided function func, if GNULIB_NAMESPACE 24851ddd709SJohn Marino is defined. 24951ddd709SJohn Marino Example: 25051ddd709SJohn Marino _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...)); 251*4ce1b016SDaniel Fojt 252*4ce1b016SDaniel Fojt Wrapping func in an object with an inline conversion operator 253*4ce1b016SDaniel Fojt avoids a reference to func unless GNULIB_NAMESPACE::func is 254*4ce1b016SDaniel Fojt actually used in the program. */ 25551ddd709SJohn Marino #if defined __cplusplus && defined GNULIB_NAMESPACE 25651ddd709SJohn Marino # define _GL_CXXALIAS_SYS(func,rettype,parameters) \ 25751ddd709SJohn Marino namespace GNULIB_NAMESPACE \ 25851ddd709SJohn Marino { \ 259*4ce1b016SDaniel Fojt static const struct _gl_ ## func ## _wrapper \ 260*4ce1b016SDaniel Fojt { \ 261*4ce1b016SDaniel Fojt typedef rettype (*type) parameters; \ 262*4ce1b016SDaniel Fojt \ 263*4ce1b016SDaniel Fojt inline operator type () const \ 264*4ce1b016SDaniel Fojt { \ 265*4ce1b016SDaniel Fojt return ::func; \ 266*4ce1b016SDaniel Fojt } \ 267*4ce1b016SDaniel Fojt } func = {}; \ 26851ddd709SJohn Marino } \ 26951ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 27051ddd709SJohn Marino #else 27151ddd709SJohn Marino # define _GL_CXXALIAS_SYS(func,rettype,parameters) \ 27251ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 27351ddd709SJohn Marino #endif 27451ddd709SJohn Marino 27551ddd709SJohn Marino /* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters); 27651ddd709SJohn Marino is like _GL_CXXALIAS_SYS (func, rettype, parameters); 27751ddd709SJohn Marino except that the C function func may have a slightly different declaration. 27851ddd709SJohn Marino A cast is used to silence the "invalid conversion" error that would 27951ddd709SJohn Marino otherwise occur. */ 28051ddd709SJohn Marino #if defined __cplusplus && defined GNULIB_NAMESPACE 28151ddd709SJohn Marino # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ 28251ddd709SJohn Marino namespace GNULIB_NAMESPACE \ 28351ddd709SJohn Marino { \ 284*4ce1b016SDaniel Fojt static const struct _gl_ ## func ## _wrapper \ 285*4ce1b016SDaniel Fojt { \ 286*4ce1b016SDaniel Fojt typedef rettype (*type) parameters; \ 287*4ce1b016SDaniel Fojt \ 288*4ce1b016SDaniel Fojt inline operator type () const \ 289*4ce1b016SDaniel Fojt { \ 290*4ce1b016SDaniel Fojt return reinterpret_cast<type>(::func); \ 291*4ce1b016SDaniel Fojt } \ 292*4ce1b016SDaniel Fojt } func = {}; \ 29351ddd709SJohn Marino } \ 29451ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 29551ddd709SJohn Marino #else 29651ddd709SJohn Marino # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ 29751ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 29851ddd709SJohn Marino #endif 29951ddd709SJohn Marino 30051ddd709SJohn Marino /* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2); 30151ddd709SJohn Marino is like _GL_CXXALIAS_SYS (func, rettype, parameters); 30251ddd709SJohn Marino except that the C function is picked among a set of overloaded functions, 30351ddd709SJohn Marino namely the one with rettype2 and parameters2. Two consecutive casts 30451ddd709SJohn Marino are used to silence the "cannot find a match" and "invalid conversion" 30551ddd709SJohn Marino errors that would otherwise occur. */ 30651ddd709SJohn Marino #if defined __cplusplus && defined GNULIB_NAMESPACE 30751ddd709SJohn Marino /* The outer cast must be a reinterpret_cast. 30851ddd709SJohn Marino The inner cast: When the function is defined as a set of overloaded 30951ddd709SJohn Marino functions, it works as a static_cast<>, choosing the designated variant. 31051ddd709SJohn Marino When the function is defined as a single variant, it works as a 31151ddd709SJohn Marino reinterpret_cast<>. The parenthesized cast syntax works both ways. */ 31251ddd709SJohn Marino # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ 31351ddd709SJohn Marino namespace GNULIB_NAMESPACE \ 31451ddd709SJohn Marino { \ 315*4ce1b016SDaniel Fojt static const struct _gl_ ## func ## _wrapper \ 316*4ce1b016SDaniel Fojt { \ 317*4ce1b016SDaniel Fojt typedef rettype (*type) parameters; \ 318*4ce1b016SDaniel Fojt \ 319*4ce1b016SDaniel Fojt inline operator type () const \ 320*4ce1b016SDaniel Fojt { \ 321*4ce1b016SDaniel Fojt return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); \ 322*4ce1b016SDaniel Fojt } \ 323*4ce1b016SDaniel Fojt } func = {}; \ 32451ddd709SJohn Marino } \ 32551ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 32651ddd709SJohn Marino #else 32751ddd709SJohn Marino # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ 32851ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 32951ddd709SJohn Marino #endif 33051ddd709SJohn Marino 33151ddd709SJohn Marino /* _GL_CXXALIASWARN (func); 33251ddd709SJohn Marino causes a warning to be emitted when ::func is used but not when 33351ddd709SJohn Marino GNULIB_NAMESPACE::func is used. func must be defined without overloaded 33451ddd709SJohn Marino variants. */ 33551ddd709SJohn Marino #if defined __cplusplus && defined GNULIB_NAMESPACE 33651ddd709SJohn Marino # define _GL_CXXALIASWARN(func) \ 33751ddd709SJohn Marino _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE) 33851ddd709SJohn Marino # define _GL_CXXALIASWARN_1(func,namespace) \ 33951ddd709SJohn Marino _GL_CXXALIASWARN_2 (func, namespace) 340*4ce1b016SDaniel Fojt /* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>, 34151ddd709SJohn Marino we enable the warning only when not optimizing. */ 34251ddd709SJohn Marino # if !__OPTIMIZE__ 34351ddd709SJohn Marino # define _GL_CXXALIASWARN_2(func,namespace) \ 34451ddd709SJohn Marino _GL_WARN_ON_USE (func, \ 34551ddd709SJohn Marino "The symbol ::" #func " refers to the system function. " \ 34651ddd709SJohn Marino "Use " #namespace "::" #func " instead.") 34751ddd709SJohn Marino # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING 34851ddd709SJohn Marino # define _GL_CXXALIASWARN_2(func,namespace) \ 34951ddd709SJohn Marino extern __typeof__ (func) func 35051ddd709SJohn Marino # else 35151ddd709SJohn Marino # define _GL_CXXALIASWARN_2(func,namespace) \ 35251ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 35351ddd709SJohn Marino # endif 35451ddd709SJohn Marino #else 35551ddd709SJohn Marino # define _GL_CXXALIASWARN(func) \ 35651ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 35751ddd709SJohn Marino #endif 35851ddd709SJohn Marino 35951ddd709SJohn Marino /* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes); 36051ddd709SJohn Marino causes a warning to be emitted when the given overloaded variant of ::func 36151ddd709SJohn Marino is used but not when GNULIB_NAMESPACE::func is used. */ 36251ddd709SJohn Marino #if defined __cplusplus && defined GNULIB_NAMESPACE 36351ddd709SJohn Marino # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ 36451ddd709SJohn Marino _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \ 36551ddd709SJohn Marino GNULIB_NAMESPACE) 36651ddd709SJohn Marino # define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \ 36751ddd709SJohn Marino _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace) 368*4ce1b016SDaniel Fojt /* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>, 36951ddd709SJohn Marino we enable the warning only when not optimizing. */ 37051ddd709SJohn Marino # if !__OPTIMIZE__ 37151ddd709SJohn Marino # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ 37251ddd709SJohn Marino _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \ 37351ddd709SJohn Marino "The symbol ::" #func " refers to the system function. " \ 37451ddd709SJohn Marino "Use " #namespace "::" #func " instead.") 37551ddd709SJohn Marino # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING 37651ddd709SJohn Marino # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ 37751ddd709SJohn Marino extern __typeof__ (func) func 37851ddd709SJohn Marino # else 37951ddd709SJohn Marino # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ 38051ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 38151ddd709SJohn Marino # endif 38251ddd709SJohn Marino #else 38351ddd709SJohn Marino # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ 38451ddd709SJohn Marino _GL_EXTERN_C int _gl_cxxalias_dummy 38551ddd709SJohn Marino #endif 38651ddd709SJohn Marino 38751ddd709SJohn Marino #endif /* _GL_CXXDEFS_H */ 38851ddd709SJohn Marino 38951ddd709SJohn Marino /* The definition of _GL_ARG_NONNULL is copied here. */ 390*4ce1b016SDaniel Fojt /* A C macro for declaring that specific arguments must not be NULL. 391*4ce1b016SDaniel Fojt Copyright (C) 2009-2020 Free Software Foundation, Inc. 392*4ce1b016SDaniel Fojt 393*4ce1b016SDaniel Fojt This program is free software: you can redistribute it and/or modify it 394*4ce1b016SDaniel Fojt under the terms of the GNU General Public License as published 395*4ce1b016SDaniel Fojt by the Free Software Foundation; either version 3 of the License, or 396*4ce1b016SDaniel Fojt (at your option) any later version. 397*4ce1b016SDaniel Fojt 398*4ce1b016SDaniel Fojt This program is distributed in the hope that it will be useful, 399*4ce1b016SDaniel Fojt but WITHOUT ANY WARRANTY; without even the implied warranty of 400*4ce1b016SDaniel Fojt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 401*4ce1b016SDaniel Fojt General Public License for more details. 402*4ce1b016SDaniel Fojt 403*4ce1b016SDaniel Fojt You should have received a copy of the GNU General Public License 404*4ce1b016SDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 405*4ce1b016SDaniel Fojt 40651ddd709SJohn Marino /* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools 40751ddd709SJohn Marino that the values passed as arguments n, ..., m must be non-NULL pointers. 40851ddd709SJohn Marino n = 1 stands for the first argument, n = 2 for the second argument etc. */ 40951ddd709SJohn Marino #ifndef _GL_ARG_NONNULL 41051ddd709SJohn Marino # if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 41151ddd709SJohn Marino # define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) 41251ddd709SJohn Marino # else 41351ddd709SJohn Marino # define _GL_ARG_NONNULL(params) 41451ddd709SJohn Marino # endif 41551ddd709SJohn Marino #endif 41651ddd709SJohn Marino 41751ddd709SJohn Marino /* The definition of _GL_WARN_ON_USE is copied here. */ 418*4ce1b016SDaniel Fojt /* A C macro for emitting warnings if a function is used. 419*4ce1b016SDaniel Fojt Copyright (C) 2010-2020 Free Software Foundation, Inc. 420*4ce1b016SDaniel Fojt 421*4ce1b016SDaniel Fojt This program is free software: you can redistribute it and/or modify it 422*4ce1b016SDaniel Fojt under the terms of the GNU General Public License as published 423*4ce1b016SDaniel Fojt by the Free Software Foundation; either version 3 of the License, or 424*4ce1b016SDaniel Fojt (at your option) any later version. 425*4ce1b016SDaniel Fojt 426*4ce1b016SDaniel Fojt This program is distributed in the hope that it will be useful, 427*4ce1b016SDaniel Fojt but WITHOUT ANY WARRANTY; without even the implied warranty of 428*4ce1b016SDaniel Fojt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 429*4ce1b016SDaniel Fojt General Public License for more details. 430*4ce1b016SDaniel Fojt 431*4ce1b016SDaniel Fojt You should have received a copy of the GNU General Public License 432*4ce1b016SDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 433*4ce1b016SDaniel Fojt 434*4ce1b016SDaniel Fojt /* _GL_WARN_ON_USE (function, "literal string") issues a declaration 435*4ce1b016SDaniel Fojt for FUNCTION which will then trigger a compiler warning containing 436*4ce1b016SDaniel Fojt the text of "literal string" anywhere that function is called, if 437*4ce1b016SDaniel Fojt supported by the compiler. If the compiler does not support this 438*4ce1b016SDaniel Fojt feature, the macro expands to an unused extern declaration. 439*4ce1b016SDaniel Fojt 440*4ce1b016SDaniel Fojt _GL_WARN_ON_USE_ATTRIBUTE ("literal string") expands to the 441*4ce1b016SDaniel Fojt attribute used in _GL_WARN_ON_USE. If the compiler does not support 442*4ce1b016SDaniel Fojt this feature, it expands to empty. 443*4ce1b016SDaniel Fojt 444*4ce1b016SDaniel Fojt These macros are useful for marking a function as a potential 445*4ce1b016SDaniel Fojt portability trap, with the intent that "literal string" include 446*4ce1b016SDaniel Fojt instructions on the replacement function that should be used 447*4ce1b016SDaniel Fojt instead. 448*4ce1b016SDaniel Fojt _GL_WARN_ON_USE is for functions with 'extern' linkage. 449*4ce1b016SDaniel Fojt _GL_WARN_ON_USE_ATTRIBUTE is for functions with 'static' or 'inline' 450*4ce1b016SDaniel Fojt linkage. 451*4ce1b016SDaniel Fojt 452*4ce1b016SDaniel Fojt However, one of the reasons that a function is a portability trap is 453*4ce1b016SDaniel Fojt if it has the wrong signature. Declaring FUNCTION with a different 454*4ce1b016SDaniel Fojt signature in C is a compilation error, so this macro must use the 455*4ce1b016SDaniel Fojt same type as any existing declaration so that programs that avoid 456*4ce1b016SDaniel Fojt the problematic FUNCTION do not fail to compile merely because they 457*4ce1b016SDaniel Fojt included a header that poisoned the function. But this implies that 458*4ce1b016SDaniel Fojt _GL_WARN_ON_USE is only safe to use if FUNCTION is known to already 459*4ce1b016SDaniel Fojt have a declaration. Use of this macro implies that there must not 460*4ce1b016SDaniel Fojt be any other macro hiding the declaration of FUNCTION; but 461*4ce1b016SDaniel Fojt undefining FUNCTION first is part of the poisoning process anyway 462*4ce1b016SDaniel Fojt (although for symbols that are provided only via a macro, the result 463*4ce1b016SDaniel Fojt is a compilation error rather than a warning containing 464*4ce1b016SDaniel Fojt "literal string"). Also note that in C++, it is only safe to use if 465*4ce1b016SDaniel Fojt FUNCTION has no overloads. 466*4ce1b016SDaniel Fojt 467*4ce1b016SDaniel Fojt For an example, it is possible to poison 'getline' by: 468*4ce1b016SDaniel Fojt - adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]], 469*4ce1b016SDaniel Fojt [getline]) in configure.ac, which potentially defines 470*4ce1b016SDaniel Fojt HAVE_RAW_DECL_GETLINE 471*4ce1b016SDaniel Fojt - adding this code to a header that wraps the system <stdio.h>: 472*4ce1b016SDaniel Fojt #undef getline 473*4ce1b016SDaniel Fojt #if HAVE_RAW_DECL_GETLINE 474*4ce1b016SDaniel Fojt _GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but" 475*4ce1b016SDaniel Fojt "not universally present; use the gnulib module getline"); 476*4ce1b016SDaniel Fojt #endif 477*4ce1b016SDaniel Fojt 478*4ce1b016SDaniel Fojt It is not possible to directly poison global variables. But it is 479*4ce1b016SDaniel Fojt possible to write a wrapper accessor function, and poison that 480*4ce1b016SDaniel Fojt (less common usage, like &environ, will cause a compilation error 481*4ce1b016SDaniel Fojt rather than issue the nice warning, but the end result of informing 482*4ce1b016SDaniel Fojt the developer about their portability problem is still achieved): 483*4ce1b016SDaniel Fojt #if HAVE_RAW_DECL_ENVIRON 484*4ce1b016SDaniel Fojt static char *** 485*4ce1b016SDaniel Fojt rpl_environ (void) { return &environ; } 486*4ce1b016SDaniel Fojt _GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared"); 487*4ce1b016SDaniel Fojt # undef environ 488*4ce1b016SDaniel Fojt # define environ (*rpl_environ ()) 489*4ce1b016SDaniel Fojt #endif 490*4ce1b016SDaniel Fojt or better (avoiding contradictory use of 'static' and 'extern'): 491*4ce1b016SDaniel Fojt #if HAVE_RAW_DECL_ENVIRON 492*4ce1b016SDaniel Fojt static char *** 493*4ce1b016SDaniel Fojt _GL_WARN_ON_USE_ATTRIBUTE ("environ is not always properly declared") 494*4ce1b016SDaniel Fojt rpl_environ (void) { return &environ; } 495*4ce1b016SDaniel Fojt # undef environ 496*4ce1b016SDaniel Fojt # define environ (*rpl_environ ()) 497*4ce1b016SDaniel Fojt #endif 498*4ce1b016SDaniel Fojt */ 49951ddd709SJohn Marino #ifndef _GL_WARN_ON_USE 50051ddd709SJohn Marino 50151ddd709SJohn Marino # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) 50251ddd709SJohn Marino /* A compiler attribute is available in gcc versions 4.3.0 and later. */ 50351ddd709SJohn Marino # define _GL_WARN_ON_USE(function, message) \ 50451ddd709SJohn Marino extern __typeof__ (function) function __attribute__ ((__warning__ (message))) 505*4ce1b016SDaniel Fojt # define _GL_WARN_ON_USE_ATTRIBUTE(message) \ 506*4ce1b016SDaniel Fojt __attribute__ ((__warning__ (message))) 50751ddd709SJohn Marino # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING 50851ddd709SJohn Marino /* Verify the existence of the function. */ 50951ddd709SJohn Marino # define _GL_WARN_ON_USE(function, message) \ 51051ddd709SJohn Marino extern __typeof__ (function) function 511*4ce1b016SDaniel Fojt # define _GL_WARN_ON_USE_ATTRIBUTE(message) 51251ddd709SJohn Marino # else /* Unsupported. */ 51351ddd709SJohn Marino # define _GL_WARN_ON_USE(function, message) \ 51451ddd709SJohn Marino _GL_WARN_EXTERN_C int _gl_warn_on_use 515*4ce1b016SDaniel Fojt # define _GL_WARN_ON_USE_ATTRIBUTE(message) 51651ddd709SJohn Marino # endif 51751ddd709SJohn Marino #endif 51851ddd709SJohn Marino 51951ddd709SJohn Marino /* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string") 52051ddd709SJohn Marino is like _GL_WARN_ON_USE (function, "string"), except that the function is 52151ddd709SJohn Marino declared with the given prototype, consisting of return type, parameters, 52251ddd709SJohn Marino and attributes. 52351ddd709SJohn Marino This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does 52451ddd709SJohn Marino not work in this case. */ 52551ddd709SJohn Marino #ifndef _GL_WARN_ON_USE_CXX 52651ddd709SJohn Marino # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) 52751ddd709SJohn Marino # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ 52851ddd709SJohn Marino extern rettype function parameters_and_attributes \ 52951ddd709SJohn Marino __attribute__ ((__warning__ (msg))) 53051ddd709SJohn Marino # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING 53151ddd709SJohn Marino /* Verify the existence of the function. */ 53251ddd709SJohn Marino # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ 53351ddd709SJohn Marino extern rettype function parameters_and_attributes 53451ddd709SJohn Marino # else /* Unsupported. */ 53551ddd709SJohn Marino # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ 53651ddd709SJohn Marino _GL_WARN_EXTERN_C int _gl_warn_on_use 53751ddd709SJohn Marino # endif 53851ddd709SJohn Marino #endif 53951ddd709SJohn Marino 54051ddd709SJohn Marino /* _GL_WARN_EXTERN_C declaration; 54151ddd709SJohn Marino performs the declaration with C linkage. */ 54251ddd709SJohn Marino #ifndef _GL_WARN_EXTERN_C 54351ddd709SJohn Marino # if defined __cplusplus 54451ddd709SJohn Marino # define _GL_WARN_EXTERN_C extern "C" 54551ddd709SJohn Marino # else 54651ddd709SJohn Marino # define _GL_WARN_EXTERN_C extern 54751ddd709SJohn Marino # endif 54851ddd709SJohn Marino #endif 54951ddd709SJohn Marino 55051ddd709SJohn Marino 551*4ce1b016SDaniel Fojt /* Clear a block of memory. The compiler will not delete a call to 552*4ce1b016SDaniel Fojt this function, even if the block is dead after the call. */ 553*4ce1b016SDaniel Fojt #if 0 554*4ce1b016SDaniel Fojt # if ! 1 555*4ce1b016SDaniel Fojt _GL_FUNCDECL_SYS (explicit_bzero, void, 556*4ce1b016SDaniel Fojt (void *__dest, size_t __n) _GL_ARG_NONNULL ((1))); 557*4ce1b016SDaniel Fojt # endif 558*4ce1b016SDaniel Fojt _GL_CXXALIAS_SYS (explicit_bzero, void, (void *__dest, size_t __n)); 559*4ce1b016SDaniel Fojt _GL_CXXALIASWARN (explicit_bzero); 560*4ce1b016SDaniel Fojt #elif defined GNULIB_POSIXCHECK 561*4ce1b016SDaniel Fojt # undef explicit_bzero 562*4ce1b016SDaniel Fojt # if HAVE_RAW_DECL_EXPLICIT_BZERO 563*4ce1b016SDaniel Fojt _GL_WARN_ON_USE (explicit_bzero, "explicit_bzero is unportable - " 564*4ce1b016SDaniel Fojt "use gnulib module explicit_bzero for portability"); 565*4ce1b016SDaniel Fojt # endif 566*4ce1b016SDaniel Fojt #endif 567*4ce1b016SDaniel Fojt 56851ddd709SJohn Marino /* Find the index of the least-significant set bit. */ 56951ddd709SJohn Marino #if 0 57051ddd709SJohn Marino # if !1 57151ddd709SJohn Marino _GL_FUNCDECL_SYS (ffsl, int, (long int i)); 57251ddd709SJohn Marino # endif 57351ddd709SJohn Marino _GL_CXXALIAS_SYS (ffsl, int, (long int i)); 57451ddd709SJohn Marino _GL_CXXALIASWARN (ffsl); 57551ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 57651ddd709SJohn Marino # undef ffsl 57751ddd709SJohn Marino # if HAVE_RAW_DECL_FFSL 57851ddd709SJohn Marino _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module"); 57951ddd709SJohn Marino # endif 58051ddd709SJohn Marino #endif 58151ddd709SJohn Marino 58251ddd709SJohn Marino 58351ddd709SJohn Marino /* Find the index of the least-significant set bit. */ 58451ddd709SJohn Marino #if 0 58551ddd709SJohn Marino # if !1 58651ddd709SJohn Marino _GL_FUNCDECL_SYS (ffsll, int, (long long int i)); 58751ddd709SJohn Marino # endif 58851ddd709SJohn Marino _GL_CXXALIAS_SYS (ffsll, int, (long long int i)); 58951ddd709SJohn Marino _GL_CXXALIASWARN (ffsll); 59051ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 59151ddd709SJohn Marino # undef ffsll 59251ddd709SJohn Marino # if HAVE_RAW_DECL_FFSLL 59351ddd709SJohn Marino _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module"); 59451ddd709SJohn Marino # endif 59551ddd709SJohn Marino #endif 59651ddd709SJohn Marino 59751ddd709SJohn Marino 59851ddd709SJohn Marino /* Return the first instance of C within N bytes of S, or NULL. */ 59951ddd709SJohn Marino #if 1 60051ddd709SJohn Marino # if 0 60151ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 60251ddd709SJohn Marino # define memchr rpl_memchr 60351ddd709SJohn Marino # endif 60451ddd709SJohn Marino _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n) 60551ddd709SJohn Marino _GL_ATTRIBUTE_PURE 60651ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 60751ddd709SJohn Marino _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n)); 60851ddd709SJohn Marino # else 60951ddd709SJohn Marino # if ! 1 61051ddd709SJohn Marino _GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n) 61151ddd709SJohn Marino _GL_ATTRIBUTE_PURE 61251ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 61351ddd709SJohn Marino # endif 61451ddd709SJohn Marino /* On some systems, this function is defined as an overloaded function: 61551ddd709SJohn Marino extern "C" { const void * std::memchr (const void *, int, size_t); } 61651ddd709SJohn Marino extern "C++" { void * std::memchr (void *, int, size_t); } */ 61751ddd709SJohn Marino _GL_CXXALIAS_SYS_CAST2 (memchr, 61851ddd709SJohn Marino void *, (void const *__s, int __c, size_t __n), 61951ddd709SJohn Marino void const *, (void const *__s, int __c, size_t __n)); 62051ddd709SJohn Marino # endif 62151ddd709SJohn Marino # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 62251ddd709SJohn Marino && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 62351ddd709SJohn Marino _GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n)); 62451ddd709SJohn Marino _GL_CXXALIASWARN1 (memchr, void const *, 62551ddd709SJohn Marino (void const *__s, int __c, size_t __n)); 626*4ce1b016SDaniel Fojt # elif __GLIBC__ >= 2 62751ddd709SJohn Marino _GL_CXXALIASWARN (memchr); 62851ddd709SJohn Marino # endif 62951ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 63051ddd709SJohn Marino # undef memchr 63151ddd709SJohn Marino /* Assume memchr is always declared. */ 63251ddd709SJohn Marino _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - " 63351ddd709SJohn Marino "use gnulib module memchr for portability" ); 63451ddd709SJohn Marino #endif 63551ddd709SJohn Marino 63651ddd709SJohn Marino /* Return the first occurrence of NEEDLE in HAYSTACK. */ 63751ddd709SJohn Marino #if 0 63851ddd709SJohn Marino # if 0 63951ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 64051ddd709SJohn Marino # define memmem rpl_memmem 64151ddd709SJohn Marino # endif 64251ddd709SJohn Marino _GL_FUNCDECL_RPL (memmem, void *, 64351ddd709SJohn Marino (void const *__haystack, size_t __haystack_len, 64451ddd709SJohn Marino void const *__needle, size_t __needle_len) 64551ddd709SJohn Marino _GL_ATTRIBUTE_PURE 64651ddd709SJohn Marino _GL_ARG_NONNULL ((1, 3))); 64751ddd709SJohn Marino _GL_CXXALIAS_RPL (memmem, void *, 64851ddd709SJohn Marino (void const *__haystack, size_t __haystack_len, 64951ddd709SJohn Marino void const *__needle, size_t __needle_len)); 65051ddd709SJohn Marino # else 65151ddd709SJohn Marino # if ! 1 65251ddd709SJohn Marino _GL_FUNCDECL_SYS (memmem, void *, 65351ddd709SJohn Marino (void const *__haystack, size_t __haystack_len, 65451ddd709SJohn Marino void const *__needle, size_t __needle_len) 65551ddd709SJohn Marino _GL_ATTRIBUTE_PURE 65651ddd709SJohn Marino _GL_ARG_NONNULL ((1, 3))); 65751ddd709SJohn Marino # endif 65851ddd709SJohn Marino _GL_CXXALIAS_SYS (memmem, void *, 65951ddd709SJohn Marino (void const *__haystack, size_t __haystack_len, 66051ddd709SJohn Marino void const *__needle, size_t __needle_len)); 66151ddd709SJohn Marino # endif 66251ddd709SJohn Marino _GL_CXXALIASWARN (memmem); 66351ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 66451ddd709SJohn Marino # undef memmem 66551ddd709SJohn Marino # if HAVE_RAW_DECL_MEMMEM 66651ddd709SJohn Marino _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - " 66751ddd709SJohn Marino "use gnulib module memmem-simple for portability, " 66851ddd709SJohn Marino "and module memmem for speed" ); 66951ddd709SJohn Marino # endif 67051ddd709SJohn Marino #endif 67151ddd709SJohn Marino 67251ddd709SJohn Marino /* Copy N bytes of SRC to DEST, return pointer to bytes after the 67351ddd709SJohn Marino last written byte. */ 67451ddd709SJohn Marino #if 1 67551ddd709SJohn Marino # if ! 1 67651ddd709SJohn Marino _GL_FUNCDECL_SYS (mempcpy, void *, 67751ddd709SJohn Marino (void *restrict __dest, void const *restrict __src, 67851ddd709SJohn Marino size_t __n) 67951ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 68051ddd709SJohn Marino # endif 68151ddd709SJohn Marino _GL_CXXALIAS_SYS (mempcpy, void *, 68251ddd709SJohn Marino (void *restrict __dest, void const *restrict __src, 68351ddd709SJohn Marino size_t __n)); 68451ddd709SJohn Marino _GL_CXXALIASWARN (mempcpy); 68551ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 68651ddd709SJohn Marino # undef mempcpy 68751ddd709SJohn Marino # if HAVE_RAW_DECL_MEMPCPY 68851ddd709SJohn Marino _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - " 68951ddd709SJohn Marino "use gnulib module mempcpy for portability"); 69051ddd709SJohn Marino # endif 69151ddd709SJohn Marino #endif 69251ddd709SJohn Marino 69351ddd709SJohn Marino /* Search backwards through a block for a byte (specified as an int). */ 69451ddd709SJohn Marino #if 1 69551ddd709SJohn Marino # if ! 1 69651ddd709SJohn Marino _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t) 69751ddd709SJohn Marino _GL_ATTRIBUTE_PURE 69851ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 69951ddd709SJohn Marino # endif 70051ddd709SJohn Marino /* On some systems, this function is defined as an overloaded function: 70151ddd709SJohn Marino extern "C++" { const void * std::memrchr (const void *, int, size_t); } 70251ddd709SJohn Marino extern "C++" { void * std::memrchr (void *, int, size_t); } */ 70351ddd709SJohn Marino _GL_CXXALIAS_SYS_CAST2 (memrchr, 70451ddd709SJohn Marino void *, (void const *, int, size_t), 70551ddd709SJohn Marino void const *, (void const *, int, size_t)); 70651ddd709SJohn Marino # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 70751ddd709SJohn Marino && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 70851ddd709SJohn Marino _GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t)); 70951ddd709SJohn Marino _GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t)); 71051ddd709SJohn Marino # else 71151ddd709SJohn Marino _GL_CXXALIASWARN (memrchr); 71251ddd709SJohn Marino # endif 71351ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 71451ddd709SJohn Marino # undef memrchr 71551ddd709SJohn Marino # if HAVE_RAW_DECL_MEMRCHR 71651ddd709SJohn Marino _GL_WARN_ON_USE (memrchr, "memrchr is unportable - " 71751ddd709SJohn Marino "use gnulib module memrchr for portability"); 71851ddd709SJohn Marino # endif 71951ddd709SJohn Marino #endif 72051ddd709SJohn Marino 72151ddd709SJohn Marino /* Find the first occurrence of C in S. More efficient than 72251ddd709SJohn Marino memchr(S,C,N), at the expense of undefined behavior if C does not 72351ddd709SJohn Marino occur within N bytes. */ 72451ddd709SJohn Marino #if 0 72551ddd709SJohn Marino # if ! 1 72651ddd709SJohn Marino _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in) 72751ddd709SJohn Marino _GL_ATTRIBUTE_PURE 72851ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 72951ddd709SJohn Marino # endif 73051ddd709SJohn Marino /* On some systems, this function is defined as an overloaded function: 73151ddd709SJohn Marino extern "C++" { const void * std::rawmemchr (const void *, int); } 73251ddd709SJohn Marino extern "C++" { void * std::rawmemchr (void *, int); } */ 73351ddd709SJohn Marino _GL_CXXALIAS_SYS_CAST2 (rawmemchr, 73451ddd709SJohn Marino void *, (void const *__s, int __c_in), 73551ddd709SJohn Marino void const *, (void const *__s, int __c_in)); 73651ddd709SJohn Marino # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 73751ddd709SJohn Marino && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 73851ddd709SJohn Marino _GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in)); 73951ddd709SJohn Marino _GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in)); 74051ddd709SJohn Marino # else 74151ddd709SJohn Marino _GL_CXXALIASWARN (rawmemchr); 74251ddd709SJohn Marino # endif 74351ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 74451ddd709SJohn Marino # undef rawmemchr 74551ddd709SJohn Marino # if HAVE_RAW_DECL_RAWMEMCHR 74651ddd709SJohn Marino _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - " 74751ddd709SJohn Marino "use gnulib module rawmemchr for portability"); 74851ddd709SJohn Marino # endif 74951ddd709SJohn Marino #endif 75051ddd709SJohn Marino 75151ddd709SJohn Marino /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ 75251ddd709SJohn Marino #if 1 75351ddd709SJohn Marino # if ! 1 75451ddd709SJohn Marino _GL_FUNCDECL_SYS (stpcpy, char *, 75551ddd709SJohn Marino (char *restrict __dst, char const *restrict __src) 75651ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 75751ddd709SJohn Marino # endif 75851ddd709SJohn Marino _GL_CXXALIAS_SYS (stpcpy, char *, 75951ddd709SJohn Marino (char *restrict __dst, char const *restrict __src)); 76051ddd709SJohn Marino _GL_CXXALIASWARN (stpcpy); 76151ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 76251ddd709SJohn Marino # undef stpcpy 76351ddd709SJohn Marino # if HAVE_RAW_DECL_STPCPY 76451ddd709SJohn Marino _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - " 76551ddd709SJohn Marino "use gnulib module stpcpy for portability"); 76651ddd709SJohn Marino # endif 76751ddd709SJohn Marino #endif 76851ddd709SJohn Marino 76951ddd709SJohn Marino /* Copy no more than N bytes of SRC to DST, returning a pointer past the 77051ddd709SJohn Marino last non-NUL byte written into DST. */ 77151ddd709SJohn Marino #if 0 77251ddd709SJohn Marino # if 0 77351ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 77451ddd709SJohn Marino # undef stpncpy 77551ddd709SJohn Marino # define stpncpy rpl_stpncpy 77651ddd709SJohn Marino # endif 77751ddd709SJohn Marino _GL_FUNCDECL_RPL (stpncpy, char *, 77851ddd709SJohn Marino (char *restrict __dst, char const *restrict __src, 77951ddd709SJohn Marino size_t __n) 78051ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 78151ddd709SJohn Marino _GL_CXXALIAS_RPL (stpncpy, char *, 78251ddd709SJohn Marino (char *restrict __dst, char const *restrict __src, 78351ddd709SJohn Marino size_t __n)); 78451ddd709SJohn Marino # else 78551ddd709SJohn Marino # if ! 1 78651ddd709SJohn Marino _GL_FUNCDECL_SYS (stpncpy, char *, 78751ddd709SJohn Marino (char *restrict __dst, char const *restrict __src, 78851ddd709SJohn Marino size_t __n) 78951ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 79051ddd709SJohn Marino # endif 79151ddd709SJohn Marino _GL_CXXALIAS_SYS (stpncpy, char *, 79251ddd709SJohn Marino (char *restrict __dst, char const *restrict __src, 79351ddd709SJohn Marino size_t __n)); 79451ddd709SJohn Marino # endif 79551ddd709SJohn Marino _GL_CXXALIASWARN (stpncpy); 79651ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 79751ddd709SJohn Marino # undef stpncpy 79851ddd709SJohn Marino # if HAVE_RAW_DECL_STPNCPY 79951ddd709SJohn Marino _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - " 80051ddd709SJohn Marino "use gnulib module stpncpy for portability"); 80151ddd709SJohn Marino # endif 80251ddd709SJohn Marino #endif 80351ddd709SJohn Marino 80451ddd709SJohn Marino #if defined GNULIB_POSIXCHECK 80551ddd709SJohn Marino /* strchr() does not work with multibyte strings if the locale encoding is 80651ddd709SJohn Marino GB18030 and the character to be searched is a digit. */ 80751ddd709SJohn Marino # undef strchr 80851ddd709SJohn Marino /* Assume strchr is always declared. */ 80951ddd709SJohn Marino _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings " 81051ddd709SJohn Marino "in some multibyte locales - " 81151ddd709SJohn Marino "use mbschr if you care about internationalization"); 81251ddd709SJohn Marino #endif 81351ddd709SJohn Marino 81451ddd709SJohn Marino /* Find the first occurrence of C in S or the final NUL byte. */ 81551ddd709SJohn Marino #if 0 81651ddd709SJohn Marino # if 0 81751ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 81851ddd709SJohn Marino # define strchrnul rpl_strchrnul 81951ddd709SJohn Marino # endif 82051ddd709SJohn Marino _GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in) 82151ddd709SJohn Marino _GL_ATTRIBUTE_PURE 82251ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 82351ddd709SJohn Marino _GL_CXXALIAS_RPL (strchrnul, char *, 82451ddd709SJohn Marino (const char *str, int ch)); 82551ddd709SJohn Marino # else 82651ddd709SJohn Marino # if ! 1 82751ddd709SJohn Marino _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in) 82851ddd709SJohn Marino _GL_ATTRIBUTE_PURE 82951ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 83051ddd709SJohn Marino # endif 83151ddd709SJohn Marino /* On some systems, this function is defined as an overloaded function: 83251ddd709SJohn Marino extern "C++" { const char * std::strchrnul (const char *, int); } 83351ddd709SJohn Marino extern "C++" { char * std::strchrnul (char *, int); } */ 83451ddd709SJohn Marino _GL_CXXALIAS_SYS_CAST2 (strchrnul, 83551ddd709SJohn Marino char *, (char const *__s, int __c_in), 83651ddd709SJohn Marino char const *, (char const *__s, int __c_in)); 83751ddd709SJohn Marino # endif 83851ddd709SJohn Marino # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 83951ddd709SJohn Marino && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 84051ddd709SJohn Marino _GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in)); 84151ddd709SJohn Marino _GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in)); 84251ddd709SJohn Marino # else 84351ddd709SJohn Marino _GL_CXXALIASWARN (strchrnul); 84451ddd709SJohn Marino # endif 84551ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 84651ddd709SJohn Marino # undef strchrnul 84751ddd709SJohn Marino # if HAVE_RAW_DECL_STRCHRNUL 84851ddd709SJohn Marino _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - " 84951ddd709SJohn Marino "use gnulib module strchrnul for portability"); 85051ddd709SJohn Marino # endif 85151ddd709SJohn Marino #endif 85251ddd709SJohn Marino 85351ddd709SJohn Marino /* Duplicate S, returning an identical malloc'd string. */ 85451ddd709SJohn Marino #if 1 85551ddd709SJohn Marino # if 0 85651ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 85751ddd709SJohn Marino # undef strdup 85851ddd709SJohn Marino # define strdup rpl_strdup 85951ddd709SJohn Marino # endif 86051ddd709SJohn Marino _GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); 86151ddd709SJohn Marino _GL_CXXALIAS_RPL (strdup, char *, (char const *__s)); 86251ddd709SJohn Marino # else 86351ddd709SJohn Marino # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup 86451ddd709SJohn Marino /* strdup exists as a function and as a macro. Get rid of the macro. */ 86551ddd709SJohn Marino # undef strdup 86651ddd709SJohn Marino # endif 86751ddd709SJohn Marino # if !(1 || defined strdup) 86851ddd709SJohn Marino _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); 86951ddd709SJohn Marino # endif 87051ddd709SJohn Marino _GL_CXXALIAS_SYS (strdup, char *, (char const *__s)); 87151ddd709SJohn Marino # endif 87251ddd709SJohn Marino _GL_CXXALIASWARN (strdup); 87351ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 87451ddd709SJohn Marino # undef strdup 87551ddd709SJohn Marino # if HAVE_RAW_DECL_STRDUP 87651ddd709SJohn Marino _GL_WARN_ON_USE (strdup, "strdup is unportable - " 87751ddd709SJohn Marino "use gnulib module strdup for portability"); 87851ddd709SJohn Marino # endif 87951ddd709SJohn Marino #endif 88051ddd709SJohn Marino 88151ddd709SJohn Marino /* Append no more than N characters from SRC onto DEST. */ 88251ddd709SJohn Marino #if 0 88351ddd709SJohn Marino # if 0 88451ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 88551ddd709SJohn Marino # undef strncat 88651ddd709SJohn Marino # define strncat rpl_strncat 88751ddd709SJohn Marino # endif 88851ddd709SJohn Marino _GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n) 88951ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 89051ddd709SJohn Marino _GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n)); 89151ddd709SJohn Marino # else 89251ddd709SJohn Marino _GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n)); 89351ddd709SJohn Marino # endif 894*4ce1b016SDaniel Fojt # if __GLIBC__ >= 2 89551ddd709SJohn Marino _GL_CXXALIASWARN (strncat); 896*4ce1b016SDaniel Fojt # endif 89751ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 89851ddd709SJohn Marino # undef strncat 89951ddd709SJohn Marino # if HAVE_RAW_DECL_STRNCAT 90051ddd709SJohn Marino _GL_WARN_ON_USE (strncat, "strncat is unportable - " 90151ddd709SJohn Marino "use gnulib module strncat for portability"); 90251ddd709SJohn Marino # endif 90351ddd709SJohn Marino #endif 90451ddd709SJohn Marino 90551ddd709SJohn Marino /* Return a newly allocated copy of at most N bytes of STRING. */ 90651ddd709SJohn Marino #if 0 90751ddd709SJohn Marino # if 0 90851ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 90951ddd709SJohn Marino # undef strndup 91051ddd709SJohn Marino # define strndup rpl_strndup 91151ddd709SJohn Marino # endif 912*4ce1b016SDaniel Fojt _GL_FUNCDECL_RPL (strndup, char *, (char const *__s, size_t __n) 91351ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 914*4ce1b016SDaniel Fojt _GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n)); 91551ddd709SJohn Marino # else 91651ddd709SJohn Marino # if ! 1 917*4ce1b016SDaniel Fojt _GL_FUNCDECL_SYS (strndup, char *, (char const *__s, size_t __n) 91851ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 91951ddd709SJohn Marino # endif 920*4ce1b016SDaniel Fojt _GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n)); 92151ddd709SJohn Marino # endif 92251ddd709SJohn Marino _GL_CXXALIASWARN (strndup); 92351ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 92451ddd709SJohn Marino # undef strndup 92551ddd709SJohn Marino # if HAVE_RAW_DECL_STRNDUP 92651ddd709SJohn Marino _GL_WARN_ON_USE (strndup, "strndup is unportable - " 92751ddd709SJohn Marino "use gnulib module strndup for portability"); 92851ddd709SJohn Marino # endif 92951ddd709SJohn Marino #endif 93051ddd709SJohn Marino 93151ddd709SJohn Marino /* Find the length (number of bytes) of STRING, but scan at most 93251ddd709SJohn Marino MAXLEN bytes. If no '\0' terminator is found in that many bytes, 93351ddd709SJohn Marino return MAXLEN. */ 93451ddd709SJohn Marino #if 1 93551ddd709SJohn Marino # if 0 93651ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 93751ddd709SJohn Marino # undef strnlen 93851ddd709SJohn Marino # define strnlen rpl_strnlen 93951ddd709SJohn Marino # endif 940*4ce1b016SDaniel Fojt _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__s, size_t __maxlen) 94151ddd709SJohn Marino _GL_ATTRIBUTE_PURE 94251ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 943*4ce1b016SDaniel Fojt _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__s, size_t __maxlen)); 94451ddd709SJohn Marino # else 94551ddd709SJohn Marino # if ! 1 946*4ce1b016SDaniel Fojt _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__s, size_t __maxlen) 94751ddd709SJohn Marino _GL_ATTRIBUTE_PURE 94851ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 94951ddd709SJohn Marino # endif 950*4ce1b016SDaniel Fojt _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__s, size_t __maxlen)); 95151ddd709SJohn Marino # endif 95251ddd709SJohn Marino _GL_CXXALIASWARN (strnlen); 95351ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 95451ddd709SJohn Marino # undef strnlen 95551ddd709SJohn Marino # if HAVE_RAW_DECL_STRNLEN 95651ddd709SJohn Marino _GL_WARN_ON_USE (strnlen, "strnlen is unportable - " 95751ddd709SJohn Marino "use gnulib module strnlen for portability"); 95851ddd709SJohn Marino # endif 95951ddd709SJohn Marino #endif 96051ddd709SJohn Marino 96151ddd709SJohn Marino #if defined GNULIB_POSIXCHECK 96251ddd709SJohn Marino /* strcspn() assumes the second argument is a list of single-byte characters. 96351ddd709SJohn Marino Even in this simple case, it does not work with multibyte strings if the 96451ddd709SJohn Marino locale encoding is GB18030 and one of the characters to be searched is a 96551ddd709SJohn Marino digit. */ 96651ddd709SJohn Marino # undef strcspn 96751ddd709SJohn Marino /* Assume strcspn is always declared. */ 96851ddd709SJohn Marino _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings " 96951ddd709SJohn Marino "in multibyte locales - " 97051ddd709SJohn Marino "use mbscspn if you care about internationalization"); 97151ddd709SJohn Marino #endif 97251ddd709SJohn Marino 97351ddd709SJohn Marino /* Find the first occurrence in S of any character in ACCEPT. */ 97451ddd709SJohn Marino #if 0 97551ddd709SJohn Marino # if ! 1 97651ddd709SJohn Marino _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept) 97751ddd709SJohn Marino _GL_ATTRIBUTE_PURE 97851ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 97951ddd709SJohn Marino # endif 98051ddd709SJohn Marino /* On some systems, this function is defined as an overloaded function: 98151ddd709SJohn Marino extern "C" { const char * strpbrk (const char *, const char *); } 98251ddd709SJohn Marino extern "C++" { char * strpbrk (char *, const char *); } */ 98351ddd709SJohn Marino _GL_CXXALIAS_SYS_CAST2 (strpbrk, 98451ddd709SJohn Marino char *, (char const *__s, char const *__accept), 98551ddd709SJohn Marino const char *, (char const *__s, char const *__accept)); 98651ddd709SJohn Marino # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 98751ddd709SJohn Marino && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 98851ddd709SJohn Marino _GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept)); 98951ddd709SJohn Marino _GL_CXXALIASWARN1 (strpbrk, char const *, 99051ddd709SJohn Marino (char const *__s, char const *__accept)); 991*4ce1b016SDaniel Fojt # elif __GLIBC__ >= 2 99251ddd709SJohn Marino _GL_CXXALIASWARN (strpbrk); 99351ddd709SJohn Marino # endif 99451ddd709SJohn Marino # if defined GNULIB_POSIXCHECK 99551ddd709SJohn Marino /* strpbrk() assumes the second argument is a list of single-byte characters. 99651ddd709SJohn Marino Even in this simple case, it does not work with multibyte strings if the 99751ddd709SJohn Marino locale encoding is GB18030 and one of the characters to be searched is a 99851ddd709SJohn Marino digit. */ 99951ddd709SJohn Marino # undef strpbrk 100051ddd709SJohn Marino _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings " 100151ddd709SJohn Marino "in multibyte locales - " 100251ddd709SJohn Marino "use mbspbrk if you care about internationalization"); 100351ddd709SJohn Marino # endif 100451ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 100551ddd709SJohn Marino # undef strpbrk 100651ddd709SJohn Marino # if HAVE_RAW_DECL_STRPBRK 100751ddd709SJohn Marino _GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - " 100851ddd709SJohn Marino "use gnulib module strpbrk for portability"); 100951ddd709SJohn Marino # endif 101051ddd709SJohn Marino #endif 101151ddd709SJohn Marino 101251ddd709SJohn Marino #if defined GNULIB_POSIXCHECK 101351ddd709SJohn Marino /* strspn() assumes the second argument is a list of single-byte characters. 101451ddd709SJohn Marino Even in this simple case, it cannot work with multibyte strings. */ 101551ddd709SJohn Marino # undef strspn 101651ddd709SJohn Marino /* Assume strspn is always declared. */ 101751ddd709SJohn Marino _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings " 101851ddd709SJohn Marino "in multibyte locales - " 101951ddd709SJohn Marino "use mbsspn if you care about internationalization"); 102051ddd709SJohn Marino #endif 102151ddd709SJohn Marino 102251ddd709SJohn Marino #if defined GNULIB_POSIXCHECK 102351ddd709SJohn Marino /* strrchr() does not work with multibyte strings if the locale encoding is 102451ddd709SJohn Marino GB18030 and the character to be searched is a digit. */ 102551ddd709SJohn Marino # undef strrchr 102651ddd709SJohn Marino /* Assume strrchr is always declared. */ 102751ddd709SJohn Marino _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings " 102851ddd709SJohn Marino "in some multibyte locales - " 102951ddd709SJohn Marino "use mbsrchr if you care about internationalization"); 103051ddd709SJohn Marino #endif 103151ddd709SJohn Marino 103251ddd709SJohn Marino /* Search the next delimiter (char listed in DELIM) starting at *STRINGP. 103351ddd709SJohn Marino If one is found, overwrite it with a NUL, and advance *STRINGP 103451ddd709SJohn Marino to point to the next char after it. Otherwise, set *STRINGP to NULL. 103551ddd709SJohn Marino If *STRINGP was already NULL, nothing happens. 103651ddd709SJohn Marino Return the old value of *STRINGP. 103751ddd709SJohn Marino 103851ddd709SJohn Marino This is a variant of strtok() that is multithread-safe and supports 103951ddd709SJohn Marino empty fields. 104051ddd709SJohn Marino 104151ddd709SJohn Marino Caveat: It modifies the original string. 104251ddd709SJohn Marino Caveat: These functions cannot be used on constant strings. 104351ddd709SJohn Marino Caveat: The identity of the delimiting character is lost. 104451ddd709SJohn Marino Caveat: It doesn't work with multibyte strings unless all of the delimiter 104551ddd709SJohn Marino characters are ASCII characters < 0x30. 104651ddd709SJohn Marino 104751ddd709SJohn Marino See also strtok_r(). */ 104851ddd709SJohn Marino #if 0 104951ddd709SJohn Marino # if ! 1 105051ddd709SJohn Marino _GL_FUNCDECL_SYS (strsep, char *, 105151ddd709SJohn Marino (char **restrict __stringp, char const *restrict __delim) 105251ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 105351ddd709SJohn Marino # endif 105451ddd709SJohn Marino _GL_CXXALIAS_SYS (strsep, char *, 105551ddd709SJohn Marino (char **restrict __stringp, char const *restrict __delim)); 105651ddd709SJohn Marino _GL_CXXALIASWARN (strsep); 105751ddd709SJohn Marino # if defined GNULIB_POSIXCHECK 105851ddd709SJohn Marino # undef strsep 105951ddd709SJohn Marino _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings " 106051ddd709SJohn Marino "in multibyte locales - " 106151ddd709SJohn Marino "use mbssep if you care about internationalization"); 106251ddd709SJohn Marino # endif 106351ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 106451ddd709SJohn Marino # undef strsep 106551ddd709SJohn Marino # if HAVE_RAW_DECL_STRSEP 106651ddd709SJohn Marino _GL_WARN_ON_USE (strsep, "strsep is unportable - " 106751ddd709SJohn Marino "use gnulib module strsep for portability"); 106851ddd709SJohn Marino # endif 106951ddd709SJohn Marino #endif 107051ddd709SJohn Marino 1071cf51209aSJohn Marino #if 1 1072cf51209aSJohn Marino # if 1 107351ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 107451ddd709SJohn Marino # define strstr rpl_strstr 107551ddd709SJohn Marino # endif 107651ddd709SJohn Marino _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle) 107751ddd709SJohn Marino _GL_ATTRIBUTE_PURE 107851ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 107951ddd709SJohn Marino _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle)); 108051ddd709SJohn Marino # else 108151ddd709SJohn Marino /* On some systems, this function is defined as an overloaded function: 108251ddd709SJohn Marino extern "C++" { const char * strstr (const char *, const char *); } 108351ddd709SJohn Marino extern "C++" { char * strstr (char *, const char *); } */ 108451ddd709SJohn Marino _GL_CXXALIAS_SYS_CAST2 (strstr, 108551ddd709SJohn Marino char *, (const char *haystack, const char *needle), 108651ddd709SJohn Marino const char *, (const char *haystack, const char *needle)); 108751ddd709SJohn Marino # endif 108851ddd709SJohn Marino # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 108951ddd709SJohn Marino && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 109051ddd709SJohn Marino _GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle)); 109151ddd709SJohn Marino _GL_CXXALIASWARN1 (strstr, const char *, 109251ddd709SJohn Marino (const char *haystack, const char *needle)); 1093*4ce1b016SDaniel Fojt # elif __GLIBC__ >= 2 109451ddd709SJohn Marino _GL_CXXALIASWARN (strstr); 109551ddd709SJohn Marino # endif 109651ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 109751ddd709SJohn Marino /* strstr() does not work with multibyte strings if the locale encoding is 109851ddd709SJohn Marino different from UTF-8: 109951ddd709SJohn Marino POSIX says that it operates on "strings", and "string" in POSIX is defined 110051ddd709SJohn Marino as a sequence of bytes, not of characters. */ 110151ddd709SJohn Marino # undef strstr 110251ddd709SJohn Marino /* Assume strstr is always declared. */ 110351ddd709SJohn Marino _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot " 110451ddd709SJohn Marino "work correctly on character strings in most " 110551ddd709SJohn Marino "multibyte locales - " 110651ddd709SJohn Marino "use mbsstr if you care about internationalization, " 110751ddd709SJohn Marino "or use strstr if you care about speed"); 110851ddd709SJohn Marino #endif 110951ddd709SJohn Marino 111051ddd709SJohn Marino /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive 111151ddd709SJohn Marino comparison. */ 111251ddd709SJohn Marino #if 0 111351ddd709SJohn Marino # if 0 111451ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 111551ddd709SJohn Marino # define strcasestr rpl_strcasestr 111651ddd709SJohn Marino # endif 111751ddd709SJohn Marino _GL_FUNCDECL_RPL (strcasestr, char *, 111851ddd709SJohn Marino (const char *haystack, const char *needle) 111951ddd709SJohn Marino _GL_ATTRIBUTE_PURE 112051ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 112151ddd709SJohn Marino _GL_CXXALIAS_RPL (strcasestr, char *, 112251ddd709SJohn Marino (const char *haystack, const char *needle)); 112351ddd709SJohn Marino # else 112451ddd709SJohn Marino # if ! 1 112551ddd709SJohn Marino _GL_FUNCDECL_SYS (strcasestr, char *, 112651ddd709SJohn Marino (const char *haystack, const char *needle) 112751ddd709SJohn Marino _GL_ATTRIBUTE_PURE 112851ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 112951ddd709SJohn Marino # endif 113051ddd709SJohn Marino /* On some systems, this function is defined as an overloaded function: 113151ddd709SJohn Marino extern "C++" { const char * strcasestr (const char *, const char *); } 113251ddd709SJohn Marino extern "C++" { char * strcasestr (char *, const char *); } */ 113351ddd709SJohn Marino _GL_CXXALIAS_SYS_CAST2 (strcasestr, 113451ddd709SJohn Marino char *, (const char *haystack, const char *needle), 113551ddd709SJohn Marino const char *, (const char *haystack, const char *needle)); 113651ddd709SJohn Marino # endif 113751ddd709SJohn Marino # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 113851ddd709SJohn Marino && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 113951ddd709SJohn Marino _GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle)); 114051ddd709SJohn Marino _GL_CXXALIASWARN1 (strcasestr, const char *, 114151ddd709SJohn Marino (const char *haystack, const char *needle)); 114251ddd709SJohn Marino # else 114351ddd709SJohn Marino _GL_CXXALIASWARN (strcasestr); 114451ddd709SJohn Marino # endif 114551ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 114651ddd709SJohn Marino /* strcasestr() does not work with multibyte strings: 114751ddd709SJohn Marino It is a glibc extension, and glibc implements it only for unibyte 114851ddd709SJohn Marino locales. */ 114951ddd709SJohn Marino # undef strcasestr 115051ddd709SJohn Marino # if HAVE_RAW_DECL_STRCASESTR 115151ddd709SJohn Marino _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character " 115251ddd709SJohn Marino "strings in multibyte locales - " 115351ddd709SJohn Marino "use mbscasestr if you care about " 115451ddd709SJohn Marino "internationalization, or use c-strcasestr if you want " 115551ddd709SJohn Marino "a locale independent function"); 115651ddd709SJohn Marino # endif 115751ddd709SJohn Marino #endif 115851ddd709SJohn Marino 115951ddd709SJohn Marino /* Parse S into tokens separated by characters in DELIM. 116051ddd709SJohn Marino If S is NULL, the saved pointer in SAVE_PTR is used as 116151ddd709SJohn Marino the next starting point. For example: 116251ddd709SJohn Marino char s[] = "-abc-=-def"; 116351ddd709SJohn Marino char *sp; 116451ddd709SJohn Marino x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" 116551ddd709SJohn Marino x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL 116651ddd709SJohn Marino x = strtok_r(NULL, "=", &sp); // x = NULL 116751ddd709SJohn Marino // s = "abc\0-def\0" 116851ddd709SJohn Marino 116951ddd709SJohn Marino This is a variant of strtok() that is multithread-safe. 117051ddd709SJohn Marino 117151ddd709SJohn Marino For the POSIX documentation for this function, see: 1172*4ce1b016SDaniel Fojt https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok.html 117351ddd709SJohn Marino 117451ddd709SJohn Marino Caveat: It modifies the original string. 117551ddd709SJohn Marino Caveat: These functions cannot be used on constant strings. 117651ddd709SJohn Marino Caveat: The identity of the delimiting character is lost. 117751ddd709SJohn Marino Caveat: It doesn't work with multibyte strings unless all of the delimiter 117851ddd709SJohn Marino characters are ASCII characters < 0x30. 117951ddd709SJohn Marino 118051ddd709SJohn Marino See also strsep(). */ 118151ddd709SJohn Marino #if 0 118251ddd709SJohn Marino # if 0 118351ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 118451ddd709SJohn Marino # undef strtok_r 118551ddd709SJohn Marino # define strtok_r rpl_strtok_r 118651ddd709SJohn Marino # endif 118751ddd709SJohn Marino _GL_FUNCDECL_RPL (strtok_r, char *, 118851ddd709SJohn Marino (char *restrict s, char const *restrict delim, 118951ddd709SJohn Marino char **restrict save_ptr) 119051ddd709SJohn Marino _GL_ARG_NONNULL ((2, 3))); 119151ddd709SJohn Marino _GL_CXXALIAS_RPL (strtok_r, char *, 119251ddd709SJohn Marino (char *restrict s, char const *restrict delim, 119351ddd709SJohn Marino char **restrict save_ptr)); 119451ddd709SJohn Marino # else 119551ddd709SJohn Marino # if 0 || defined GNULIB_POSIXCHECK 119651ddd709SJohn Marino # undef strtok_r 119751ddd709SJohn Marino # endif 119851ddd709SJohn Marino # if ! 1 119951ddd709SJohn Marino _GL_FUNCDECL_SYS (strtok_r, char *, 120051ddd709SJohn Marino (char *restrict s, char const *restrict delim, 120151ddd709SJohn Marino char **restrict save_ptr) 120251ddd709SJohn Marino _GL_ARG_NONNULL ((2, 3))); 120351ddd709SJohn Marino # endif 120451ddd709SJohn Marino _GL_CXXALIAS_SYS (strtok_r, char *, 120551ddd709SJohn Marino (char *restrict s, char const *restrict delim, 120651ddd709SJohn Marino char **restrict save_ptr)); 120751ddd709SJohn Marino # endif 120851ddd709SJohn Marino _GL_CXXALIASWARN (strtok_r); 120951ddd709SJohn Marino # if defined GNULIB_POSIXCHECK 121051ddd709SJohn Marino _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character " 121151ddd709SJohn Marino "strings in multibyte locales - " 121251ddd709SJohn Marino "use mbstok_r if you care about internationalization"); 121351ddd709SJohn Marino # endif 121451ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 121551ddd709SJohn Marino # undef strtok_r 121651ddd709SJohn Marino # if HAVE_RAW_DECL_STRTOK_R 121751ddd709SJohn Marino _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - " 121851ddd709SJohn Marino "use gnulib module strtok_r for portability"); 121951ddd709SJohn Marino # endif 122051ddd709SJohn Marino #endif 122151ddd709SJohn Marino 122251ddd709SJohn Marino 122351ddd709SJohn Marino /* The following functions are not specified by POSIX. They are gnulib 122451ddd709SJohn Marino extensions. */ 122551ddd709SJohn Marino 122651ddd709SJohn Marino #if 1 122751ddd709SJohn Marino /* Return the number of multibyte characters in the character string STRING. 122851ddd709SJohn Marino This considers multibyte characters, unlike strlen, which counts bytes. */ 122951ddd709SJohn Marino # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */ 123051ddd709SJohn Marino # undef mbslen 123151ddd709SJohn Marino # endif 123251ddd709SJohn Marino # if 0 /* AIX, OSF/1, MirBSD define mbslen already in libc. */ 123351ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 123451ddd709SJohn Marino # define mbslen rpl_mbslen 123551ddd709SJohn Marino # endif 123651ddd709SJohn Marino _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) 123751ddd709SJohn Marino _GL_ATTRIBUTE_PURE 123851ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 123951ddd709SJohn Marino _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string)); 124051ddd709SJohn Marino # else 124151ddd709SJohn Marino _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) 124251ddd709SJohn Marino _GL_ATTRIBUTE_PURE 124351ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 124451ddd709SJohn Marino _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string)); 124551ddd709SJohn Marino # endif 124651ddd709SJohn Marino _GL_CXXALIASWARN (mbslen); 124751ddd709SJohn Marino #endif 124851ddd709SJohn Marino 124951ddd709SJohn Marino #if 0 125051ddd709SJohn Marino /* Return the number of multibyte characters in the character string starting 125151ddd709SJohn Marino at STRING and ending at STRING + LEN. */ 125251ddd709SJohn Marino _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len) 125351ddd709SJohn Marino _GL_ATTRIBUTE_PURE 125451ddd709SJohn Marino _GL_ARG_NONNULL ((1)); 125551ddd709SJohn Marino #endif 125651ddd709SJohn Marino 125751ddd709SJohn Marino #if 0 125851ddd709SJohn Marino /* Locate the first single-byte character C in the character string STRING, 125951ddd709SJohn Marino and return a pointer to it. Return NULL if C is not found in STRING. 126051ddd709SJohn Marino Unlike strchr(), this function works correctly in multibyte locales with 126151ddd709SJohn Marino encodings such as GB18030. */ 126251ddd709SJohn Marino # if defined __hpux 126351ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 126451ddd709SJohn Marino # define mbschr rpl_mbschr /* avoid collision with HP-UX function */ 126551ddd709SJohn Marino # endif 126651ddd709SJohn Marino _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c) 126751ddd709SJohn Marino _GL_ATTRIBUTE_PURE 126851ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 126951ddd709SJohn Marino _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c)); 127051ddd709SJohn Marino # else 127151ddd709SJohn Marino _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c) 127251ddd709SJohn Marino _GL_ATTRIBUTE_PURE 127351ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 127451ddd709SJohn Marino _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c)); 127551ddd709SJohn Marino # endif 127651ddd709SJohn Marino _GL_CXXALIASWARN (mbschr); 127751ddd709SJohn Marino #endif 127851ddd709SJohn Marino 127951ddd709SJohn Marino #if 0 128051ddd709SJohn Marino /* Locate the last single-byte character C in the character string STRING, 128151ddd709SJohn Marino and return a pointer to it. Return NULL if C is not found in STRING. 128251ddd709SJohn Marino Unlike strrchr(), this function works correctly in multibyte locales with 128351ddd709SJohn Marino encodings such as GB18030. */ 128451ddd709SJohn Marino # if defined __hpux || defined __INTERIX 128551ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 128651ddd709SJohn Marino # define mbsrchr rpl_mbsrchr /* avoid collision with system function */ 128751ddd709SJohn Marino # endif 128851ddd709SJohn Marino _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c) 128951ddd709SJohn Marino _GL_ATTRIBUTE_PURE 129051ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 129151ddd709SJohn Marino _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c)); 129251ddd709SJohn Marino # else 129351ddd709SJohn Marino _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c) 129451ddd709SJohn Marino _GL_ATTRIBUTE_PURE 129551ddd709SJohn Marino _GL_ARG_NONNULL ((1))); 129651ddd709SJohn Marino _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c)); 129751ddd709SJohn Marino # endif 129851ddd709SJohn Marino _GL_CXXALIASWARN (mbsrchr); 129951ddd709SJohn Marino #endif 130051ddd709SJohn Marino 130151ddd709SJohn Marino #if 1 130251ddd709SJohn Marino /* Find the first occurrence of the character string NEEDLE in the character 130351ddd709SJohn Marino string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. 130451ddd709SJohn Marino Unlike strstr(), this function works correctly in multibyte locales with 130551ddd709SJohn Marino encodings different from UTF-8. */ 130651ddd709SJohn Marino _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle) 130751ddd709SJohn Marino _GL_ATTRIBUTE_PURE 130851ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2)); 130951ddd709SJohn Marino #endif 131051ddd709SJohn Marino 131151ddd709SJohn Marino #if 1 131251ddd709SJohn Marino /* Compare the character strings S1 and S2, ignoring case, returning less than, 131351ddd709SJohn Marino equal to or greater than zero if S1 is lexicographically less than, equal to 131451ddd709SJohn Marino or greater than S2. 131551ddd709SJohn Marino Note: This function may, in multibyte locales, return 0 for strings of 131651ddd709SJohn Marino different lengths! 131751ddd709SJohn Marino Unlike strcasecmp(), this function works correctly in multibyte locales. */ 131851ddd709SJohn Marino _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2) 131951ddd709SJohn Marino _GL_ATTRIBUTE_PURE 132051ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2)); 132151ddd709SJohn Marino #endif 132251ddd709SJohn Marino 132351ddd709SJohn Marino #if 0 132451ddd709SJohn Marino /* Compare the initial segment of the character string S1 consisting of at most 132551ddd709SJohn Marino N characters with the initial segment of the character string S2 consisting 132651ddd709SJohn Marino of at most N characters, ignoring case, returning less than, equal to or 132751ddd709SJohn Marino greater than zero if the initial segment of S1 is lexicographically less 132851ddd709SJohn Marino than, equal to or greater than the initial segment of S2. 132951ddd709SJohn Marino Note: This function may, in multibyte locales, return 0 for initial segments 133051ddd709SJohn Marino of different lengths! 133151ddd709SJohn Marino Unlike strncasecmp(), this function works correctly in multibyte locales. 133251ddd709SJohn Marino But beware that N is not a byte count but a character count! */ 133351ddd709SJohn Marino _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n) 133451ddd709SJohn Marino _GL_ATTRIBUTE_PURE 133551ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2)); 133651ddd709SJohn Marino #endif 133751ddd709SJohn Marino 133851ddd709SJohn Marino #if 0 133951ddd709SJohn Marino /* Compare the initial segment of the character string STRING consisting of 134051ddd709SJohn Marino at most mbslen (PREFIX) characters with the character string PREFIX, 134151ddd709SJohn Marino ignoring case. If the two match, return a pointer to the first byte 134251ddd709SJohn Marino after this prefix in STRING. Otherwise, return NULL. 134351ddd709SJohn Marino Note: This function may, in multibyte locales, return non-NULL if STRING 134451ddd709SJohn Marino is of smaller length than PREFIX! 134551ddd709SJohn Marino Unlike strncasecmp(), this function works correctly in multibyte 134651ddd709SJohn Marino locales. */ 134751ddd709SJohn Marino _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix) 134851ddd709SJohn Marino _GL_ATTRIBUTE_PURE 134951ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2)); 135051ddd709SJohn Marino #endif 135151ddd709SJohn Marino 135251ddd709SJohn Marino #if 0 135351ddd709SJohn Marino /* Find the first occurrence of the character string NEEDLE in the character 135451ddd709SJohn Marino string HAYSTACK, using case-insensitive comparison. 135551ddd709SJohn Marino Note: This function may, in multibyte locales, return success even if 135651ddd709SJohn Marino strlen (haystack) < strlen (needle) ! 135751ddd709SJohn Marino Unlike strcasestr(), this function works correctly in multibyte locales. */ 135851ddd709SJohn Marino _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle) 135951ddd709SJohn Marino _GL_ATTRIBUTE_PURE 136051ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2)); 136151ddd709SJohn Marino #endif 136251ddd709SJohn Marino 136351ddd709SJohn Marino #if 0 136451ddd709SJohn Marino /* Find the first occurrence in the character string STRING of any character 136551ddd709SJohn Marino in the character string ACCEPT. Return the number of bytes from the 136651ddd709SJohn Marino beginning of the string to this occurrence, or to the end of the string 136751ddd709SJohn Marino if none exists. 136851ddd709SJohn Marino Unlike strcspn(), this function works correctly in multibyte locales. */ 136951ddd709SJohn Marino _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept) 137051ddd709SJohn Marino _GL_ATTRIBUTE_PURE 137151ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2)); 137251ddd709SJohn Marino #endif 137351ddd709SJohn Marino 137451ddd709SJohn Marino #if 0 137551ddd709SJohn Marino /* Find the first occurrence in the character string STRING of any character 137651ddd709SJohn Marino in the character string ACCEPT. Return the pointer to it, or NULL if none 137751ddd709SJohn Marino exists. 137851ddd709SJohn Marino Unlike strpbrk(), this function works correctly in multibyte locales. */ 137951ddd709SJohn Marino # if defined __hpux 138051ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 138151ddd709SJohn Marino # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ 138251ddd709SJohn Marino # endif 138351ddd709SJohn Marino _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept) 138451ddd709SJohn Marino _GL_ATTRIBUTE_PURE 138551ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 138651ddd709SJohn Marino _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept)); 138751ddd709SJohn Marino # else 138851ddd709SJohn Marino _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept) 138951ddd709SJohn Marino _GL_ATTRIBUTE_PURE 139051ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 139151ddd709SJohn Marino _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept)); 139251ddd709SJohn Marino # endif 139351ddd709SJohn Marino _GL_CXXALIASWARN (mbspbrk); 139451ddd709SJohn Marino #endif 139551ddd709SJohn Marino 139651ddd709SJohn Marino #if 0 139751ddd709SJohn Marino /* Find the first occurrence in the character string STRING of any character 139851ddd709SJohn Marino not in the character string REJECT. Return the number of bytes from the 139951ddd709SJohn Marino beginning of the string to this occurrence, or to the end of the string 140051ddd709SJohn Marino if none exists. 140151ddd709SJohn Marino Unlike strspn(), this function works correctly in multibyte locales. */ 140251ddd709SJohn Marino _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject) 140351ddd709SJohn Marino _GL_ATTRIBUTE_PURE 140451ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2)); 140551ddd709SJohn Marino #endif 140651ddd709SJohn Marino 140751ddd709SJohn Marino #if 0 140851ddd709SJohn Marino /* Search the next delimiter (multibyte character listed in the character 140951ddd709SJohn Marino string DELIM) starting at the character string *STRINGP. 141051ddd709SJohn Marino If one is found, overwrite it with a NUL, and advance *STRINGP to point 141151ddd709SJohn Marino to the next multibyte character after it. Otherwise, set *STRINGP to NULL. 141251ddd709SJohn Marino If *STRINGP was already NULL, nothing happens. 141351ddd709SJohn Marino Return the old value of *STRINGP. 141451ddd709SJohn Marino 141551ddd709SJohn Marino This is a variant of mbstok_r() that supports empty fields. 141651ddd709SJohn Marino 141751ddd709SJohn Marino Caveat: It modifies the original string. 141851ddd709SJohn Marino Caveat: These functions cannot be used on constant strings. 141951ddd709SJohn Marino Caveat: The identity of the delimiting character is lost. 142051ddd709SJohn Marino 142151ddd709SJohn Marino See also mbstok_r(). */ 142251ddd709SJohn Marino _GL_EXTERN_C char * mbssep (char **stringp, const char *delim) 142351ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2)); 142451ddd709SJohn Marino #endif 142551ddd709SJohn Marino 142651ddd709SJohn Marino #if 0 142751ddd709SJohn Marino /* Parse the character string STRING into tokens separated by characters in 142851ddd709SJohn Marino the character string DELIM. 142951ddd709SJohn Marino If STRING is NULL, the saved pointer in SAVE_PTR is used as 143051ddd709SJohn Marino the next starting point. For example: 143151ddd709SJohn Marino char s[] = "-abc-=-def"; 143251ddd709SJohn Marino char *sp; 143351ddd709SJohn Marino x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" 143451ddd709SJohn Marino x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL 143551ddd709SJohn Marino x = mbstok_r(NULL, "=", &sp); // x = NULL 143651ddd709SJohn Marino // s = "abc\0-def\0" 143751ddd709SJohn Marino 143851ddd709SJohn Marino Caveat: It modifies the original string. 143951ddd709SJohn Marino Caveat: These functions cannot be used on constant strings. 144051ddd709SJohn Marino Caveat: The identity of the delimiting character is lost. 144151ddd709SJohn Marino 144251ddd709SJohn Marino See also mbssep(). */ 144351ddd709SJohn Marino _GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr) 144451ddd709SJohn Marino _GL_ARG_NONNULL ((2, 3)); 144551ddd709SJohn Marino #endif 144651ddd709SJohn Marino 144751ddd709SJohn Marino /* Map any int, typically from errno, into an error message. */ 144851ddd709SJohn Marino #if 1 144951ddd709SJohn Marino # if 1 145051ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 145151ddd709SJohn Marino # undef strerror 145251ddd709SJohn Marino # define strerror rpl_strerror 145351ddd709SJohn Marino # endif 145451ddd709SJohn Marino _GL_FUNCDECL_RPL (strerror, char *, (int)); 145551ddd709SJohn Marino _GL_CXXALIAS_RPL (strerror, char *, (int)); 145651ddd709SJohn Marino # else 145751ddd709SJohn Marino _GL_CXXALIAS_SYS (strerror, char *, (int)); 145851ddd709SJohn Marino # endif 1459*4ce1b016SDaniel Fojt # if __GLIBC__ >= 2 146051ddd709SJohn Marino _GL_CXXALIASWARN (strerror); 1461*4ce1b016SDaniel Fojt # endif 146251ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 146351ddd709SJohn Marino # undef strerror 146451ddd709SJohn Marino /* Assume strerror is always declared. */ 146551ddd709SJohn Marino _GL_WARN_ON_USE (strerror, "strerror is unportable - " 146651ddd709SJohn Marino "use gnulib module strerror to guarantee non-NULL result"); 146751ddd709SJohn Marino #endif 146851ddd709SJohn Marino 146951ddd709SJohn Marino /* Map any int, typically from errno, into an error message. Multithread-safe. 147051ddd709SJohn Marino Uses the POSIX declaration, not the glibc declaration. */ 1471*4ce1b016SDaniel Fojt #if IN_GREP_GNULIB_TESTS 1472*4ce1b016SDaniel Fojt # if 1 147351ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 147451ddd709SJohn Marino # undef strerror_r 147551ddd709SJohn Marino # define strerror_r rpl_strerror_r 147651ddd709SJohn Marino # endif 147751ddd709SJohn Marino _GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen) 147851ddd709SJohn Marino _GL_ARG_NONNULL ((2))); 147951ddd709SJohn Marino _GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)); 148051ddd709SJohn Marino # else 148151ddd709SJohn Marino # if !1 148251ddd709SJohn Marino _GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen) 148351ddd709SJohn Marino _GL_ARG_NONNULL ((2))); 148451ddd709SJohn Marino # endif 148551ddd709SJohn Marino _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)); 148651ddd709SJohn Marino # endif 148751ddd709SJohn Marino # if 1 148851ddd709SJohn Marino _GL_CXXALIASWARN (strerror_r); 148951ddd709SJohn Marino # endif 149051ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 149151ddd709SJohn Marino # undef strerror_r 149251ddd709SJohn Marino # if HAVE_RAW_DECL_STRERROR_R 149351ddd709SJohn Marino _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - " 149451ddd709SJohn Marino "use gnulib module strerror_r-posix for portability"); 149551ddd709SJohn Marino # endif 149651ddd709SJohn Marino #endif 149751ddd709SJohn Marino 149851ddd709SJohn Marino #if 0 149951ddd709SJohn Marino # if 0 150051ddd709SJohn Marino # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 150151ddd709SJohn Marino # define strsignal rpl_strsignal 150251ddd709SJohn Marino # endif 150351ddd709SJohn Marino _GL_FUNCDECL_RPL (strsignal, char *, (int __sig)); 150451ddd709SJohn Marino _GL_CXXALIAS_RPL (strsignal, char *, (int __sig)); 150551ddd709SJohn Marino # else 150651ddd709SJohn Marino # if ! 1 150751ddd709SJohn Marino _GL_FUNCDECL_SYS (strsignal, char *, (int __sig)); 150851ddd709SJohn Marino # endif 150951ddd709SJohn Marino /* Need to cast, because on Cygwin 1.5.x systems, the return type is 151051ddd709SJohn Marino 'const char *'. */ 151151ddd709SJohn Marino _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig)); 151251ddd709SJohn Marino # endif 151351ddd709SJohn Marino _GL_CXXALIASWARN (strsignal); 151451ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 151551ddd709SJohn Marino # undef strsignal 151651ddd709SJohn Marino # if HAVE_RAW_DECL_STRSIGNAL 151751ddd709SJohn Marino _GL_WARN_ON_USE (strsignal, "strsignal is unportable - " 151851ddd709SJohn Marino "use gnulib module strsignal for portability"); 151951ddd709SJohn Marino # endif 152051ddd709SJohn Marino #endif 152151ddd709SJohn Marino 152251ddd709SJohn Marino #if 0 152351ddd709SJohn Marino # if !1 152451ddd709SJohn Marino _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *) 152551ddd709SJohn Marino _GL_ATTRIBUTE_PURE 152651ddd709SJohn Marino _GL_ARG_NONNULL ((1, 2))); 152751ddd709SJohn Marino # endif 152851ddd709SJohn Marino _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *)); 152951ddd709SJohn Marino _GL_CXXALIASWARN (strverscmp); 153051ddd709SJohn Marino #elif defined GNULIB_POSIXCHECK 153151ddd709SJohn Marino # undef strverscmp 153251ddd709SJohn Marino # if HAVE_RAW_DECL_STRVERSCMP 153351ddd709SJohn Marino _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - " 153451ddd709SJohn Marino "use gnulib module strverscmp for portability"); 153551ddd709SJohn Marino # endif 153651ddd709SJohn Marino #endif 153751ddd709SJohn Marino 153851ddd709SJohn Marino 153951ddd709SJohn Marino #endif /* _GL_STRING_H */ 154051ddd709SJohn Marino #endif /* _GL_STRING_H */ 1541cf51209aSJohn Marino #endif 1542