1 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2 /* A substitute <strings.h>.
4 Copyright (C) 2007-2019 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <https://www.gnu.org/licenses/>. */
22 #pragma GCC system_header
26 /* Minix 3.1.8 has a bug: <sys/types.h> must be included before <strings.h>.
27 But avoid namespace pollution on glibc systems. */
28 #if defined __minix && !defined __GLIBC__
29 # include <sys/types.h>
32 /* The include_next requires a split double-inclusion guard. */
34 # include_next <strings.h>
46 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
47 /* C++ compatible function declaration macros.
48 Copyright (C) 2010-2019 Free Software Foundation, Inc.
50 This program is free software: you can redistribute it and/or modify it
51 under the terms of the GNU General Public License as published
52 by the Free Software Foundation; either version 3 of the License, or
53 (at your option) any later version.
55 This program is distributed in the hope that it will be useful,
56 but WITHOUT ANY WARRANTY; without even the implied warranty of
57 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
58 General Public License for more details.
60 You should have received a copy of the GNU General Public License
61 along with this program. If not, see <https://www.gnu.org/licenses/>. */
66 /* Begin/end the GNULIB_NAMESPACE namespace. */
67 #if defined __cplusplus && defined GNULIB_NAMESPACE
68 # define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
69 # define _GL_END_NAMESPACE }
71 # define _GL_BEGIN_NAMESPACE
72 # define _GL_END_NAMESPACE
75 /* The three most frequent use cases of these macros are:
77 * For providing a substitute for a function that is missing on some
78 platforms, but is declared and works fine on the platforms on which
83 _GL_FUNCDECL_SYS (foo, ...);
85 _GL_CXXALIAS_SYS (foo, ...);
86 _GL_CXXALIASWARN (foo);
87 #elif defined GNULIB_POSIXCHECK
91 * For providing a replacement for a function that exists on all platforms,
92 but is broken/insufficient and needs to be replaced on some platforms:
96 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
100 _GL_FUNCDECL_RPL (foo, ...);
101 _GL_CXXALIAS_RPL (foo, ...);
103 _GL_CXXALIAS_SYS (foo, ...);
105 _GL_CXXALIASWARN (foo);
106 #elif defined GNULIB_POSIXCHECK
110 * For providing a replacement for a function that exists on some platforms
111 but is broken/insufficient and needs to be replaced on some of them and
112 is additionally either missing or undeclared on some other platforms:
116 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
120 _GL_FUNCDECL_RPL (foo, ...);
121 _GL_CXXALIAS_RPL (foo, ...);
123 # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
124 _GL_FUNCDECL_SYS (foo, ...);
126 _GL_CXXALIAS_SYS (foo, ...);
128 _GL_CXXALIASWARN (foo);
129 #elif defined GNULIB_POSIXCHECK
134 /* _GL_EXTERN_C declaration;
135 performs the declaration with C linkage. */
136 #if defined __cplusplus
137 # define _GL_EXTERN_C extern "C"
139 # define _GL_EXTERN_C extern
142 /* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
143 declares a replacement function, named rpl_func, with the given prototype,
144 consisting of return type, parameters, and attributes.
146 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
147 _GL_ARG_NONNULL ((1)));
149 #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
150 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
151 #define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
152 _GL_EXTERN_C rettype rpl_func parameters_and_attributes
154 /* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
155 declares the system function, named func, with the given prototype,
156 consisting of return type, parameters, and attributes.
158 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
159 _GL_ARG_NONNULL ((1)));
161 #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
162 _GL_EXTERN_C rettype func parameters_and_attributes
164 /* _GL_CXXALIAS_RPL (func, rettype, parameters);
165 declares a C++ alias called GNULIB_NAMESPACE::func
166 that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
168 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
170 Wrapping rpl_func in an object with an inline conversion operator
171 avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
172 actually used in the program. */
173 #define _GL_CXXALIAS_RPL(func,rettype,parameters) \
174 _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
175 #if defined __cplusplus && defined GNULIB_NAMESPACE
176 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
177 namespace GNULIB_NAMESPACE \
179 static const struct _gl_ ## func ## _wrapper \
181 typedef rettype (*type) parameters; \
183 inline operator type () const \
189 _GL_EXTERN_C int _gl_cxxalias_dummy
191 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
192 _GL_EXTERN_C int _gl_cxxalias_dummy
195 /* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
196 is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
197 except that the C function rpl_func may have a slightly different
198 declaration. A cast is used to silence the "invalid conversion" error
199 that would otherwise occur. */
200 #if defined __cplusplus && defined GNULIB_NAMESPACE
201 # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
202 namespace GNULIB_NAMESPACE \
204 static const struct _gl_ ## func ## _wrapper \
206 typedef rettype (*type) parameters; \
208 inline operator type () const \
210 return reinterpret_cast<type>(::rpl_func); \
214 _GL_EXTERN_C int _gl_cxxalias_dummy
216 # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
217 _GL_EXTERN_C int _gl_cxxalias_dummy
220 /* _GL_CXXALIAS_SYS (func, rettype, parameters);
221 declares a C++ alias called GNULIB_NAMESPACE::func
222 that redirects to the system provided function func, if GNULIB_NAMESPACE
225 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
227 Wrapping func in an object with an inline conversion operator
228 avoids a reference to func unless GNULIB_NAMESPACE::func is
229 actually used in the program. */
230 #if defined __cplusplus && defined GNULIB_NAMESPACE
231 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
232 namespace GNULIB_NAMESPACE \
234 static const struct _gl_ ## func ## _wrapper \
236 typedef rettype (*type) parameters; \
238 inline operator type () const \
244 _GL_EXTERN_C int _gl_cxxalias_dummy
246 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
247 _GL_EXTERN_C int _gl_cxxalias_dummy
250 /* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
251 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
252 except that the C function func may have a slightly different declaration.
253 A cast is used to silence the "invalid conversion" error that would
255 #if defined __cplusplus && defined GNULIB_NAMESPACE
256 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
257 namespace GNULIB_NAMESPACE \
259 static const struct _gl_ ## func ## _wrapper \
261 typedef rettype (*type) parameters; \
263 inline operator type () const \
265 return reinterpret_cast<type>(::func); \
269 _GL_EXTERN_C int _gl_cxxalias_dummy
271 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
272 _GL_EXTERN_C int _gl_cxxalias_dummy
275 /* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
276 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
277 except that the C function is picked among a set of overloaded functions,
278 namely the one with rettype2 and parameters2. Two consecutive casts
279 are used to silence the "cannot find a match" and "invalid conversion"
280 errors that would otherwise occur. */
281 #if defined __cplusplus && defined GNULIB_NAMESPACE
282 /* The outer cast must be a reinterpret_cast.
283 The inner cast: When the function is defined as a set of overloaded
284 functions, it works as a static_cast<>, choosing the designated variant.
285 When the function is defined as a single variant, it works as a
286 reinterpret_cast<>. The parenthesized cast syntax works both ways. */
287 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
288 namespace GNULIB_NAMESPACE \
290 static const struct _gl_ ## func ## _wrapper \
292 typedef rettype (*type) parameters; \
294 inline operator type () const \
296 return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); \
300 _GL_EXTERN_C int _gl_cxxalias_dummy
302 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
303 _GL_EXTERN_C int _gl_cxxalias_dummy
306 /* _GL_CXXALIASWARN (func);
307 causes a warning to be emitted when ::func is used but not when
308 GNULIB_NAMESPACE::func is used. func must be defined without overloaded
310 #if defined __cplusplus && defined GNULIB_NAMESPACE
311 # define _GL_CXXALIASWARN(func) \
312 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
313 # define _GL_CXXALIASWARN_1(func,namespace) \
314 _GL_CXXALIASWARN_2 (func, namespace)
315 /* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
316 we enable the warning only when not optimizing. */
318 # define _GL_CXXALIASWARN_2(func,namespace) \
319 _GL_WARN_ON_USE (func, \
320 "The symbol ::" #func " refers to the system function. " \
321 "Use " #namespace "::" #func " instead.")
322 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
323 # define _GL_CXXALIASWARN_2(func,namespace) \
324 extern __typeof__ (func) func
326 # define _GL_CXXALIASWARN_2(func,namespace) \
327 _GL_EXTERN_C int _gl_cxxalias_dummy
330 # define _GL_CXXALIASWARN(func) \
331 _GL_EXTERN_C int _gl_cxxalias_dummy
334 /* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
335 causes a warning to be emitted when the given overloaded variant of ::func
336 is used but not when GNULIB_NAMESPACE::func is used. */
337 #if defined __cplusplus && defined GNULIB_NAMESPACE
338 # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
339 _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
341 # define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
342 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
343 /* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
344 we enable the warning only when not optimizing. */
346 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
347 _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
348 "The symbol ::" #func " refers to the system function. " \
349 "Use " #namespace "::" #func " instead.")
350 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
351 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
352 extern __typeof__ (func) func
354 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
355 _GL_EXTERN_C int _gl_cxxalias_dummy
358 # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
359 _GL_EXTERN_C int _gl_cxxalias_dummy
362 #endif /* _GL_CXXDEFS_H */
364 /* The definition of _GL_ARG_NONNULL is copied here. */
365 /* A C macro for declaring that specific arguments must not be NULL.
366 Copyright (C) 2009-2019 Free Software Foundation, Inc.
368 This program is free software: you can redistribute it and/or modify it
369 under the terms of the GNU General Public License as published
370 by the Free Software Foundation; either version 3 of the License, or
371 (at your option) any later version.
373 This program is distributed in the hope that it will be useful,
374 but WITHOUT ANY WARRANTY; without even the implied warranty of
375 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376 General Public License for more details.
378 You should have received a copy of the GNU General Public License
379 along with this program. If not, see <https://www.gnu.org/licenses/>. */
381 /* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
382 that the values passed as arguments n, ..., m must be non-NULL pointers.
383 n = 1 stands for the first argument, n = 2 for the second argument etc. */
384 #ifndef _GL_ARG_NONNULL
385 # if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
386 # define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
388 # define _GL_ARG_NONNULL(params)
392 /* The definition of _GL_WARN_ON_USE is copied here. */
393 /* A C macro for emitting warnings if a function is used.
394 Copyright (C) 2010-2019 Free Software Foundation, Inc.
396 This program is free software: you can redistribute it and/or modify it
397 under the terms of the GNU General Public License as published
398 by the Free Software Foundation; either version 3 of the License, or
399 (at your option) any later version.
401 This program is distributed in the hope that it will be useful,
402 but WITHOUT ANY WARRANTY; without even the implied warranty of
403 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
404 General Public License for more details.
406 You should have received a copy of the GNU General Public License
407 along with this program. If not, see <https://www.gnu.org/licenses/>. */
409 /* _GL_WARN_ON_USE (function, "literal string") issues a declaration
410 for FUNCTION which will then trigger a compiler warning containing
411 the text of "literal string" anywhere that function is called, if
412 supported by the compiler. If the compiler does not support this
413 feature, the macro expands to an unused extern declaration.
415 _GL_WARN_ON_USE_ATTRIBUTE ("literal string") expands to the
416 attribute used in _GL_WARN_ON_USE. If the compiler does not support
417 this feature, it expands to empty.
419 These macros are useful for marking a function as a potential
420 portability trap, with the intent that "literal string" include
421 instructions on the replacement function that should be used
423 _GL_WARN_ON_USE is for functions with 'extern' linkage.
424 _GL_WARN_ON_USE_ATTRIBUTE is for functions with 'static' or 'inline'
427 However, one of the reasons that a function is a portability trap is
428 if it has the wrong signature. Declaring FUNCTION with a different
429 signature in C is a compilation error, so this macro must use the
430 same type as any existing declaration so that programs that avoid
431 the problematic FUNCTION do not fail to compile merely because they
432 included a header that poisoned the function. But this implies that
433 _GL_WARN_ON_USE is only safe to use if FUNCTION is known to already
434 have a declaration. Use of this macro implies that there must not
435 be any other macro hiding the declaration of FUNCTION; but
436 undefining FUNCTION first is part of the poisoning process anyway
437 (although for symbols that are provided only via a macro, the result
438 is a compilation error rather than a warning containing
439 "literal string"). Also note that in C++, it is only safe to use if
440 FUNCTION has no overloads.
442 For an example, it is possible to poison 'getline' by:
443 - adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
444 [getline]) in configure.ac, which potentially defines
445 HAVE_RAW_DECL_GETLINE
446 - adding this code to a header that wraps the system <stdio.h>:
448 #if HAVE_RAW_DECL_GETLINE
449 _GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
450 "not universally present; use the gnulib module getline");
453 It is not possible to directly poison global variables. But it is
454 possible to write a wrapper accessor function, and poison that
455 (less common usage, like &environ, will cause a compilation error
456 rather than issue the nice warning, but the end result of informing
457 the developer about their portability problem is still achieved):
458 #if HAVE_RAW_DECL_ENVIRON
460 rpl_environ (void) { return &environ; }
461 _GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
463 # define environ (*rpl_environ ())
465 or better (avoiding contradictory use of 'static' and 'extern'):
466 #if HAVE_RAW_DECL_ENVIRON
468 _GL_WARN_ON_USE_ATTRIBUTE ("environ is not always properly declared")
469 rpl_environ (void) { return &environ; }
471 # define environ (*rpl_environ ())
474 #ifndef _GL_WARN_ON_USE
476 # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
477 /* A compiler attribute is available in gcc versions 4.3.0 and later. */
478 # define _GL_WARN_ON_USE(function, message) \
479 extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
480 # define _GL_WARN_ON_USE_ATTRIBUTE(message) \
481 __attribute__ ((__warning__ (message)))
482 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
483 /* Verify the existence of the function. */
484 # define _GL_WARN_ON_USE(function, message) \
485 extern __typeof__ (function) function
486 # define _GL_WARN_ON_USE_ATTRIBUTE(message)
487 # else /* Unsupported. */
488 # define _GL_WARN_ON_USE(function, message) \
489 _GL_WARN_EXTERN_C int _gl_warn_on_use
490 # define _GL_WARN_ON_USE_ATTRIBUTE(message)
494 /* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
495 is like _GL_WARN_ON_USE (function, "string"), except that the function is
496 declared with the given prototype, consisting of return type, parameters,
498 This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
499 not work in this case. */
500 #ifndef _GL_WARN_ON_USE_CXX
501 # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
502 # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
503 extern rettype function parameters_and_attributes \
504 __attribute__ ((__warning__ (msg)))
505 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
506 /* Verify the existence of the function. */
507 # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
508 extern rettype function parameters_and_attributes
509 # else /* Unsupported. */
510 # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
511 _GL_WARN_EXTERN_C int _gl_warn_on_use
515 /* _GL_WARN_EXTERN_C declaration;
516 performs the declaration with C linkage. */
517 #ifndef _GL_WARN_EXTERN_C
518 # if defined __cplusplus
519 # define _GL_WARN_EXTERN_C extern "C"
521 # define _GL_WARN_EXTERN_C extern
530 /* Find the index of the least-significant set bit. */
533 _GL_FUNCDECL_SYS (ffs
, int, (int i
));
535 _GL_CXXALIAS_SYS (ffs
, int, (int i
));
536 _GL_CXXALIASWARN (ffs
);
537 #elif defined GNULIB_POSIXCHECK
539 # if HAVE_RAW_DECL_FFS
540 _GL_WARN_ON_USE (ffs
, "ffs is not portable - use the ffs module");
544 /* Compare strings S1 and S2, ignoring case, returning less than, equal to or
545 greater than zero if S1 is lexicographically less than, equal to or greater
547 Note: This function does not work in multibyte locales. */
549 extern int strcasecmp (char const *s1
, char const *s2
)
550 _GL_ARG_NONNULL ((1, 2));
552 #if defined GNULIB_POSIXCHECK
553 /* strcasecmp() does not work with multibyte strings:
554 POSIX says that it operates on "strings", and "string" in POSIX is defined
555 as a sequence of bytes, not of characters. */
557 # if HAVE_RAW_DECL_STRCASECMP
558 _GL_WARN_ON_USE (strcasecmp
, "strcasecmp cannot work correctly on character "
559 "strings in multibyte locales - "
560 "use mbscasecmp if you care about "
561 "internationalization, or use c_strcasecmp , "
562 "gnulib module c-strcase) if you want a locale "
563 "independent function");
567 /* Compare no more than N bytes of strings S1 and S2, ignoring case,
568 returning less than, equal to or greater than zero if S1 is
569 lexicographically less than, equal to or greater than S2.
570 Note: This function cannot work correctly in multibyte locales. */
572 extern int strncasecmp (char const *s1
, char const *s2
, size_t n
)
573 _GL_ARG_NONNULL ((1, 2));
575 #if defined GNULIB_POSIXCHECK
576 /* strncasecmp() does not work with multibyte strings:
577 POSIX says that it operates on "strings", and "string" in POSIX is defined
578 as a sequence of bytes, not of characters. */
580 # if HAVE_RAW_DECL_STRNCASECMP
581 _GL_WARN_ON_USE (strncasecmp
, "strncasecmp cannot work correctly on character "
582 "strings in multibyte locales - "
583 "use mbsncasecmp or mbspcasecmp if you care about "
584 "internationalization, or use c_strncasecmp , "
585 "gnulib module c-strcase) if you want a locale "
586 "independent function");
595 #endif /* _GL_STRING_H */
596 #endif /* _GL_STRING_H */