pmt: revert 7f8090b
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
/* A C macro for declaring that a function does not return.
|
||||
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _Noreturn
|
||||
# if (defined __cplusplus \
|
||||
&& ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
|
||||
|| (defined _MSC_VER && 1900 <= _MSC_VER)) \
|
||||
&& 0)
|
||||
/* [[noreturn]] is not practically usable, because with it the syntax
|
||||
extern _Noreturn void func (...);
|
||||
would not be valid; such a declaration would only be valid with 'extern'
|
||||
and '_Noreturn' swapped, or without the 'extern' keyword. However, some
|
||||
AIX system header files and several gnulib header files use precisely
|
||||
this syntax with 'extern'. */
|
||||
# define _Noreturn [[noreturn]]
|
||||
# elif ((!defined __cplusplus || defined __clang__) \
|
||||
&& (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
|
||||
|| (!defined __STRICT_ANSI__ \
|
||||
&& (4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
|
||||
|| (defined __apple_build_version__ \
|
||||
? 6000000 <= __apple_build_version__ \
|
||||
: 3 < __clang_major__ + (5 <= __clang_minor__))))))
|
||||
/* _Noreturn works as-is. */
|
||||
# elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \
|
||||
|| 0x5110 <= __SUNPRO_C)
|
||||
# define _Noreturn __attribute__ ((__noreturn__))
|
||||
# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
|
||||
# define _Noreturn __declspec (noreturn)
|
||||
# else
|
||||
# define _Noreturn
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,69 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* Memory allocation on the stack.
|
||||
Copyright (C) 1995, 1999, 2001-2007 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* When this file is included, it may be preceded only by preprocessor
|
||||
declarations. Thanks to AIX. Therefore we include it right after
|
||||
"config.h", not later. */
|
||||
|
||||
/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
|
||||
means there is a real alloca function. */
|
||||
#ifndef _GL_ALLOCA_H
|
||||
#define _GL_ALLOCA_H
|
||||
|
||||
/* alloca(N) returns a pointer (void* or char*) to N bytes of memory
|
||||
allocated on the stack, and which will last until the function returns.
|
||||
Use of alloca should be avoided:
|
||||
- inside arguments of function calls - undefined behaviour,
|
||||
- in inline functions - the allocation may actually last until the
|
||||
calling function returns,
|
||||
- for huge N (say, N >= 65536) - you never know how large (or small)
|
||||
the stack is, and when the stack cannot fulfill the memory allocation
|
||||
request, the program just crashes.
|
||||
*/
|
||||
|
||||
#ifndef alloca
|
||||
# ifdef __GNUC__
|
||||
# define alloca __builtin_alloca
|
||||
# else
|
||||
# ifdef _MSC_VER
|
||||
# include <malloc.h>
|
||||
# define alloca _alloca
|
||||
# else
|
||||
# if HAVE_ALLOCA_H
|
||||
# include <alloca.h>
|
||||
# else
|
||||
# ifdef _AIX
|
||||
#pragma alloca
|
||||
# else
|
||||
# ifdef __hpux /* This section must match that of bison generated files. */
|
||||
# ifdef __cplusplus
|
||||
extern "C" void *alloca (unsigned int);
|
||||
# else /* not __cplusplus */
|
||||
extern void *alloca ();
|
||||
# endif /* not __cplusplus */
|
||||
# else /* not __hpux */
|
||||
# ifndef alloca
|
||||
extern char *alloca ();
|
||||
# endif
|
||||
# endif /* __hpux */
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _GL_ALLOCA_H */
|
||||
@@ -1,58 +0,0 @@
|
||||
/* Memory allocators such as malloc+free.
|
||||
|
||||
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#ifndef _GL_ALLOCATOR_H
|
||||
#define _GL_ALLOCATOR_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* An object describing a memory allocator family. */
|
||||
|
||||
struct allocator
|
||||
{
|
||||
/* Do not use GCC attributes such as __attribute__ ((malloc)) with
|
||||
the function types pointed at by these members, because these
|
||||
attributes do not work with pointers to functions. See
|
||||
<https://lists.gnu.org/r/bug-gnulib/2011-04/msg00007.html>. */
|
||||
|
||||
/* Call ALLOCATE to allocate memory, like 'malloc'. On failure ALLOCATE
|
||||
should return NULL, though not necessarily set errno. When given
|
||||
a zero size it may return NULL even if successful. */
|
||||
void *(*allocate) (size_t);
|
||||
|
||||
/* If nonnull, call REALLOCATE to reallocate memory, like 'realloc'.
|
||||
On failure REALLOCATE should return NULL, though not necessarily set
|
||||
errno. When given a zero size it may return NULL even if
|
||||
successful. */
|
||||
void *(*reallocate) (void *, size_t);
|
||||
|
||||
/* Call FREE to free memory, like 'free'. */
|
||||
void (*free) (void *);
|
||||
|
||||
/* If nonnull, call DIE (SIZE) if MALLOC (SIZE) or REALLOC (...,
|
||||
SIZE) fails. DIE should not return. SIZE should equal SIZE_MAX
|
||||
if size_t overflow was detected while calculating sizes to be
|
||||
passed to MALLOC or REALLOC. */
|
||||
void (*die) (size_t);
|
||||
};
|
||||
|
||||
/* An allocator using the stdlib functions and a null DIE function. */
|
||||
extern struct allocator const stdlib_allocator;
|
||||
|
||||
#endif /* _GL_ALLOCATOR_H */
|
||||
@@ -1,37 +0,0 @@
|
||||
/* Read symbolic links without size limitation.
|
||||
|
||||
Copyright (C) 2001, 2003-2004, 2007, 2009-2022 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Jim Meyering <jim@meyering.net> */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
extern char *areadlink (char const *filename)
|
||||
_GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
extern char *areadlink_with_size (char const *filename, size_t size_hint)
|
||||
_GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
|
||||
#if GNULIB_AREADLINKAT
|
||||
extern char *areadlinkat (int fd, char const *filename)
|
||||
_GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
#endif
|
||||
|
||||
#if GNULIB_AREADLINKAT_WITH_SIZE
|
||||
extern char *areadlinkat_with_size (int fd, char const *filename,
|
||||
size_t size_hint)
|
||||
_GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
/* A C macro for declaring that specific arguments must not be NULL.
|
||||
Copyright (C) 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
|
||||
that the values passed as arguments n, ..., m must be non-NULL pointers.
|
||||
n = 1 stands for the first argument, n = 2 for the second argument etc. */
|
||||
#ifndef _GL_ARG_NONNULL
|
||||
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__
|
||||
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
|
||||
# else
|
||||
# define _GL_ARG_NONNULL(params)
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,78 +0,0 @@
|
||||
/* Extract the last component (base name) of a file name.
|
||||
|
||||
Copyright (C) 1998, 2001, 2003-2006, 2009-2022 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _BASENAME_LGPL_H
|
||||
#define _BASENAME_LGPL_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
|
||||
# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Return the address of the last file name component of FILENAME.
|
||||
If FILENAME has some trailing slash(es), they are considered to be
|
||||
part of the last component.
|
||||
If FILENAME has no relative file name components because it is a file
|
||||
system root, return the empty string.
|
||||
Examples:
|
||||
FILENAME RESULT
|
||||
"foo.c" "foo.c"
|
||||
"foo/bar.c" "bar.c"
|
||||
"/foo/bar.c" "bar.c"
|
||||
"foo/bar/" "bar/"
|
||||
"foo/bar//" "bar//"
|
||||
"/" ""
|
||||
"//" ""
|
||||
"" ""
|
||||
The return value is a tail of the given FILENAME; do NOT free() it! */
|
||||
|
||||
/* This function was traditionally called 'basename', but we avoid this
|
||||
function name because
|
||||
* Various platforms have different functions in their libc.
|
||||
In particular, the glibc basename(), defined in <string.h>, does
|
||||
not consider trailing slashes to be part of the component:
|
||||
FILENAME RESULT
|
||||
"foo/bar/" ""
|
||||
"foo/bar//" ""
|
||||
* The 'basename' command eliminates trailing slashes and for a root
|
||||
produces a non-empty result:
|
||||
FILENAME RESULT
|
||||
"foo/bar/" "bar"
|
||||
"foo/bar//" "bar"
|
||||
"/" "/"
|
||||
"//" "/"
|
||||
*/
|
||||
extern char *last_component (char const *filename) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return the length of the basename FILENAME.
|
||||
Typically FILENAME is the value returned by base_name or last_component.
|
||||
Act like strlen (FILENAME), except omit all trailing slashes. */
|
||||
extern size_t base_len (char const *filename) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* _BASENAME_LGPL_H */
|
||||
@@ -1,77 +0,0 @@
|
||||
/* Binary mode I/O.
|
||||
Copyright (C) 2001, 2003, 2005, 2008-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _BINARY_H
|
||||
#define _BINARY_H
|
||||
|
||||
/* For systems that distinguish between text and binary I/O.
|
||||
O_BINARY is guaranteed by the gnulib <fcntl.h>. */
|
||||
#include <fcntl.h>
|
||||
|
||||
/* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...',
|
||||
so we include it here first. */
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef _GL_INLINE_HEADER_BEGIN
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef BINARY_IO_INLINE
|
||||
# define BINARY_IO_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#if O_BINARY
|
||||
# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
|
||||
# include <io.h> /* declares setmode() */
|
||||
# define __gl_setmode setmode
|
||||
# else
|
||||
# define __gl_setmode _setmode
|
||||
# undef fileno
|
||||
# define fileno _fileno
|
||||
# endif
|
||||
#else
|
||||
/* On reasonable systems, binary I/O is the only choice. */
|
||||
/* Use a function rather than a macro, to avoid gcc warnings
|
||||
"warning: statement with no effect". */
|
||||
BINARY_IO_INLINE int
|
||||
__gl_setmode (_GL_UNUSED int fd, _GL_UNUSED int mode)
|
||||
{
|
||||
return O_BINARY;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY.
|
||||
Return the old mode if successful, -1 (setting errno) on failure.
|
||||
Ordinarily this function would be called 'setmode', since that is
|
||||
its old name on MS-Windows, but it is called 'set_binary_mode' here
|
||||
to avoid colliding with a BSD function of another name. */
|
||||
|
||||
#if defined __DJGPP__ || defined __EMX__
|
||||
extern int set_binary_mode (int fd, int mode);
|
||||
#else
|
||||
BINARY_IO_INLINE int
|
||||
set_binary_mode (int fd, int mode)
|
||||
{
|
||||
return __gl_setmode (fd, mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This macro is obsolescent. */
|
||||
#define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif /* _BINARY_H */
|
||||
@@ -1,331 +0,0 @@
|
||||
/* C++ compatible function declaration macros.
|
||||
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GL_CXXDEFS_H
|
||||
#define _GL_CXXDEFS_H
|
||||
|
||||
/* Begin/end the GNULIB_NAMESPACE namespace. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
|
||||
# define _GL_END_NAMESPACE }
|
||||
#else
|
||||
# define _GL_BEGIN_NAMESPACE
|
||||
# define _GL_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
/* The three most frequent use cases of these macros are:
|
||||
|
||||
* For providing a substitute for a function that is missing on some
|
||||
platforms, but is declared and works fine on the platforms on which
|
||||
it exists:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if !@HAVE_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on all platforms,
|
||||
but is broken/insufficient and needs to be replaced on some platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on some platforms
|
||||
but is broken/insufficient and needs to be replaced on some of them and
|
||||
is additionally either missing or undeclared on some other platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
# if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
*/
|
||||
|
||||
/* _GL_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#if defined __cplusplus
|
||||
# define _GL_EXTERN_C extern "C"
|
||||
#else
|
||||
# define _GL_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
|
||||
declares a replacement function, named rpl_func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
|
||||
_GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
|
||||
#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype rpl_func parameters_and_attributes
|
||||
|
||||
/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
|
||||
declares the system function, named func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype func parameters_and_attributes
|
||||
|
||||
/* _GL_CXXALIAS_RPL (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
|
||||
|
||||
Wrapping rpl_func in an object with an inline conversion operator
|
||||
avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
|
||||
actually used in the program. */
|
||||
#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return ::rpl_func; \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||
is to be used when func is a Microsoft deprecated alias, on native Windows.
|
||||
It declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to _func, if GNULIB_NAMESPACE is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
|
||||
*/
|
||||
#define _GL_CXXALIAS_MDA(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_1 (func, _##func, rettype, parameters)
|
||||
|
||||
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
|
||||
except that the C function rpl_func may have a slightly different
|
||||
declaration. A cast is used to silence the "invalid conversion" error
|
||||
that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>(::rpl_func); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_MDA_CAST (func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||
except that the C function func may have a slightly different declaration.
|
||||
A cast is used to silence the "invalid conversion" error that would
|
||||
otherwise occur. */
|
||||
#define _GL_CXXALIAS_MDA_CAST(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_CAST_1 (func, _##func, rettype, parameters)
|
||||
|
||||
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to the system provided function func, if GNULIB_NAMESPACE
|
||||
is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
|
||||
|
||||
Wrapping func in an object with an inline conversion operator
|
||||
avoids a reference to func unless GNULIB_NAMESPACE::func is
|
||||
actually used in the program. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return ::func; \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function func may have a slightly different declaration.
|
||||
A cast is used to silence the "invalid conversion" error that would
|
||||
otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>(::func); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function is picked among a set of overloaded functions,
|
||||
namely the one with rettype2 and parameters2. Two consecutive casts
|
||||
are used to silence the "cannot find a match" and "invalid conversion"
|
||||
errors that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
/* The outer cast must be a reinterpret_cast.
|
||||
The inner cast: When the function is defined as a set of overloaded
|
||||
functions, it works as a static_cast<>, choosing the designated variant.
|
||||
When the function is defined as a single variant, it works as a
|
||||
reinterpret_cast<>. The parenthesized cast syntax works both ways. */
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN (func);
|
||||
causes a warning to be emitted when ::func is used but not when
|
||||
GNULIB_NAMESPACE::func is used. func must be defined without overloaded
|
||||
variants. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN_1(func,namespace) \
|
||||
_GL_CXXALIASWARN_2 (func, namespace)
|
||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_WARN_ON_USE (func, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
extern __typeof__ (func) func
|
||||
# else
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
|
||||
causes a warning to be emitted when the given overloaded variant of ::func
|
||||
is used but not when GNULIB_NAMESPACE::func is used. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
|
||||
GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
|
||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_WARN_ON_USE_CXX (func, rettype, rettype, parameters_and_attributes, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# else
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
#endif /* _GL_CXXDEFS_H */
|
||||
@@ -1,21 +0,0 @@
|
||||
/* Character handling in C locale.
|
||||
|
||||
Copyright (C) 2003-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#define C_CTYPE_INLINE _GL_EXTERN_INLINE
|
||||
#include "c-ctype.h"
|
||||
@@ -1,366 +0,0 @@
|
||||
/* Character handling in C locale.
|
||||
|
||||
These functions work like the corresponding functions in <ctype.h>,
|
||||
except that they have the C (POSIX) locale hardwired, whereas the
|
||||
<ctype.h> functions' behaviour depends on the current locale set via
|
||||
setlocale.
|
||||
|
||||
Copyright (C) 2000-2003, 2006, 2008-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef C_CTYPE_H
|
||||
#define C_CTYPE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef _GL_INLINE_HEADER_BEGIN
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef C_CTYPE_INLINE
|
||||
# define C_CTYPE_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* The functions defined in this file assume the "C" locale and a character
|
||||
set without diacritics (ASCII-US or EBCDIC-US or something like that).
|
||||
Even if the "C" locale on a particular system is an extension of the ASCII
|
||||
character set (like on BeOS, where it is UTF-8, or on AmigaOS, where it
|
||||
is ISO-8859-1), the functions in this file recognize only the ASCII
|
||||
characters. */
|
||||
|
||||
|
||||
#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
|
||||
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
|
||||
&& (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
|
||||
&& ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
|
||||
&& ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
|
||||
&& ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
|
||||
&& ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
|
||||
&& ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
|
||||
&& ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
|
||||
&& ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
|
||||
&& ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
|
||||
&& ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
|
||||
&& ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
|
||||
&& ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
|
||||
&& ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
|
||||
&& ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
|
||||
&& ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
|
||||
&& ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
|
||||
&& ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
|
||||
&& ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
|
||||
&& ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
|
||||
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
|
||||
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)
|
||||
/* The character set is ASCII or one of its variants or extensions, not EBCDIC.
|
||||
Testing the value of '\n' and '\r' is not relevant. */
|
||||
# define C_CTYPE_ASCII 1
|
||||
#elif ! (' ' == '\x40' && '0' == '\xf0' \
|
||||
&& 'A' == '\xc1' && 'J' == '\xd1' && 'S' == '\xe2' \
|
||||
&& 'a' == '\x81' && 'j' == '\x91' && 's' == '\xa2')
|
||||
# error "Only ASCII and EBCDIC are supported"
|
||||
#endif
|
||||
|
||||
#if 'A' < 0
|
||||
# error "EBCDIC and char is signed -- not supported"
|
||||
#endif
|
||||
|
||||
/* Cases for control characters. */
|
||||
|
||||
#define _C_CTYPE_CNTRL \
|
||||
case '\a': case '\b': case '\f': case '\n': \
|
||||
case '\r': case '\t': case '\v': \
|
||||
_C_CTYPE_OTHER_CNTRL
|
||||
|
||||
/* ASCII control characters other than those with \-letter escapes. */
|
||||
|
||||
#if C_CTYPE_ASCII
|
||||
# define _C_CTYPE_OTHER_CNTRL \
|
||||
case '\x00': case '\x01': case '\x02': case '\x03': \
|
||||
case '\x04': case '\x05': case '\x06': case '\x0e': \
|
||||
case '\x0f': case '\x10': case '\x11': case '\x12': \
|
||||
case '\x13': case '\x14': case '\x15': case '\x16': \
|
||||
case '\x17': case '\x18': case '\x19': case '\x1a': \
|
||||
case '\x1b': case '\x1c': case '\x1d': case '\x1e': \
|
||||
case '\x1f': case '\x7f'
|
||||
#else
|
||||
/* Use EBCDIC code page 1047's assignments for ASCII control chars;
|
||||
assume all EBCDIC code pages agree about these assignments. */
|
||||
# define _C_CTYPE_OTHER_CNTRL \
|
||||
case '\x00': case '\x01': case '\x02': case '\x03': \
|
||||
case '\x07': case '\x0e': case '\x0f': case '\x10': \
|
||||
case '\x11': case '\x12': case '\x13': case '\x18': \
|
||||
case '\x19': case '\x1c': case '\x1d': case '\x1e': \
|
||||
case '\x1f': case '\x26': case '\x27': case '\x2d': \
|
||||
case '\x2e': case '\x32': case '\x37': case '\x3c': \
|
||||
case '\x3d': case '\x3f'
|
||||
#endif
|
||||
|
||||
/* Cases for lowercase hex letters, and lowercase letters, all offset by N. */
|
||||
|
||||
#define _C_CTYPE_LOWER_A_THRU_F_N(N) \
|
||||
case 'a' + (N): case 'b' + (N): case 'c' + (N): case 'd' + (N): \
|
||||
case 'e' + (N): case 'f' + (N)
|
||||
#define _C_CTYPE_LOWER_N(N) \
|
||||
_C_CTYPE_LOWER_A_THRU_F_N(N): \
|
||||
case 'g' + (N): case 'h' + (N): case 'i' + (N): case 'j' + (N): \
|
||||
case 'k' + (N): case 'l' + (N): case 'm' + (N): case 'n' + (N): \
|
||||
case 'o' + (N): case 'p' + (N): case 'q' + (N): case 'r' + (N): \
|
||||
case 's' + (N): case 't' + (N): case 'u' + (N): case 'v' + (N): \
|
||||
case 'w' + (N): case 'x' + (N): case 'y' + (N): case 'z' + (N)
|
||||
|
||||
/* Cases for hex letters, digits, lower, punct, and upper. */
|
||||
|
||||
#define _C_CTYPE_A_THRU_F \
|
||||
_C_CTYPE_LOWER_A_THRU_F_N (0): \
|
||||
_C_CTYPE_LOWER_A_THRU_F_N ('A' - 'a')
|
||||
#define _C_CTYPE_DIGIT \
|
||||
case '0': case '1': case '2': case '3': \
|
||||
case '4': case '5': case '6': case '7': \
|
||||
case '8': case '9'
|
||||
#define _C_CTYPE_LOWER _C_CTYPE_LOWER_N (0)
|
||||
#define _C_CTYPE_PUNCT \
|
||||
case '!': case '"': case '#': case '$': \
|
||||
case '%': case '&': case '\'': case '(': \
|
||||
case ')': case '*': case '+': case ',': \
|
||||
case '-': case '.': case '/': case ':': \
|
||||
case ';': case '<': case '=': case '>': \
|
||||
case '?': case '@': case '[': case '\\': \
|
||||
case ']': case '^': case '_': case '`': \
|
||||
case '{': case '|': case '}': case '~'
|
||||
#define _C_CTYPE_UPPER _C_CTYPE_LOWER_N ('A' - 'a')
|
||||
|
||||
|
||||
/* Function definitions. */
|
||||
|
||||
/* Unlike the functions in <ctype.h>, which require an argument in the range
|
||||
of the 'unsigned char' type, the functions here operate on values that are
|
||||
in the 'unsigned char' range or in the 'char' range. In other words,
|
||||
when you have a 'char' value, you need to cast it before using it as
|
||||
argument to a <ctype.h> function:
|
||||
|
||||
const char *s = ...;
|
||||
if (isalpha ((unsigned char) *s)) ...
|
||||
|
||||
but you don't need to cast it for the functions defined in this file:
|
||||
|
||||
const char *s = ...;
|
||||
if (c_isalpha (*s)) ...
|
||||
*/
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_isalnum (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_DIGIT:
|
||||
_C_CTYPE_LOWER:
|
||||
_C_CTYPE_UPPER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_isalpha (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_LOWER:
|
||||
_C_CTYPE_UPPER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* The function isascii is not locale dependent.
|
||||
Its use in EBCDIC is questionable. */
|
||||
C_CTYPE_INLINE bool
|
||||
c_isascii (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case ' ':
|
||||
_C_CTYPE_CNTRL:
|
||||
_C_CTYPE_DIGIT:
|
||||
_C_CTYPE_LOWER:
|
||||
_C_CTYPE_PUNCT:
|
||||
_C_CTYPE_UPPER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_isblank (int c)
|
||||
{
|
||||
return c == ' ' || c == '\t';
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_iscntrl (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_CNTRL:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_isdigit (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_DIGIT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_isgraph (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_DIGIT:
|
||||
_C_CTYPE_LOWER:
|
||||
_C_CTYPE_PUNCT:
|
||||
_C_CTYPE_UPPER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_islower (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_LOWER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_isprint (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case ' ':
|
||||
_C_CTYPE_DIGIT:
|
||||
_C_CTYPE_LOWER:
|
||||
_C_CTYPE_PUNCT:
|
||||
_C_CTYPE_UPPER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_ispunct (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_PUNCT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_isspace (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case ' ': case '\t': case '\n': case '\v': case '\f': case '\r':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_isupper (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_UPPER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE bool
|
||||
c_isxdigit (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_DIGIT:
|
||||
_C_CTYPE_A_THRU_F:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE int
|
||||
c_tolower (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_UPPER:
|
||||
return c - 'A' + 'a';
|
||||
default:
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
C_CTYPE_INLINE int
|
||||
c_toupper (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
_C_CTYPE_LOWER:
|
||||
return c - 'a' + 'A';
|
||||
default:
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif /* C_CTYPE_H */
|
||||
@@ -1,67 +0,0 @@
|
||||
/* Read symbolic links into a buffer without size limitation, relative to fd.
|
||||
|
||||
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
|
||||
|
||||
#ifndef _GL_CAREADLINKAT_H
|
||||
#define _GL_CAREADLINKAT_H
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct allocator;
|
||||
|
||||
/* Assuming the current directory is FD, get the symbolic link value
|
||||
of FILENAME as a null-terminated string and put it into a buffer.
|
||||
If FD is AT_FDCWD, FILENAME is interpreted relative to the current
|
||||
working directory, as in openat.
|
||||
|
||||
If the link is small enough to fit into BUFFER put it there.
|
||||
BUFFER's size is BUFFER_SIZE, and BUFFER can be null
|
||||
if BUFFER_SIZE is zero.
|
||||
|
||||
If the link is not small, put it into a dynamically allocated
|
||||
buffer managed by ALLOC. It is the caller's responsibility to free
|
||||
the returned value if it is nonnull and is not BUFFER.
|
||||
|
||||
The PREADLINKAT function specifies how to read links. It operates
|
||||
like POSIX readlinkat()
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>
|
||||
but can assume that its first argument is the same as FD.
|
||||
|
||||
If successful, return the buffer address; otherwise return NULL and
|
||||
set errno. */
|
||||
|
||||
char *careadlinkat (int fd, char const *filename,
|
||||
char *restrict buffer, size_t buffer_size,
|
||||
struct allocator const *alloc,
|
||||
ssize_t (*preadlinkat) (int, char const *,
|
||||
char *, size_t));
|
||||
|
||||
/* Suitable value for careadlinkat's FD argument. */
|
||||
#if HAVE_READLINKAT
|
||||
/* AT_FDCWD is declared in <fcntl.h>. */
|
||||
#else
|
||||
/* Define AT_FDCWD independently, so that the careadlinkat module does
|
||||
not depend on the fcntl-h module. We might as well use the same value
|
||||
as fcntl-h. */
|
||||
# ifndef AT_FDCWD
|
||||
# define AT_FDCWD (-3041965)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _GL_CAREADLINKAT_H */
|
||||
@@ -1,707 +0,0 @@
|
||||
/* Copyright (C) 1992-2022 Free Software Foundation, Inc.
|
||||
Copyright The GNU Toolchain Authors.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _SYS_CDEFS_H
|
||||
#define _SYS_CDEFS_H 1
|
||||
|
||||
/* We are almost always included from features.h. */
|
||||
#ifndef _FEATURES_H
|
||||
# include <features.h>
|
||||
#endif
|
||||
|
||||
/* The GNU libc does not support any K&R compilers or the traditional mode
|
||||
of ISO C compilers anymore. Check for some of the combinations not
|
||||
supported anymore. */
|
||||
#if defined __GNUC__ && !defined __STDC__
|
||||
# error "You need a ISO C conforming compiler to use the glibc headers"
|
||||
#endif
|
||||
|
||||
/* Some user header file might have defined this before. */
|
||||
#undef __P
|
||||
#undef __PMT
|
||||
|
||||
/* Compilers that lack __has_attribute may object to
|
||||
#if defined __has_attribute && __has_attribute (...)
|
||||
even though they do not need to evaluate the right-hand side of the &&.
|
||||
Similarly for __has_builtin, etc. */
|
||||
#if (defined __has_attribute \
|
||||
&& (!defined __clang_minor__ \
|
||||
|| (defined __apple_build_version__ \
|
||||
? 6000000 <= __apple_build_version__ \
|
||||
: 3 < __clang_major__ + (5 <= __clang_minor__))))
|
||||
# define __glibc_has_attribute(attr) __has_attribute (attr)
|
||||
#else
|
||||
# define __glibc_has_attribute(attr) 0
|
||||
#endif
|
||||
#ifdef __has_builtin
|
||||
# define __glibc_has_builtin(name) __has_builtin (name)
|
||||
#else
|
||||
# define __glibc_has_builtin(name) 0
|
||||
#endif
|
||||
#ifdef __has_extension
|
||||
# define __glibc_has_extension(ext) __has_extension (ext)
|
||||
#else
|
||||
# define __glibc_has_extension(ext) 0
|
||||
#endif
|
||||
|
||||
#if defined __GNUC__ || defined __clang__
|
||||
|
||||
/* All functions, except those with callbacks or those that
|
||||
synchronize memory, are leaf functions. */
|
||||
# if __GNUC_PREREQ (4, 6) && !defined _LIBC
|
||||
# define __LEAF , __leaf__
|
||||
# define __LEAF_ATTR __attribute__ ((__leaf__))
|
||||
# else
|
||||
# define __LEAF
|
||||
# define __LEAF_ATTR
|
||||
# endif
|
||||
|
||||
/* GCC can always grok prototypes. For C++ programs we add throw()
|
||||
to help it optimize the function calls. But this only works with
|
||||
gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions
|
||||
as non-throwing using a function attribute since programs can use
|
||||
the -fexceptions options for C code as well. */
|
||||
# if !defined __cplusplus \
|
||||
&& (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__))
|
||||
# define __THROW __attribute__ ((__nothrow__ __LEAF))
|
||||
# define __THROWNL __attribute__ ((__nothrow__))
|
||||
# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
|
||||
# define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
|
||||
# else
|
||||
# if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4)
|
||||
# if __cplusplus >= 201103L
|
||||
# define __THROW noexcept (true)
|
||||
# else
|
||||
# define __THROW throw ()
|
||||
# endif
|
||||
# define __THROWNL __THROW
|
||||
# define __NTH(fct) __LEAF_ATTR fct __THROW
|
||||
# define __NTHNL(fct) fct __THROW
|
||||
# else
|
||||
# define __THROW
|
||||
# define __THROWNL
|
||||
# define __NTH(fct) fct
|
||||
# define __NTHNL(fct) fct
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#else /* Not GCC or clang. */
|
||||
|
||||
# if (defined __cplusplus \
|
||||
|| (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
|
||||
# define __inline inline
|
||||
# else
|
||||
# define __inline /* No inline functions. */
|
||||
# endif
|
||||
|
||||
# define __THROW
|
||||
# define __THROWNL
|
||||
# define __NTH(fct) fct
|
||||
|
||||
#endif /* GCC || clang. */
|
||||
|
||||
/* These two macros are not used in glibc anymore. They are kept here
|
||||
only because some other projects expect the macros to be defined. */
|
||||
#define __P(args) args
|
||||
#define __PMT(args) args
|
||||
|
||||
/* For these things, GCC behaves the ANSI way normally,
|
||||
and the non-ANSI way under -traditional. */
|
||||
|
||||
#define __CONCAT(x,y) x ## y
|
||||
#define __STRING(x) #x
|
||||
|
||||
/* This is not a typedef so `const __ptr_t' does the right thing. */
|
||||
#define __ptr_t void *
|
||||
|
||||
|
||||
/* C++ needs to know that types and declarations are C, not C++. */
|
||||
#ifdef __cplusplus
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
#else
|
||||
# define __BEGIN_DECLS
|
||||
# define __END_DECLS
|
||||
#endif
|
||||
|
||||
|
||||
/* Fortify support. */
|
||||
#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
|
||||
#define __bos0(ptr) __builtin_object_size (ptr, 0)
|
||||
|
||||
/* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */
|
||||
#if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \
|
||||
|| __GNUC_PREREQ (12, 0))
|
||||
# define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
|
||||
# define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1)
|
||||
#else
|
||||
# define __glibc_objsize0(__o) __bos0 (__o)
|
||||
# define __glibc_objsize(__o) __bos (__o)
|
||||
#endif
|
||||
|
||||
/* Compile time conditions to choose between the regular, _chk and _chk_warn
|
||||
variants. These conditions should get evaluated to constant and optimized
|
||||
away. */
|
||||
|
||||
#define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s))
|
||||
#define __glibc_unsigned_or_positive(__l) \
|
||||
((__typeof (__l)) 0 < (__typeof (__l)) -1 \
|
||||
|| (__builtin_constant_p (__l) && (__l) > 0))
|
||||
|
||||
/* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
|
||||
condition can be folded to a constant and if it is true, or unknown (-1) */
|
||||
#define __glibc_safe_or_unknown_len(__l, __s, __osz) \
|
||||
((__osz) == (__SIZE_TYPE__) -1 \
|
||||
|| (__glibc_unsigned_or_positive (__l) \
|
||||
&& __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
|
||||
(__s), (__osz))) \
|
||||
&& __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), (__s), (__osz))))
|
||||
|
||||
/* Conversely, we know at compile time that the length is unsafe if the
|
||||
__L * __S <= __OBJSZ condition can be folded to a constant and if it is
|
||||
false. */
|
||||
#define __glibc_unsafe_len(__l, __s, __osz) \
|
||||
(__glibc_unsigned_or_positive (__l) \
|
||||
&& __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
|
||||
__s, __osz)) \
|
||||
&& !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
|
||||
|
||||
/* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be
|
||||
declared. */
|
||||
|
||||
#define __glibc_fortify(f, __l, __s, __osz, ...) \
|
||||
(__glibc_safe_or_unknown_len (__l, __s, __osz) \
|
||||
? __ ## f ## _alias (__VA_ARGS__) \
|
||||
: (__glibc_unsafe_len (__l, __s, __osz) \
|
||||
? __ ## f ## _chk_warn (__VA_ARGS__, __osz) \
|
||||
: __ ## f ## _chk (__VA_ARGS__, __osz))) \
|
||||
|
||||
/* Fortify function f, where object size argument passed to f is the number of
|
||||
elements and not total size. */
|
||||
|
||||
#define __glibc_fortify_n(f, __l, __s, __osz, ...) \
|
||||
(__glibc_safe_or_unknown_len (__l, __s, __osz) \
|
||||
? __ ## f ## _alias (__VA_ARGS__) \
|
||||
: (__glibc_unsafe_len (__l, __s, __osz) \
|
||||
? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s)) \
|
||||
: __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s)))) \
|
||||
|
||||
#if __GNUC_PREREQ (4,3)
|
||||
# define __warnattr(msg) __attribute__((__warning__ (msg)))
|
||||
# define __errordecl(name, msg) \
|
||||
extern void name (void) __attribute__((__error__ (msg)))
|
||||
#else
|
||||
# define __warnattr(msg)
|
||||
# define __errordecl(name, msg) extern void name (void)
|
||||
#endif
|
||||
|
||||
/* Support for flexible arrays.
|
||||
Headers that should use flexible arrays only if they're "real"
|
||||
(e.g. only if they won't affect sizeof()) should test
|
||||
#if __glibc_c99_flexarr_available. */
|
||||
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc
|
||||
# define __flexarr []
|
||||
# define __glibc_c99_flexarr_available 1
|
||||
#elif __GNUC_PREREQ (2,97) || defined __clang__
|
||||
/* GCC 2.97 and clang support C99 flexible array members as an extension,
|
||||
even when in C89 mode or compiling C++ (any version). */
|
||||
# define __flexarr []
|
||||
# define __glibc_c99_flexarr_available 1
|
||||
#elif defined __GNUC__
|
||||
/* Pre-2.97 GCC did not support C99 flexible arrays but did have
|
||||
an equivalent extension with slightly different notation. */
|
||||
# define __flexarr [0]
|
||||
# define __glibc_c99_flexarr_available 1
|
||||
#else
|
||||
/* Some other non-C99 compiler. Approximate with [1]. */
|
||||
# define __flexarr [1]
|
||||
# define __glibc_c99_flexarr_available 0
|
||||
#endif
|
||||
|
||||
|
||||
/* __asm__ ("xyz") is used throughout the headers to rename functions
|
||||
at the assembly language level. This is wrapped by the __REDIRECT
|
||||
macro, in order to support compilers that can do this some other
|
||||
way. When compilers don't support asm-names at all, we have to do
|
||||
preprocessor tricks instead (which don't have exactly the right
|
||||
semantics, but it's the best we can do).
|
||||
|
||||
Example:
|
||||
int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
|
||||
|
||||
#if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
|
||||
|
||||
# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
|
||||
# ifdef __cplusplus
|
||||
# define __REDIRECT_NTH(name, proto, alias) \
|
||||
name proto __THROW __asm__ (__ASMNAME (#alias))
|
||||
# define __REDIRECT_NTHNL(name, proto, alias) \
|
||||
name proto __THROWNL __asm__ (__ASMNAME (#alias))
|
||||
# else
|
||||
# define __REDIRECT_NTH(name, proto, alias) \
|
||||
name proto __asm__ (__ASMNAME (#alias)) __THROW
|
||||
# define __REDIRECT_NTHNL(name, proto, alias) \
|
||||
name proto __asm__ (__ASMNAME (#alias)) __THROWNL
|
||||
# endif
|
||||
# define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
|
||||
# define __ASMNAME2(prefix, cname) __STRING (prefix) cname
|
||||
|
||||
/*
|
||||
#elif __SOME_OTHER_COMPILER__
|
||||
|
||||
# define __REDIRECT(name, proto, alias) name proto; \
|
||||
_Pragma("let " #name " = " #alias)
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* GCC and clang have various useful declarations that can be made with
|
||||
the '__attribute__' syntax. All of the ways we use this do fine if
|
||||
they are omitted for compilers that don't understand it. */
|
||||
#if !(defined __GNUC__ || defined __clang__)
|
||||
# define __attribute__(xyz) /* Ignore */
|
||||
#endif
|
||||
|
||||
/* At some point during the gcc 2.96 development the `malloc' attribute
|
||||
for functions was introduced. We don't want to use it unconditionally
|
||||
(although this would be possible) since it generates warnings. */
|
||||
#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__)
|
||||
# define __attribute_malloc__ __attribute__ ((__malloc__))
|
||||
#else
|
||||
# define __attribute_malloc__ /* Ignore */
|
||||
#endif
|
||||
|
||||
/* Tell the compiler which arguments to an allocation function
|
||||
indicate the size of the allocation. */
|
||||
#if __GNUC_PREREQ (4, 3)
|
||||
# define __attribute_alloc_size__(params) \
|
||||
__attribute__ ((__alloc_size__ params))
|
||||
#else
|
||||
# define __attribute_alloc_size__(params) /* Ignore. */
|
||||
#endif
|
||||
|
||||
/* Tell the compiler which argument to an allocation function
|
||||
indicates the alignment of the allocation. */
|
||||
#if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__)
|
||||
# define __attribute_alloc_align__(param) \
|
||||
__attribute__ ((__alloc_align__ param))
|
||||
#else
|
||||
# define __attribute_alloc_align__(param) /* Ignore. */
|
||||
#endif
|
||||
|
||||
/* At some point during the gcc 2.96 development the `pure' attribute
|
||||
for functions was introduced. We don't want to use it unconditionally
|
||||
(although this would be possible) since it generates warnings. */
|
||||
#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__)
|
||||
# define __attribute_pure__ __attribute__ ((__pure__))
|
||||
#else
|
||||
# define __attribute_pure__ /* Ignore */
|
||||
#endif
|
||||
|
||||
/* This declaration tells the compiler that the value is constant. */
|
||||
#if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
|
||||
# define __attribute_const__ __attribute__ ((__const__))
|
||||
#else
|
||||
# define __attribute_const__ /* Ignore */
|
||||
#endif
|
||||
|
||||
#if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__)
|
||||
# define __attribute_maybe_unused__ __attribute__ ((__unused__))
|
||||
#else
|
||||
# define __attribute_maybe_unused__ /* Ignore */
|
||||
#endif
|
||||
|
||||
/* At some point during the gcc 3.1 development the `used' attribute
|
||||
for functions was introduced. We don't want to use it unconditionally
|
||||
(although this would be possible) since it generates warnings. */
|
||||
#if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__)
|
||||
# define __attribute_used__ __attribute__ ((__used__))
|
||||
# define __attribute_noinline__ __attribute__ ((__noinline__))
|
||||
#else
|
||||
# define __attribute_used__ __attribute__ ((__unused__))
|
||||
# define __attribute_noinline__ /* Ignore */
|
||||
#endif
|
||||
|
||||
/* Since version 3.2, gcc allows marking deprecated functions. */
|
||||
#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__)
|
||||
# define __attribute_deprecated__ __attribute__ ((__deprecated__))
|
||||
#else
|
||||
# define __attribute_deprecated__ /* Ignore */
|
||||
#endif
|
||||
|
||||
/* Since version 4.5, gcc also allows one to specify the message printed
|
||||
when a deprecated function is used. clang claims to be gcc 4.2, but
|
||||
may also support this feature. */
|
||||
#if __GNUC_PREREQ (4,5) \
|
||||
|| __glibc_has_extension (__attribute_deprecated_with_message__)
|
||||
# define __attribute_deprecated_msg__(msg) \
|
||||
__attribute__ ((__deprecated__ (msg)))
|
||||
#else
|
||||
# define __attribute_deprecated_msg__(msg) __attribute_deprecated__
|
||||
#endif
|
||||
|
||||
/* At some point during the gcc 2.8 development the `format_arg' attribute
|
||||
for functions was introduced. We don't want to use it unconditionally
|
||||
(although this would be possible) since it generates warnings.
|
||||
If several `format_arg' attributes are given for the same function, in
|
||||
gcc-3.0 and older, all but the last one are ignored. In newer gccs,
|
||||
all designated arguments are considered. */
|
||||
#if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__)
|
||||
# define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
|
||||
#else
|
||||
# define __attribute_format_arg__(x) /* Ignore */
|
||||
#endif
|
||||
|
||||
/* At some point during the gcc 2.97 development the `strfmon' format
|
||||
attribute for functions was introduced. We don't want to use it
|
||||
unconditionally (although this would be possible) since it
|
||||
generates warnings. */
|
||||
#if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__)
|
||||
# define __attribute_format_strfmon__(a,b) \
|
||||
__attribute__ ((__format__ (__strfmon__, a, b)))
|
||||
#else
|
||||
# define __attribute_format_strfmon__(a,b) /* Ignore */
|
||||
#endif
|
||||
|
||||
/* The nonnull function attribute marks pointer parameters that
|
||||
must not be NULL. This has the name __nonnull in glibc,
|
||||
and __attribute_nonnull__ in files shared with Gnulib to avoid
|
||||
collision with a different __nonnull in DragonFlyBSD 5.9. */
|
||||
#ifndef __attribute_nonnull__
|
||||
# if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__)
|
||||
# define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
|
||||
# else
|
||||
# define __attribute_nonnull__(params)
|
||||
# endif
|
||||
#endif
|
||||
#ifndef __nonnull
|
||||
# define __nonnull(params) __attribute_nonnull__ (params)
|
||||
#endif
|
||||
|
||||
/* The returns_nonnull function attribute marks the return type of the function
|
||||
as always being non-null. */
|
||||
#ifndef __returns_nonnull
|
||||
# if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__)
|
||||
# define __returns_nonnull __attribute__ ((__returns_nonnull__))
|
||||
# else
|
||||
# define __returns_nonnull
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* If fortification mode, we warn about unused results of certain
|
||||
function calls which can lead to problems. */
|
||||
#if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
|
||||
# define __attribute_warn_unused_result__ \
|
||||
__attribute__ ((__warn_unused_result__))
|
||||
# if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
|
||||
# define __wur __attribute_warn_unused_result__
|
||||
# endif
|
||||
#else
|
||||
# define __attribute_warn_unused_result__ /* empty */
|
||||
#endif
|
||||
#ifndef __wur
|
||||
# define __wur /* Ignore */
|
||||
#endif
|
||||
|
||||
/* Forces a function to be always inlined. */
|
||||
#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__)
|
||||
/* The Linux kernel defines __always_inline in stddef.h (283d7573), and
|
||||
it conflicts with this definition. Therefore undefine it first to
|
||||
allow either header to be included first. */
|
||||
# undef __always_inline
|
||||
# define __always_inline __inline __attribute__ ((__always_inline__))
|
||||
#else
|
||||
# undef __always_inline
|
||||
# define __always_inline __inline
|
||||
#endif
|
||||
|
||||
/* Associate error messages with the source location of the call site rather
|
||||
than with the source location inside the function. */
|
||||
#if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__)
|
||||
# define __attribute_artificial__ __attribute__ ((__artificial__))
|
||||
#else
|
||||
# define __attribute_artificial__ /* Ignore */
|
||||
#endif
|
||||
|
||||
/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
|
||||
inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
|
||||
or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
|
||||
older than 4.3 may define these macros and still not guarantee GNU inlining
|
||||
semantics.
|
||||
|
||||
clang++ identifies itself as gcc-4.2, but has support for GNU inlining
|
||||
semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and
|
||||
__GNUC_GNU_INLINE__ macro definitions. */
|
||||
#if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
|
||||
|| (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
|
||||
|| defined __GNUC_GNU_INLINE__)))
|
||||
# if defined __GNUC_STDC_INLINE__ || defined __cplusplus
|
||||
# define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
|
||||
# define __extern_always_inline \
|
||||
extern __always_inline __attribute__ ((__gnu_inline__))
|
||||
# else
|
||||
# define __extern_inline extern __inline
|
||||
# define __extern_always_inline extern __always_inline
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __extern_always_inline
|
||||
# define __fortify_function __extern_always_inline __attribute_artificial__
|
||||
#endif
|
||||
|
||||
/* GCC 4.3 and above allow passing all anonymous arguments of an
|
||||
__extern_always_inline function to some other vararg function. */
|
||||
#if __GNUC_PREREQ (4,3)
|
||||
# define __va_arg_pack() __builtin_va_arg_pack ()
|
||||
# define __va_arg_pack_len() __builtin_va_arg_pack_len ()
|
||||
#endif
|
||||
|
||||
/* It is possible to compile containing GCC extensions even if GCC is
|
||||
run in pedantic mode if the uses are carefully marked using the
|
||||
`__extension__' keyword. But this is not generally available before
|
||||
version 2.8. */
|
||||
#if !(__GNUC_PREREQ (2,8) || defined __clang__)
|
||||
# define __extension__ /* Ignore */
|
||||
#endif
|
||||
|
||||
/* __restrict is known in EGCS 1.2 and above, and in clang.
|
||||
It works also in C++ mode (outside of arrays), but only when spelled
|
||||
as '__restrict', not 'restrict'. */
|
||||
#if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
|
||||
# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
|
||||
# define __restrict restrict
|
||||
# else
|
||||
# define __restrict /* Ignore */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
|
||||
array_name[restrict]
|
||||
GCC 3.1 and clang support this.
|
||||
This syntax is not usable in C++ mode. */
|
||||
#if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus
|
||||
# define __restrict_arr __restrict
|
||||
#else
|
||||
# ifdef __GNUC__
|
||||
# define __restrict_arr /* Not supported in old GCC. */
|
||||
# else
|
||||
# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
|
||||
# define __restrict_arr restrict
|
||||
# else
|
||||
/* Some other non-C99 compiler. */
|
||||
# define __restrict_arr /* Not supported. */
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect)
|
||||
# define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
|
||||
# define __glibc_likely(cond) __builtin_expect ((cond), 1)
|
||||
#else
|
||||
# define __glibc_unlikely(cond) (cond)
|
||||
# define __glibc_likely(cond) (cond)
|
||||
#endif
|
||||
|
||||
#if (!defined _Noreturn \
|
||||
&& (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
|
||||
&& !(__GNUC_PREREQ (4,7) \
|
||||
|| (3 < __clang_major__ + (5 <= __clang_minor__))))
|
||||
# if __GNUC_PREREQ (2,8)
|
||||
# define _Noreturn __attribute__ ((__noreturn__))
|
||||
# else
|
||||
# define _Noreturn
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if __GNUC_PREREQ (8, 0)
|
||||
/* Describes a char array whose address can safely be passed as the first
|
||||
argument to strncpy and strncat, as the char array is not necessarily
|
||||
a NUL-terminated string. */
|
||||
# define __attribute_nonstring__ __attribute__ ((__nonstring__))
|
||||
#else
|
||||
# define __attribute_nonstring__
|
||||
#endif
|
||||
|
||||
/* Undefine (also defined in libc-symbols.h). */
|
||||
#undef __attribute_copy__
|
||||
#if __GNUC_PREREQ (9, 0)
|
||||
/* Copies attributes from the declaration or type referenced by
|
||||
the argument. */
|
||||
# define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
|
||||
#else
|
||||
# define __attribute_copy__(arg)
|
||||
#endif
|
||||
|
||||
#if (!defined _Static_assert && !defined __cplusplus \
|
||||
&& (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
|
||||
&& (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \
|
||||
|| defined __STRICT_ANSI__))
|
||||
# define _Static_assert(expr, diagnostic) \
|
||||
extern int (*__Static_assert_function (void)) \
|
||||
[!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
|
||||
#endif
|
||||
|
||||
/* Gnulib avoids including these, as they don't work on non-glibc or
|
||||
older glibc platforms. */
|
||||
#ifndef __GNULIB_CDEFS
|
||||
# include <bits/wordsize.h>
|
||||
# include <bits/long-double.h>
|
||||
#endif
|
||||
|
||||
#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
|
||||
# ifdef __REDIRECT
|
||||
|
||||
/* Alias name defined automatically. */
|
||||
# define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
|
||||
# define __LDBL_REDIR_DECL(name) \
|
||||
extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
|
||||
|
||||
/* Alias name defined automatically, with leading underscores. */
|
||||
# define __LDBL_REDIR2_DECL(name) \
|
||||
extern __typeof (__##name) __##name \
|
||||
__asm (__ASMNAME ("__" #name "ieee128"));
|
||||
|
||||
/* Alias name defined manually. */
|
||||
# define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1
|
||||
# define __LDBL_REDIR1_DECL(name, alias) \
|
||||
extern __typeof (name) name __asm (__ASMNAME (#alias));
|
||||
|
||||
# define __LDBL_REDIR1_NTH(name, proto, alias) \
|
||||
__REDIRECT_NTH (name, proto, alias)
|
||||
# define __REDIRECT_NTH_LDBL(name, proto, alias) \
|
||||
__LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
|
||||
|
||||
/* Unused. */
|
||||
# define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl
|
||||
# define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
|
||||
|
||||
# else
|
||||
_Static_assert (0, "IEEE 128-bits long double requires redirection on this platform");
|
||||
# endif
|
||||
#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
|
||||
# define __LDBL_COMPAT 1
|
||||
# ifdef __REDIRECT
|
||||
# define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
|
||||
# define __LDBL_REDIR(name, proto) \
|
||||
__LDBL_REDIR1 (name, proto, __nldbl_##name)
|
||||
# define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
|
||||
# define __LDBL_REDIR_NTH(name, proto) \
|
||||
__LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
|
||||
# define __LDBL_REDIR2_DECL(name) \
|
||||
extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___" #name));
|
||||
# define __LDBL_REDIR1_DECL(name, alias) \
|
||||
extern __typeof (name) name __asm (__ASMNAME (#alias));
|
||||
# define __LDBL_REDIR_DECL(name) \
|
||||
extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
|
||||
# define __REDIRECT_LDBL(name, proto, alias) \
|
||||
__LDBL_REDIR1 (name, proto, __nldbl_##alias)
|
||||
# define __REDIRECT_NTH_LDBL(name, proto, alias) \
|
||||
__LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
|
||||
# endif
|
||||
#endif
|
||||
#if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \
|
||||
|| !defined __REDIRECT
|
||||
# define __LDBL_REDIR1(name, proto, alias) name proto
|
||||
# define __LDBL_REDIR(name, proto) name proto
|
||||
# define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
|
||||
# define __LDBL_REDIR_NTH(name, proto) name proto __THROW
|
||||
# define __LDBL_REDIR2_DECL(name)
|
||||
# define __LDBL_REDIR_DECL(name)
|
||||
# ifdef __REDIRECT
|
||||
# define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
|
||||
# define __REDIRECT_NTH_LDBL(name, proto, alias) \
|
||||
__REDIRECT_NTH (name, proto, alias)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is
|
||||
intended for use in preprocessor macros.
|
||||
|
||||
Note: MESSAGE must be a _single_ string; concatenation of string
|
||||
literals is not supported. */
|
||||
#if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
|
||||
# define __glibc_macro_warning1(message) _Pragma (#message)
|
||||
# define __glibc_macro_warning(message) \
|
||||
__glibc_macro_warning1 (GCC warning message)
|
||||
#else
|
||||
# define __glibc_macro_warning(msg)
|
||||
#endif
|
||||
|
||||
/* Generic selection (ISO C11) is a C-only feature, available in GCC
|
||||
since version 4.9. Previous versions do not provide generic
|
||||
selection, even though they might set __STDC_VERSION__ to 201112L,
|
||||
when in -std=c11 mode. Thus, we must check for !defined __GNUC__
|
||||
when testing __STDC_VERSION__ for generic selection support.
|
||||
On the other hand, Clang also defines __GNUC__, so a clang-specific
|
||||
check is required to enable the use of generic selection. */
|
||||
#if !defined __cplusplus \
|
||||
&& (__GNUC_PREREQ (4, 9) \
|
||||
|| __glibc_has_extension (c_generic_selections) \
|
||||
|| (!defined __GNUC__ && defined __STDC_VERSION__ \
|
||||
&& __STDC_VERSION__ >= 201112L))
|
||||
# define __HAVE_GENERIC_SELECTION 1
|
||||
#else
|
||||
# define __HAVE_GENERIC_SELECTION 0
|
||||
#endif
|
||||
|
||||
#if __GNUC_PREREQ (10, 0)
|
||||
/* Designates a 1-based positional argument ref-index of pointer type
|
||||
that can be used to access size-index elements of the pointed-to
|
||||
array according to access mode, or at least one element when
|
||||
size-index is not provided:
|
||||
access (access-mode, <ref-index> [, <size-index>]) */
|
||||
# define __attr_access(x) __attribute__ ((__access__ x))
|
||||
/* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may
|
||||
use the access attribute to get object sizes from function definition
|
||||
arguments, so we can't use them on functions we fortify. Drop the object
|
||||
size hints for such functions. */
|
||||
# if __USE_FORTIFY_LEVEL == 3
|
||||
# define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o)))
|
||||
# else
|
||||
# define __fortified_attr_access(a, o, s) __attr_access ((a, o, s))
|
||||
# endif
|
||||
# if __GNUC_PREREQ (11, 0)
|
||||
# define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno)))
|
||||
# else
|
||||
# define __attr_access_none(argno)
|
||||
# endif
|
||||
#else
|
||||
# define __fortified_attr_access(a, o, s)
|
||||
# define __attr_access(x)
|
||||
# define __attr_access_none(argno)
|
||||
#endif
|
||||
|
||||
#if __GNUC_PREREQ (11, 0)
|
||||
/* Designates dealloc as a function to call to deallocate objects
|
||||
allocated by the declared function. */
|
||||
# define __attr_dealloc(dealloc, argno) \
|
||||
__attribute__ ((__malloc__ (dealloc, argno)))
|
||||
# define __attr_dealloc_free __attr_dealloc (__builtin_free, 1)
|
||||
#else
|
||||
# define __attr_dealloc(dealloc, argno)
|
||||
# define __attr_dealloc_free
|
||||
#endif
|
||||
|
||||
/* Specify that a function such as setjmp or vfork may return
|
||||
twice. */
|
||||
#if __GNUC_PREREQ (4, 1)
|
||||
# define __attribute_returns_twice__ __attribute__ ((__returns_twice__))
|
||||
#else
|
||||
# define __attribute_returns_twice__ /* Ignore. */
|
||||
#endif
|
||||
|
||||
#endif /* sys/cdefs.h */
|
||||
@@ -1,36 +0,0 @@
|
||||
/* cloexec.c - set or clear the close-on-exec descriptor flag
|
||||
|
||||
Copyright (C) 2004, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
|
||||
or clear the flag if VALUE is false.
|
||||
Return 0 on success, or -1 on error with 'errno' set.
|
||||
|
||||
Note that on MingW, this function does NOT protect DESC from being
|
||||
inherited into spawned children. Instead, either use dup_cloexec
|
||||
followed by closing the original DESC, or use interfaces such as
|
||||
open or pipe2 that accept flags like O_CLOEXEC to create DESC
|
||||
non-inheritable in the first place. */
|
||||
|
||||
int set_cloexec_flag (int desc, bool value);
|
||||
|
||||
/* Duplicates a file handle FD, while marking the copy to be closed
|
||||
prior to exec or spawn. Returns -1 and sets errno if FD could not
|
||||
be duplicated. */
|
||||
|
||||
int dup_cloexec (int fd);
|
||||
@@ -1,75 +0,0 @@
|
||||
/* close replacement.
|
||||
Copyright (C) 2008-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <unistd.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "fd-hook.h"
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
# include "msvc-inval.h"
|
||||
#endif
|
||||
|
||||
#undef close
|
||||
|
||||
#if defined _WIN32 && !defined __CYGWIN__
|
||||
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
static int
|
||||
close_nothrow (int fd)
|
||||
{
|
||||
int result;
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = _close (fd);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
result = -1;
|
||||
errno = EBADF;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
return result;
|
||||
}
|
||||
# else
|
||||
# define close_nothrow _close
|
||||
# endif
|
||||
#else
|
||||
# define close_nothrow close
|
||||
#endif
|
||||
|
||||
/* Override close() to call into other gnulib modules. */
|
||||
|
||||
int
|
||||
rpl_close (int fd)
|
||||
{
|
||||
#if WINDOWS_SOCKETS
|
||||
int retval = execute_all_close_hooks (close_nothrow, fd);
|
||||
#else
|
||||
int retval = close_nothrow (fd);
|
||||
#endif
|
||||
|
||||
#if REPLACE_FCHDIR
|
||||
if (retval >= 0)
|
||||
_gl_unregister_fd (fd);
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
/* Duplicate an open file descriptor to a specified file descriptor.
|
||||
|
||||
Copyright (C) 1999, 2004-2007, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* written by Paul Eggert */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <unistd.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#undef dup2
|
||||
|
||||
#if defined _WIN32 && ! defined __CYGWIN__
|
||||
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
|
||||
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
# include "msvc-inval.h"
|
||||
# endif
|
||||
|
||||
/* Get _get_osfhandle. */
|
||||
# if GNULIB_MSVC_NOTHROW
|
||||
# include "msvc-nothrow.h"
|
||||
# else
|
||||
# include <io.h>
|
||||
# endif
|
||||
|
||||
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
static int
|
||||
dup2_nothrow (int fd, int desired_fd)
|
||||
{
|
||||
int result;
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = _dup2 (fd, desired_fd);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
errno = EBADF;
|
||||
result = -1;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
return result;
|
||||
}
|
||||
# else
|
||||
# define dup2_nothrow _dup2
|
||||
# endif
|
||||
|
||||
static int
|
||||
ms_windows_dup2 (int fd, int desired_fd)
|
||||
{
|
||||
int result;
|
||||
|
||||
/* If fd is closed, mingw hangs on dup2 (fd, fd). If fd is open,
|
||||
dup2 (fd, fd) returns 0, but all further attempts to use fd in
|
||||
future dup2 calls will hang. */
|
||||
if (fd == desired_fd)
|
||||
{
|
||||
if ((HANDLE) _get_osfhandle (fd) == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* Wine 1.0.1 return 0 when desired_fd is negative but not -1:
|
||||
https://bugs.winehq.org/show_bug.cgi?id=21289 */
|
||||
if (desired_fd < 0)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = dup2_nothrow (fd, desired_fd);
|
||||
|
||||
if (result == 0)
|
||||
result = desired_fd;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
# define dup2 ms_windows_dup2
|
||||
|
||||
#elif defined __KLIBC__
|
||||
|
||||
# include <InnoTekLIBC/backend.h>
|
||||
|
||||
static int
|
||||
klibc_dup2dirfd (int fd, int desired_fd)
|
||||
{
|
||||
int tempfd;
|
||||
int dupfd;
|
||||
|
||||
tempfd = open ("NUL", O_RDONLY);
|
||||
if (tempfd == -1)
|
||||
return -1;
|
||||
|
||||
if (tempfd == desired_fd)
|
||||
{
|
||||
close (tempfd);
|
||||
|
||||
char path[_MAX_PATH];
|
||||
if (__libc_Back_ioFHToPath (fd, path, sizeof (path)))
|
||||
return -1;
|
||||
|
||||
return open(path, O_RDONLY);
|
||||
}
|
||||
|
||||
dupfd = klibc_dup2dirfd (fd, desired_fd);
|
||||
|
||||
close (tempfd);
|
||||
|
||||
return dupfd;
|
||||
}
|
||||
|
||||
static int
|
||||
klibc_dup2 (int fd, int desired_fd)
|
||||
{
|
||||
int dupfd;
|
||||
struct stat sbuf;
|
||||
|
||||
dupfd = dup2 (fd, desired_fd);
|
||||
if (dupfd == -1 && errno == ENOTSUP \
|
||||
&& !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
|
||||
{
|
||||
close (desired_fd);
|
||||
|
||||
return klibc_dup2dirfd (fd, desired_fd);
|
||||
}
|
||||
|
||||
return dupfd;
|
||||
}
|
||||
|
||||
# define dup2 klibc_dup2
|
||||
#endif
|
||||
|
||||
int
|
||||
rpl_dup2 (int fd, int desired_fd)
|
||||
{
|
||||
int result;
|
||||
|
||||
#ifdef F_GETFL
|
||||
/* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
|
||||
On Cygwin 1.5.x, dup2 (1, 1) returns 0.
|
||||
On Cygwin 1.7.17, dup2 (1, -1) dumps core.
|
||||
On Cygwin 1.7.25, dup2 (1, 256) can dump core.
|
||||
On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */
|
||||
# if HAVE_SETDTABLESIZE
|
||||
setdtablesize (desired_fd + 1);
|
||||
# endif
|
||||
if (desired_fd < 0)
|
||||
fd = desired_fd;
|
||||
if (fd == desired_fd)
|
||||
return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
|
||||
#endif
|
||||
|
||||
result = dup2 (fd, desired_fd);
|
||||
|
||||
/* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x. */
|
||||
if (result == -1 && errno == EMFILE)
|
||||
errno = EBADF;
|
||||
#if REPLACE_FCHDIR
|
||||
if (fd != desired_fd && result != -1)
|
||||
result = _gl_register_dup (fd, result);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/* Threshold at which to diagnose ELOOP. Generic version.
|
||||
Copyright (C) 2012-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _ELOOP_THRESHOLD_H
|
||||
#define _ELOOP_THRESHOLD_H 1
|
||||
|
||||
#include <limits.h>
|
||||
#ifdef _LIBC
|
||||
# include <sys/param.h>
|
||||
# define _GL_ATTRIBUTE_CONST __attribute__ ((const))
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include "minmax.h"
|
||||
# define __sysconf sysconf
|
||||
# if (!defined SYMLOOP_MAX \
|
||||
&& ! (defined _SC_SYMLOOP_MAX && defined _POSIX_SYMLOOP_MAX))
|
||||
# define SYMLOOP_MAX 8
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* POSIX specifies SYMLOOP_MAX as the "Maximum number of symbolic
|
||||
links that can be reliably traversed in the resolution of a
|
||||
pathname in the absence of a loop." This makes it a minimum that
|
||||
we should certainly accept. But it leaves open the possibility
|
||||
that more might sometimes work--just not "reliably".
|
||||
|
||||
For example, Linux implements a complex policy whereby there is a
|
||||
small limit on the number of direct symlink traversals (a symlink
|
||||
to a symlink to a symlink), but larger limit on the total number of
|
||||
symlink traversals overall. Hence the SYMLOOP_MAX number should be
|
||||
the small one, but the limit library functions enforce on users
|
||||
should be the larger one.
|
||||
|
||||
So, we use the larger of the reported SYMLOOP_MAX (if any) and our
|
||||
own constant MIN_ELOOP_THRESHOLD, below. This constant should be
|
||||
large enough that it never rules out a file name and directory tree
|
||||
that the underlying system (i.e. calls to 'open' et al) would
|
||||
resolve successfully. It should be small enough that actual loops
|
||||
are detected without a huge number of iterations. */
|
||||
|
||||
#ifndef MIN_ELOOP_THRESHOLD
|
||||
# define MIN_ELOOP_THRESHOLD 40
|
||||
#endif
|
||||
|
||||
/* Return the maximum number of symlink traversals to permit
|
||||
before diagnosing ELOOP. */
|
||||
static inline unsigned int _GL_ATTRIBUTE_CONST
|
||||
__eloop_threshold (void)
|
||||
{
|
||||
#ifdef SYMLOOP_MAX
|
||||
const int symloop_max = SYMLOOP_MAX;
|
||||
#else
|
||||
/* The function is marked 'const' even though we use memory and
|
||||
call a function, because sysconf is required to return the
|
||||
same value in every call and so it must always be safe to
|
||||
call __eloop_threshold exactly once and reuse the value. */
|
||||
static long int sysconf_symloop_max;
|
||||
if (sysconf_symloop_max == 0)
|
||||
sysconf_symloop_max = __sysconf (_SC_SYMLOOP_MAX);
|
||||
const unsigned int symloop_max = (sysconf_symloop_max <= 0
|
||||
? _POSIX_SYMLOOP_MAX
|
||||
: sysconf_symloop_max);
|
||||
#endif
|
||||
|
||||
return MAX (symloop_max, MIN_ELOOP_THRESHOLD);
|
||||
}
|
||||
|
||||
#endif /* eloop-threshold.h */
|
||||
@@ -1,411 +0,0 @@
|
||||
/* Error handler for noninteractive utilities
|
||||
Copyright (C) 1990-1998, 2000-2007, 2009-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
|
||||
|
||||
#if !_LIBC
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "error.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !_LIBC && ENABLE_NLS
|
||||
# include "gettext.h"
|
||||
# define _(msgid) gettext (msgid)
|
||||
#endif
|
||||
|
||||
#ifdef _LIBC
|
||||
# include <libintl.h>
|
||||
# include <stdbool.h>
|
||||
# include <stdint.h>
|
||||
# include <wchar.h>
|
||||
# define mbsrtowcs __mbsrtowcs
|
||||
# define USE_UNLOCKED_IO 0
|
||||
# define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(a, b)
|
||||
# define _GL_ARG_NONNULL(a)
|
||||
#else
|
||||
# include "getprogname.h"
|
||||
#endif
|
||||
|
||||
#if USE_UNLOCKED_IO
|
||||
# include "unlocked-io.h"
|
||||
#endif
|
||||
|
||||
#ifndef _
|
||||
# define _(String) String
|
||||
#endif
|
||||
|
||||
/* If NULL, error will flush stdout, then print on stderr the program
|
||||
name, a colon and a space. Otherwise, error will call this
|
||||
function without parameters instead. */
|
||||
void (*error_print_progname) (void);
|
||||
|
||||
/* This variable is incremented each time 'error' is called. */
|
||||
unsigned int error_message_count;
|
||||
|
||||
#ifdef _LIBC
|
||||
/* In the GNU C library, there is a predefined variable for this. */
|
||||
|
||||
# define program_name program_invocation_name
|
||||
# include <errno.h>
|
||||
# include <limits.h>
|
||||
# include <libio/libioP.h>
|
||||
|
||||
/* In GNU libc we want do not want to use the common name 'error' directly.
|
||||
Instead make it a weak alias. */
|
||||
extern void __error (int status, int errnum, const char *message, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
extern void __error_at_line (int status, int errnum, const char *file_name,
|
||||
unsigned int line_number, const char *message,
|
||||
...)
|
||||
__attribute__ ((__format__ (__printf__, 5, 6)));
|
||||
# define error __error
|
||||
# define error_at_line __error_at_line
|
||||
|
||||
# include <libio/iolibio.h>
|
||||
# define fflush(s) _IO_fflush (s)
|
||||
# undef putc
|
||||
# define putc(c, fp) _IO_putc (c, fp)
|
||||
|
||||
# include <bits/libc-lock.h>
|
||||
|
||||
#else /* not _LIBC */
|
||||
|
||||
# include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
|
||||
# if defined _WIN32 && ! defined __CYGWIN__
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
/* Get _get_osfhandle. */
|
||||
# if GNULIB_MSVC_NOTHROW
|
||||
# include "msvc-nothrow.h"
|
||||
# else
|
||||
# include <io.h>
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* The gnulib override of fcntl is not needed in this file. */
|
||||
# undef fcntl
|
||||
|
||||
# if !(GNULIB_STRERROR_R_POSIX || HAVE_DECL_STRERROR_R)
|
||||
# ifndef HAVE_DECL_STRERROR_R
|
||||
"this configure-time declaration test was not run"
|
||||
# endif
|
||||
# if STRERROR_R_CHAR_P
|
||||
char *strerror_r (int errnum, char *buf, size_t buflen);
|
||||
# else
|
||||
int strerror_r (int errnum, char *buf, size_t buflen);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# define program_name getprogname ()
|
||||
|
||||
# if GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r
|
||||
# define __strerror_r strerror_r
|
||||
# endif /* GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r */
|
||||
#endif /* not _LIBC */
|
||||
|
||||
#if !_LIBC
|
||||
/* Return non-zero if FD is open. */
|
||||
static int
|
||||
is_open (int fd)
|
||||
{
|
||||
# if defined _WIN32 && ! defined __CYGWIN__
|
||||
/* On native Windows: The initial state of unassigned standard file
|
||||
descriptors is that they are open but point to an INVALID_HANDLE_VALUE.
|
||||
There is no fcntl, and the gnulib replacement fcntl does not support
|
||||
F_GETFL. */
|
||||
return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
|
||||
# else
|
||||
# ifndef F_GETFL
|
||||
# error Please port fcntl to your platform
|
||||
# endif
|
||||
return 0 <= fcntl (fd, F_GETFL);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
flush_stdout (void)
|
||||
{
|
||||
#if !_LIBC
|
||||
int stdout_fd;
|
||||
|
||||
# if GNULIB_FREOPEN_SAFER
|
||||
/* Use of gnulib's freopen-safer module normally ensures that
|
||||
fileno (stdout) == 1
|
||||
whenever stdout is open. */
|
||||
stdout_fd = STDOUT_FILENO;
|
||||
# else
|
||||
/* POSIX states that fileno (stdout) after fclose is unspecified. But in
|
||||
practice it is not a problem, because stdout is statically allocated and
|
||||
the fd of a FILE stream is stored as a field in its allocated memory. */
|
||||
stdout_fd = fileno (stdout);
|
||||
# endif
|
||||
/* POSIX states that fflush (stdout) after fclose is unspecified; it
|
||||
is safe in glibc, but not on all other platforms. fflush (NULL)
|
||||
is always defined, but too draconian. */
|
||||
if (0 <= stdout_fd && is_open (stdout_fd))
|
||||
#endif
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
static void
|
||||
print_errno_message (int errnum)
|
||||
{
|
||||
char const *s;
|
||||
|
||||
#if _LIBC || GNULIB_STRERROR_R_POSIX || defined HAVE_STRERROR_R
|
||||
char errbuf[1024];
|
||||
# if _LIBC || (!GNULIB_STRERROR_R_POSIX && STRERROR_R_CHAR_P)
|
||||
s = __strerror_r (errnum, errbuf, sizeof errbuf);
|
||||
# else
|
||||
if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
|
||||
s = errbuf;
|
||||
else
|
||||
s = 0;
|
||||
# endif
|
||||
#else
|
||||
s = strerror (errnum);
|
||||
#endif
|
||||
|
||||
#if !_LIBC
|
||||
if (! s)
|
||||
s = _("Unknown system error");
|
||||
#endif
|
||||
|
||||
#if _LIBC
|
||||
__fxprintf (NULL, ": %s", s);
|
||||
#else
|
||||
fprintf (stderr, ": %s", s);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0) _GL_ARG_NONNULL ((3))
|
||||
error_tail (int status, int errnum, const char *message, va_list args)
|
||||
{
|
||||
#if _LIBC
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
{
|
||||
size_t len = strlen (message) + 1;
|
||||
wchar_t *wmessage = NULL;
|
||||
mbstate_t st;
|
||||
size_t res;
|
||||
const char *tmp;
|
||||
bool use_malloc = false;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (__libc_use_alloca (len * sizeof (wchar_t)))
|
||||
wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
|
||||
else
|
||||
{
|
||||
if (!use_malloc)
|
||||
wmessage = NULL;
|
||||
|
||||
wchar_t *p = (wchar_t *) realloc (wmessage,
|
||||
len * sizeof (wchar_t));
|
||||
if (p == NULL)
|
||||
{
|
||||
free (wmessage);
|
||||
fputws_unlocked (L"out of memory\n", stderr);
|
||||
return;
|
||||
}
|
||||
wmessage = p;
|
||||
use_malloc = true;
|
||||
}
|
||||
|
||||
memset (&st, '\0', sizeof (st));
|
||||
tmp = message;
|
||||
|
||||
res = mbsrtowcs (wmessage, &tmp, len, &st);
|
||||
if (res != len)
|
||||
break;
|
||||
|
||||
if (__builtin_expect (len >= SIZE_MAX / sizeof (wchar_t) / 2, 0))
|
||||
{
|
||||
/* This really should not happen if everything is fine. */
|
||||
res = (size_t) -1;
|
||||
break;
|
||||
}
|
||||
|
||||
len *= 2;
|
||||
}
|
||||
|
||||
if (res == (size_t) -1)
|
||||
{
|
||||
/* The string cannot be converted. */
|
||||
if (use_malloc)
|
||||
{
|
||||
free (wmessage);
|
||||
use_malloc = false;
|
||||
}
|
||||
wmessage = (wchar_t *) L"???";
|
||||
}
|
||||
|
||||
__vfwprintf (stderr, wmessage, args);
|
||||
|
||||
if (use_malloc)
|
||||
free (wmessage);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
vfprintf (stderr, message, args);
|
||||
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
print_errno_message (errnum);
|
||||
#if _LIBC
|
||||
__fxprintf (NULL, "\n");
|
||||
#else
|
||||
putc ('\n', stderr);
|
||||
#endif
|
||||
fflush (stderr);
|
||||
if (status)
|
||||
exit (status);
|
||||
}
|
||||
|
||||
|
||||
/* Print the program name and error message MESSAGE, which is a printf-style
|
||||
format string with optional args.
|
||||
If ERRNUM is nonzero, print its corresponding system error message.
|
||||
Exit with status STATUS if it is nonzero. */
|
||||
void
|
||||
error (int status, int errnum, const char *message, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
#if defined _LIBC && defined __libc_ptf_call
|
||||
/* We do not want this call to be cut short by a thread
|
||||
cancellation. Therefore disable cancellation for now. */
|
||||
int state = PTHREAD_CANCEL_ENABLE;
|
||||
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
|
||||
0);
|
||||
#endif
|
||||
|
||||
flush_stdout ();
|
||||
#ifdef _LIBC
|
||||
_IO_flockfile (stderr);
|
||||
#endif
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
#if _LIBC
|
||||
__fxprintf (NULL, "%s: ", program_name);
|
||||
#else
|
||||
fprintf (stderr, "%s: ", program_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
va_start (args, message);
|
||||
error_tail (status, errnum, message, args);
|
||||
va_end (args);
|
||||
|
||||
#ifdef _LIBC
|
||||
_IO_funlockfile (stderr);
|
||||
# ifdef __libc_ptf_call
|
||||
__libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Sometimes we want to have at most one error per line. This
|
||||
variable controls whether this mode is selected or not. */
|
||||
int error_one_per_line;
|
||||
|
||||
void
|
||||
error_at_line (int status, int errnum, const char *file_name,
|
||||
unsigned int line_number, const char *message, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (error_one_per_line)
|
||||
{
|
||||
static const char *old_file_name;
|
||||
static unsigned int old_line_number;
|
||||
|
||||
if (old_line_number == line_number
|
||||
&& (file_name == old_file_name
|
||||
|| (old_file_name != NULL
|
||||
&& file_name != NULL
|
||||
&& strcmp (old_file_name, file_name) == 0)))
|
||||
|
||||
/* Simply return and print nothing. */
|
||||
return;
|
||||
|
||||
old_file_name = file_name;
|
||||
old_line_number = line_number;
|
||||
}
|
||||
|
||||
#if defined _LIBC && defined __libc_ptf_call
|
||||
/* We do not want this call to be cut short by a thread
|
||||
cancellation. Therefore disable cancellation for now. */
|
||||
int state = PTHREAD_CANCEL_ENABLE;
|
||||
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
|
||||
0);
|
||||
#endif
|
||||
|
||||
flush_stdout ();
|
||||
#ifdef _LIBC
|
||||
_IO_flockfile (stderr);
|
||||
#endif
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
#if _LIBC
|
||||
__fxprintf (NULL, "%s:", program_name);
|
||||
#else
|
||||
fprintf (stderr, "%s:", program_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if _LIBC
|
||||
__fxprintf (NULL, file_name != NULL ? "%s:%u: " : " ",
|
||||
file_name, line_number);
|
||||
#else
|
||||
fprintf (stderr, file_name != NULL ? "%s:%u: " : " ",
|
||||
file_name, line_number);
|
||||
#endif
|
||||
|
||||
va_start (args, message);
|
||||
error_tail (status, errnum, message, args);
|
||||
va_end (args);
|
||||
|
||||
#ifdef _LIBC
|
||||
_IO_funlockfile (stderr);
|
||||
# ifdef __libc_ptf_call
|
||||
__libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _LIBC
|
||||
/* Make the weak alias. */
|
||||
# undef error
|
||||
# undef error_at_line
|
||||
weak_alias (__error, error)
|
||||
weak_alias (__error_at_line, error_at_line)
|
||||
#endif
|
||||
@@ -1,66 +0,0 @@
|
||||
/* Declaration for error-reporting function
|
||||
Copyright (C) 1995-1997, 2003, 2006, 2008-2022 Free Software Foundation,
|
||||
Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _ERROR_H
|
||||
#define _ERROR_H 1
|
||||
|
||||
/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM. */
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Print a message with 'fprintf (stderr, FORMAT, ...)';
|
||||
if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
|
||||
If STATUS is nonzero, terminate the program with 'exit (STATUS)'. */
|
||||
|
||||
extern void error (int __status, int __errnum, const char *__format, ...)
|
||||
#if GNULIB_VFPRINTF_POSIX
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 4))
|
||||
#else
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 3, 4))
|
||||
#endif
|
||||
;
|
||||
|
||||
extern void error_at_line (int __status, int __errnum, const char *__fname,
|
||||
unsigned int __lineno, const char *__format, ...)
|
||||
#if GNULIB_VFPRINTF_POSIX
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 5, 6))
|
||||
#else
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 5, 6))
|
||||
#endif
|
||||
;
|
||||
|
||||
/* If NULL, error will flush stdout, then print on stderr the program
|
||||
name, a colon and a space. Otherwise, error will call this
|
||||
function without parameters instead. */
|
||||
extern DLL_VARIABLE void (*error_print_progname) (void);
|
||||
|
||||
/* This variable is incremented each time 'error' is called. */
|
||||
extern DLL_VARIABLE unsigned int error_message_count;
|
||||
|
||||
/* Sometimes we want to have at most one error per line. This
|
||||
variable controls whether this mode is selected or not. */
|
||||
extern DLL_VARIABLE int error_one_per_line;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* error.h */
|
||||
@@ -1,952 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* Like <fcntl.h>, but with non-working flags defined to 0.
|
||||
|
||||
Copyright (C) 2006-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* written by Paul Eggert */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
|
||||
#if defined __need_system_fcntl_h
|
||||
/* Special invocation convention. */
|
||||
|
||||
/* Needed before <sys/stat.h>.
|
||||
May also define off_t to a 64-bit type on native Windows. */
|
||||
#include <sys/types.h>
|
||||
/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
|
||||
<fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
|
||||
But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
|
||||
extern "C" { ... } block, which leads to errors in C++ mode with the
|
||||
overridden <sys/stat.h> from gnulib. These errors are known to be gone
|
||||
with g++ version >= 4.3. */
|
||||
#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#include_next <fcntl.h>
|
||||
|
||||
/* Native Windows platforms declare open(), creat() in <io.h>. */
|
||||
#if (0 || 1 || defined GNULIB_POSIXCHECK) \
|
||||
&& (defined _WIN32 && ! defined __CYGWIN__)
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
#ifndef _GL_FCNTL_H
|
||||
|
||||
/* Needed before <sys/stat.h>.
|
||||
May also define off_t to a 64-bit type on native Windows. */
|
||||
#include <sys/types.h>
|
||||
/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
|
||||
<fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
|
||||
But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
|
||||
extern "C" { ... } block, which leads to errors in C++ mode with the
|
||||
overridden <sys/stat.h> from gnulib. These errors are known to be gone
|
||||
with g++ version >= 4.3. */
|
||||
#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#include_next <fcntl.h>
|
||||
|
||||
/* Native Windows platforms declare open(), creat() in <io.h>. */
|
||||
#if (0 || 1 || defined GNULIB_POSIXCHECK) \
|
||||
&& (defined _WIN32 && ! defined __CYGWIN__)
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#ifndef _GL_FCNTL_H
|
||||
#define _GL_FCNTL_H
|
||||
|
||||
#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
/* C++ compatible function declaration macros.
|
||||
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GL_CXXDEFS_H
|
||||
#define _GL_CXXDEFS_H
|
||||
|
||||
/* Begin/end the GNULIB_NAMESPACE namespace. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
|
||||
# define _GL_END_NAMESPACE }
|
||||
#else
|
||||
# define _GL_BEGIN_NAMESPACE
|
||||
# define _GL_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
/* The three most frequent use cases of these macros are:
|
||||
|
||||
* For providing a substitute for a function that is missing on some
|
||||
platforms, but is declared and works fine on the platforms on which
|
||||
it exists:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if !@HAVE_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on all platforms,
|
||||
but is broken/insufficient and needs to be replaced on some platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on some platforms
|
||||
but is broken/insufficient and needs to be replaced on some of them and
|
||||
is additionally either missing or undeclared on some other platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
# if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
*/
|
||||
|
||||
/* _GL_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#if defined __cplusplus
|
||||
# define _GL_EXTERN_C extern "C"
|
||||
#else
|
||||
# define _GL_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
|
||||
declares a replacement function, named rpl_func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
|
||||
_GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
|
||||
#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype rpl_func parameters_and_attributes
|
||||
|
||||
/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
|
||||
declares the system function, named func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype func parameters_and_attributes
|
||||
|
||||
/* _GL_CXXALIAS_RPL (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
|
||||
|
||||
Wrapping rpl_func in an object with an inline conversion operator
|
||||
avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
|
||||
actually used in the program. */
|
||||
#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return ::rpl_func; \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||
is to be used when func is a Microsoft deprecated alias, on native Windows.
|
||||
It declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to _func, if GNULIB_NAMESPACE is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
|
||||
*/
|
||||
#define _GL_CXXALIAS_MDA(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_1 (func, _##func, rettype, parameters)
|
||||
|
||||
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
|
||||
except that the C function rpl_func may have a slightly different
|
||||
declaration. A cast is used to silence the "invalid conversion" error
|
||||
that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>(::rpl_func); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_MDA_CAST (func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||
except that the C function func may have a slightly different declaration.
|
||||
A cast is used to silence the "invalid conversion" error that would
|
||||
otherwise occur. */
|
||||
#define _GL_CXXALIAS_MDA_CAST(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_CAST_1 (func, _##func, rettype, parameters)
|
||||
|
||||
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to the system provided function func, if GNULIB_NAMESPACE
|
||||
is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
|
||||
|
||||
Wrapping func in an object with an inline conversion operator
|
||||
avoids a reference to func unless GNULIB_NAMESPACE::func is
|
||||
actually used in the program. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return ::func; \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function func may have a slightly different declaration.
|
||||
A cast is used to silence the "invalid conversion" error that would
|
||||
otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>(::func); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function is picked among a set of overloaded functions,
|
||||
namely the one with rettype2 and parameters2. Two consecutive casts
|
||||
are used to silence the "cannot find a match" and "invalid conversion"
|
||||
errors that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
/* The outer cast must be a reinterpret_cast.
|
||||
The inner cast: When the function is defined as a set of overloaded
|
||||
functions, it works as a static_cast<>, choosing the designated variant.
|
||||
When the function is defined as a single variant, it works as a
|
||||
reinterpret_cast<>. The parenthesized cast syntax works both ways. */
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN (func);
|
||||
causes a warning to be emitted when ::func is used but not when
|
||||
GNULIB_NAMESPACE::func is used. func must be defined without overloaded
|
||||
variants. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN_1(func,namespace) \
|
||||
_GL_CXXALIASWARN_2 (func, namespace)
|
||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_WARN_ON_USE (func, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
extern __typeof__ (func) func
|
||||
# else
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
|
||||
causes a warning to be emitted when the given overloaded variant of ::func
|
||||
is used but not when GNULIB_NAMESPACE::func is used. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
|
||||
GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
|
||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_WARN_ON_USE_CXX (func, rettype, rettype, parameters_and_attributes, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# else
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
#endif /* _GL_CXXDEFS_H */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
/* A C macro for declaring that specific arguments must not be NULL.
|
||||
Copyright (C) 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
|
||||
that the values passed as arguments n, ..., m must be non-NULL pointers.
|
||||
n = 1 stands for the first argument, n = 2 for the second argument etc. */
|
||||
#ifndef _GL_ARG_NONNULL
|
||||
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__
|
||||
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
|
||||
# else
|
||||
# define _GL_ARG_NONNULL(params)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
/* A C macro for emitting warnings if a function is used.
|
||||
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
|
||||
for FUNCTION which will then trigger a compiler warning containing
|
||||
the text of "literal string" anywhere that function is called, if
|
||||
supported by the compiler. If the compiler does not support this
|
||||
feature, the macro expands to an unused extern declaration.
|
||||
|
||||
_GL_WARN_ON_USE_ATTRIBUTE ("literal string") expands to the
|
||||
attribute used in _GL_WARN_ON_USE. If the compiler does not support
|
||||
this feature, it expands to empty.
|
||||
|
||||
These macros are useful for marking a function as a potential
|
||||
portability trap, with the intent that "literal string" include
|
||||
instructions on the replacement function that should be used
|
||||
instead.
|
||||
_GL_WARN_ON_USE is for functions with 'extern' linkage.
|
||||
_GL_WARN_ON_USE_ATTRIBUTE is for functions with 'static' or 'inline'
|
||||
linkage.
|
||||
|
||||
However, one of the reasons that a function is a portability trap is
|
||||
if it has the wrong signature. Declaring FUNCTION with a different
|
||||
signature in C is a compilation error, so this macro must use the
|
||||
same type as any existing declaration so that programs that avoid
|
||||
the problematic FUNCTION do not fail to compile merely because they
|
||||
included a header that poisoned the function. But this implies that
|
||||
_GL_WARN_ON_USE is only safe to use if FUNCTION is known to already
|
||||
have a declaration. Use of this macro implies that there must not
|
||||
be any other macro hiding the declaration of FUNCTION; but
|
||||
undefining FUNCTION first is part of the poisoning process anyway
|
||||
(although for symbols that are provided only via a macro, the result
|
||||
is a compilation error rather than a warning containing
|
||||
"literal string"). Also note that in C++, it is only safe to use if
|
||||
FUNCTION has no overloads.
|
||||
|
||||
For an example, it is possible to poison 'getline' by:
|
||||
- adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
|
||||
[getline]) in configure.ac, which potentially defines
|
||||
HAVE_RAW_DECL_GETLINE
|
||||
- adding this code to a header that wraps the system <stdio.h>:
|
||||
#undef getline
|
||||
#if HAVE_RAW_DECL_GETLINE
|
||||
_GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
|
||||
"not universally present; use the gnulib module getline");
|
||||
#endif
|
||||
|
||||
It is not possible to directly poison global variables. But it is
|
||||
possible to write a wrapper accessor function, and poison that
|
||||
(less common usage, like &environ, will cause a compilation error
|
||||
rather than issue the nice warning, but the end result of informing
|
||||
the developer about their portability problem is still achieved):
|
||||
#if HAVE_RAW_DECL_ENVIRON
|
||||
static char ***
|
||||
rpl_environ (void) { return &environ; }
|
||||
_GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
|
||||
# undef environ
|
||||
# define environ (*rpl_environ ())
|
||||
#endif
|
||||
or better (avoiding contradictory use of 'static' and 'extern'):
|
||||
#if HAVE_RAW_DECL_ENVIRON
|
||||
static char ***
|
||||
_GL_WARN_ON_USE_ATTRIBUTE ("environ is not always properly declared")
|
||||
rpl_environ (void) { return &environ; }
|
||||
# undef environ
|
||||
# define environ (*rpl_environ ())
|
||||
#endif
|
||||
*/
|
||||
#ifndef _GL_WARN_ON_USE
|
||||
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function __attribute__ ((__warning__ (message)))
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
||||
__attribute__ ((__warning__ (message)))
|
||||
# elif __clang_major__ >= 4
|
||||
/* Another compiler attribute is available in clang. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function \
|
||||
__attribute__ ((__diagnose_if__ (1, message, "warning")))
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
||||
__attribute__ ((__diagnose_if__ (1, message, "warning")))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message)
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_ON_USE_CXX (function, rettype_gcc, rettype_clang, parameters_and_attributes, "message")
|
||||
is like _GL_WARN_ON_USE (function, "message"), except that in C++ mode the
|
||||
function is declared with the given prototype, consisting of return type,
|
||||
parameters, and attributes.
|
||||
This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
|
||||
not work in this case. */
|
||||
#ifndef _GL_WARN_ON_USE_CXX
|
||||
# if !defined __cplusplus
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
_GL_WARN_ON_USE (function, msg)
|
||||
# else
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_gcc function parameters_and_attributes \
|
||||
__attribute__ ((__warning__ (msg)))
|
||||
# elif __clang_major__ >= 4
|
||||
/* Another compiler attribute is available in clang. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_clang function parameters_and_attributes \
|
||||
__attribute__ ((__diagnose_if__ (1, msg, "warning")))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_gcc function parameters_and_attributes
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#ifndef _GL_WARN_EXTERN_C
|
||||
# if defined __cplusplus
|
||||
# define _GL_WARN_EXTERN_C extern "C"
|
||||
# else
|
||||
# define _GL_WARN_EXTERN_C extern
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Declare overridden functions. */
|
||||
|
||||
#if 0
|
||||
# if 0
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef creat
|
||||
# define creat rpl_creat
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (creat, int, (const char *filename, mode_t mode)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (creat, int, (const char *filename, mode_t mode));
|
||||
# elif defined _WIN32 && !defined __CYGWIN__
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef creat
|
||||
# define creat _creat
|
||||
# endif
|
||||
_GL_CXXALIAS_MDA (creat, int, (const char *filename, mode_t mode));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (creat);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef creat
|
||||
/* Assume creat is always declared. */
|
||||
_GL_WARN_ON_USE (creat, "creat is not always POSIX compliant - "
|
||||
"use gnulib module creat for portability");
|
||||
#elif 1
|
||||
/* On native Windows, map 'creat' to '_creat', so that -loldnames is not
|
||||
required. In C++ with GNULIB_NAMESPACE, avoid differences between
|
||||
platforms by defining GNULIB_NAMESPACE::creat always. */
|
||||
# if defined _WIN32 && !defined __CYGWIN__
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef creat
|
||||
# define creat _creat
|
||||
# endif
|
||||
/* Need to cast, because in mingw the last argument is 'int mode'. */
|
||||
_GL_CXXALIAS_MDA_CAST (creat, int, (const char *filename, mode_t mode));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (creat);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
# if 1
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef fcntl
|
||||
# define fcntl rpl_fcntl
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
|
||||
_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
|
||||
# if !GNULIB_defined_rpl_fcntl
|
||||
# define GNULIB_defined_rpl_fcntl 1
|
||||
# endif
|
||||
# else
|
||||
# if !1
|
||||
_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
|
||||
# if !GNULIB_defined_fcntl
|
||||
# define GNULIB_defined_fcntl 1
|
||||
# endif
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (fcntl);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef fcntl
|
||||
# if HAVE_RAW_DECL_FCNTL
|
||||
_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
|
||||
"use gnulib module fcntl for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
# if 0
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef open
|
||||
# define open rpl_open
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
|
||||
# elif defined _WIN32 && !defined __CYGWIN__
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef open
|
||||
# define open _open
|
||||
# endif
|
||||
_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
|
||||
# endif
|
||||
/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
|
||||
default argument. _GL_CXXALIASWARN does not work in this case. */
|
||||
# if !defined __hpux
|
||||
_GL_CXXALIASWARN (open);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef open
|
||||
/* Assume open is always declared. */
|
||||
_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
|
||||
"use gnulib module open for portability");
|
||||
#elif 1
|
||||
/* On native Windows, map 'open' to '_open', so that -loldnames is not
|
||||
required. In C++ with GNULIB_NAMESPACE, avoid differences between
|
||||
platforms by defining GNULIB_NAMESPACE::open always. */
|
||||
# if defined _WIN32 && !defined __CYGWIN__
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef open
|
||||
# define open _open
|
||||
# endif
|
||||
_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
|
||||
# endif
|
||||
# if !defined __hpux
|
||||
_GL_CXXALIASWARN (open);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
# if 0
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef openat
|
||||
# define openat rpl_openat
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (openat, int,
|
||||
(int fd, char const *file, int flags, /* mode_t mode */ ...)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_RPL (openat, int,
|
||||
(int fd, char const *file, int flags, /* mode_t mode */ ...));
|
||||
# else
|
||||
# if !1
|
||||
_GL_FUNCDECL_SYS (openat, int,
|
||||
(int fd, char const *file, int flags, /* mode_t mode */ ...)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (openat, int,
|
||||
(int fd, char const *file, int flags, /* mode_t mode */ ...));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (openat);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef openat
|
||||
# if HAVE_RAW_DECL_OPENAT
|
||||
_GL_WARN_ON_USE (openat, "openat is not portable - "
|
||||
"use gnulib module openat for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Fix up the FD_* macros, only known to be missing on mingw. */
|
||||
|
||||
#ifndef FD_CLOEXEC
|
||||
# define FD_CLOEXEC 1
|
||||
#endif
|
||||
|
||||
/* Fix up the supported F_* macros. Intentionally leave other F_*
|
||||
macros undefined. Only known to be missing on mingw. */
|
||||
|
||||
#ifndef F_DUPFD_CLOEXEC
|
||||
# define F_DUPFD_CLOEXEC 0x40000000
|
||||
/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
|
||||
# define GNULIB_defined_F_DUPFD_CLOEXEC 1
|
||||
#else
|
||||
# define GNULIB_defined_F_DUPFD_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
#ifndef F_DUPFD
|
||||
# define F_DUPFD 1
|
||||
#endif
|
||||
|
||||
#ifndef F_GETFD
|
||||
# define F_GETFD 2
|
||||
#endif
|
||||
|
||||
/* Fix up the O_* macros. */
|
||||
|
||||
/* AIX 7.1 with XL C 12.1 defines O_CLOEXEC, O_NOFOLLOW, and O_TTY_INIT
|
||||
to values outside 'int' range, so omit these misdefinitions.
|
||||
But avoid namespace pollution on non-AIX systems. */
|
||||
#ifdef _AIX
|
||||
# include <limits.h>
|
||||
# if defined O_CLOEXEC && ! (INT_MIN <= O_CLOEXEC && O_CLOEXEC <= INT_MAX)
|
||||
# undef O_CLOEXEC
|
||||
# endif
|
||||
# if defined O_NOFOLLOW && ! (INT_MIN <= O_NOFOLLOW && O_NOFOLLOW <= INT_MAX)
|
||||
# undef O_NOFOLLOW
|
||||
# endif
|
||||
# if defined O_TTY_INIT && ! (INT_MIN <= O_TTY_INIT && O_TTY_INIT <= INT_MAX)
|
||||
# undef O_TTY_INIT
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined O_DIRECT && defined O_DIRECTIO
|
||||
/* Tru64 spells it 'O_DIRECTIO'. */
|
||||
# define O_DIRECT O_DIRECTIO
|
||||
#endif
|
||||
|
||||
#if !defined O_CLOEXEC && defined O_NOINHERIT
|
||||
/* Mingw spells it 'O_NOINHERIT'. */
|
||||
# define O_CLOEXEC O_NOINHERIT
|
||||
#endif
|
||||
|
||||
#ifndef O_CLOEXEC
|
||||
# define O_CLOEXEC 0x40000000 /* Try to not collide with system O_* flags. */
|
||||
# define GNULIB_defined_O_CLOEXEC 1
|
||||
#else
|
||||
# define GNULIB_defined_O_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
#ifndef O_DIRECT
|
||||
# define O_DIRECT 0
|
||||
#endif
|
||||
|
||||
#ifndef O_DIRECTORY
|
||||
# define O_DIRECTORY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_DSYNC
|
||||
# define O_DSYNC 0
|
||||
#endif
|
||||
|
||||
#ifndef O_EXEC
|
||||
# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
|
||||
#endif
|
||||
|
||||
#ifndef O_IGNORE_CTTY
|
||||
# define O_IGNORE_CTTY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NDELAY
|
||||
# define O_NDELAY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOATIME
|
||||
# define O_NOATIME 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NONBLOCK
|
||||
# define O_NONBLOCK O_NDELAY
|
||||
#endif
|
||||
|
||||
/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
|
||||
value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
|
||||
or to 0 as fallback. */
|
||||
#if 0
|
||||
# if O_NONBLOCK
|
||||
# define GNULIB_defined_O_NONBLOCK 0
|
||||
# else
|
||||
# define GNULIB_defined_O_NONBLOCK 1
|
||||
# undef O_NONBLOCK
|
||||
# define O_NONBLOCK 0x40000000
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef O_NOCTTY
|
||||
# define O_NOCTTY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOFOLLOW
|
||||
# define O_NOFOLLOW 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOLINK
|
||||
# define O_NOLINK 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOLINKS
|
||||
# define O_NOLINKS 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOTRANS
|
||||
# define O_NOTRANS 0
|
||||
#endif
|
||||
|
||||
#ifndef O_RSYNC
|
||||
# define O_RSYNC 0
|
||||
#endif
|
||||
|
||||
#ifndef O_SEARCH
|
||||
# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
|
||||
#endif
|
||||
|
||||
#ifndef O_SYNC
|
||||
# define O_SYNC 0
|
||||
#endif
|
||||
|
||||
#ifndef O_TTY_INIT
|
||||
# define O_TTY_INIT 0
|
||||
#endif
|
||||
|
||||
#if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
|
||||
# undef O_ACCMODE
|
||||
# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
|
||||
#endif
|
||||
|
||||
/* For systems that distinguish between text and binary I/O.
|
||||
O_BINARY is usually declared in fcntl.h */
|
||||
#if !defined O_BINARY && defined _O_BINARY
|
||||
/* For MSC-compatible compilers. */
|
||||
# define O_BINARY _O_BINARY
|
||||
# define O_TEXT _O_TEXT
|
||||
#endif
|
||||
|
||||
#if defined __BEOS__ || defined __HAIKU__
|
||||
/* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
|
||||
# undef O_BINARY
|
||||
# undef O_TEXT
|
||||
#endif
|
||||
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0
|
||||
# define O_TEXT 0
|
||||
#endif
|
||||
|
||||
/* Fix up the AT_* macros. */
|
||||
|
||||
/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
|
||||
value exceeds INT_MAX, so its use as an int doesn't conform to the
|
||||
C standard, and GCC and Sun C complain in some cases. If the bug
|
||||
is present, undef AT_FDCWD here, so it can be redefined below. */
|
||||
#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
|
||||
# undef AT_FDCWD
|
||||
#endif
|
||||
|
||||
/* Use the same bit pattern as Solaris 9, but with the proper
|
||||
signedness. The bit pattern is important, in case this actually is
|
||||
Solaris with the above workaround. */
|
||||
#ifndef AT_FDCWD
|
||||
# define AT_FDCWD (-3041965)
|
||||
#endif
|
||||
|
||||
/* Use the same values as Solaris 9. This shouldn't matter, but
|
||||
there's no real reason to differ. */
|
||||
#ifndef AT_SYMLINK_NOFOLLOW
|
||||
# define AT_SYMLINK_NOFOLLOW 4096
|
||||
#endif
|
||||
|
||||
#ifndef AT_REMOVEDIR
|
||||
# define AT_REMOVEDIR 1
|
||||
#endif
|
||||
|
||||
/* Solaris 9 lacks these two, so just pick unique values. */
|
||||
#ifndef AT_SYMLINK_FOLLOW
|
||||
# define AT_SYMLINK_FOLLOW 2
|
||||
#endif
|
||||
|
||||
#ifndef AT_EACCESS
|
||||
# define AT_EACCESS 4
|
||||
#endif
|
||||
|
||||
/* Ignore this flag if not supported. */
|
||||
#ifndef AT_NO_AUTOMOUNT
|
||||
# define AT_NO_AUTOMOUNT 0
|
||||
#endif
|
||||
|
||||
#endif /* _GL_FCNTL_H */
|
||||
#endif /* _GL_FCNTL_H */
|
||||
#endif
|
||||
@@ -1,119 +0,0 @@
|
||||
/* Hook for making file descriptor functions close(), ioctl() extensible.
|
||||
Copyright (C) 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
#ifndef FD_HOOK_H
|
||||
#define FD_HOOK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Currently, this entire code is only needed for the handling of sockets
|
||||
on native Windows platforms. */
|
||||
#if WINDOWS_SOCKETS
|
||||
|
||||
|
||||
/* Type of function that closes FD. */
|
||||
typedef int (*gl_close_fn) (int fd);
|
||||
|
||||
/* Type of function that applies a control request to FD. */
|
||||
typedef int (*gl_ioctl_fn) (int fd, int request, void *arg);
|
||||
|
||||
/* An element of the list of file descriptor hooks.
|
||||
In CLOS (Common Lisp Object System) speak, it consists of an "around"
|
||||
method for the close() function and an "around" method for the ioctl()
|
||||
function.
|
||||
The fields of this structure are considered private. */
|
||||
struct fd_hook
|
||||
{
|
||||
/* Doubly linked list. */
|
||||
struct fd_hook *private_next;
|
||||
struct fd_hook *private_prev;
|
||||
/* Function that treats the types of FD that it knows about and calls
|
||||
execute_close_hooks (REMAINING_LIST, PRIMARY, FD) as a fallback. */
|
||||
int (*private_close_fn) (const struct fd_hook *remaining_list,
|
||||
gl_close_fn primary,
|
||||
int fd);
|
||||
/* Function that treats the types of FD that it knows about and calls
|
||||
execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG) as a
|
||||
fallback. */
|
||||
int (*private_ioctl_fn) (const struct fd_hook *remaining_list,
|
||||
gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg);
|
||||
};
|
||||
|
||||
/* This type of function closes FD, applying special knowledge for the FD
|
||||
types it knows about, and calls
|
||||
execute_close_hooks (REMAINING_LIST, PRIMARY, FD)
|
||||
for the other FD types.
|
||||
In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
|
||||
and PRIMARY is the "primary" method for close(). */
|
||||
typedef int (*close_hook_fn) (const struct fd_hook *remaining_list,
|
||||
gl_close_fn primary,
|
||||
int fd);
|
||||
|
||||
/* Execute the close hooks in REMAINING_LIST, with PRIMARY as "primary" method.
|
||||
Return 0 or -1, like close() would do. */
|
||||
extern int execute_close_hooks (const struct fd_hook *remaining_list,
|
||||
gl_close_fn primary,
|
||||
int fd);
|
||||
|
||||
/* Execute all close hooks, with PRIMARY as "primary" method.
|
||||
Return 0 or -1, like close() would do. */
|
||||
extern int execute_all_close_hooks (gl_close_fn primary, int fd);
|
||||
|
||||
/* This type of function applies a control request to FD, applying special
|
||||
knowledge for the FD types it knows about, and calls
|
||||
execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG)
|
||||
for the other FD types.
|
||||
In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
|
||||
and PRIMARY is the "primary" method for ioctl(). */
|
||||
typedef int (*ioctl_hook_fn) (const struct fd_hook *remaining_list,
|
||||
gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg);
|
||||
|
||||
/* Execute the ioctl hooks in REMAINING_LIST, with PRIMARY as "primary" method.
|
||||
Return 0 or -1, like ioctl() would do. */
|
||||
extern int execute_ioctl_hooks (const struct fd_hook *remaining_list,
|
||||
gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg);
|
||||
|
||||
/* Execute all ioctl hooks, with PRIMARY as "primary" method.
|
||||
Return 0 or -1, like ioctl() would do. */
|
||||
extern int execute_all_ioctl_hooks (gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg);
|
||||
|
||||
/* Add a function pair to the list of file descriptor hooks.
|
||||
CLOSE_HOOK and IOCTL_HOOK may be NULL, indicating no change.
|
||||
The LINK variable points to a piece of memory which is guaranteed to be
|
||||
accessible until the corresponding call to unregister_fd_hook. */
|
||||
extern void register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook,
|
||||
struct fd_hook *link);
|
||||
|
||||
/* Removes a hook from the list of file descriptor hooks. */
|
||||
extern void unregister_fd_hook (struct fd_hook *link);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FD_HOOK_H */
|
||||
@@ -1,112 +0,0 @@
|
||||
/* Basic filename support macros.
|
||||
Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* From Paul Eggert and Jim Meyering. */
|
||||
|
||||
#ifndef _FILENAME_H
|
||||
#define _FILENAME_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Filename support.
|
||||
ISSLASH(C) tests whether C is a directory separator
|
||||
character.
|
||||
HAS_DEVICE(Filename) tests whether Filename contains a device
|
||||
specification.
|
||||
FILE_SYSTEM_PREFIX_LEN(Filename) length of the device specification
|
||||
at the beginning of Filename,
|
||||
index of the part consisting of
|
||||
alternating components and slashes.
|
||||
FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
|
||||
1 when a non-empty device specification
|
||||
can be followed by an empty or relative
|
||||
part,
|
||||
0 when a non-empty device specification
|
||||
must be followed by a slash,
|
||||
0 when device specification don't exist.
|
||||
IS_ABSOLUTE_FILE_NAME(Filename)
|
||||
tests whether Filename is independent of
|
||||
any notion of "current directory".
|
||||
IS_RELATIVE_FILE_NAME(Filename)
|
||||
tests whether Filename may be concatenated
|
||||
to a directory filename.
|
||||
Note: On native Windows, OS/2, DOS, "c:" is neither an absolute nor a
|
||||
relative file name!
|
||||
IS_FILE_NAME_WITH_DIR(Filename) tests whether Filename contains a device
|
||||
or directory specification.
|
||||
*/
|
||||
#if defined _WIN32 || defined __CYGWIN__ \
|
||||
|| defined __EMX__ || defined __MSDOS__ || defined __DJGPP__
|
||||
/* Native Windows, Cygwin, OS/2, DOS */
|
||||
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
|
||||
/* Internal macro: Tests whether a character is a drive letter. */
|
||||
# define _IS_DRIVE_LETTER(C) \
|
||||
(((C) >= 'A' && (C) <= 'Z') || ((C) >= 'a' && (C) <= 'z'))
|
||||
/* Help the compiler optimizing it. This assumes ASCII. */
|
||||
# undef _IS_DRIVE_LETTER
|
||||
# define _IS_DRIVE_LETTER(C) \
|
||||
(((unsigned int) (C) | ('a' - 'A')) - 'a' <= 'z' - 'a')
|
||||
# define HAS_DEVICE(Filename) \
|
||||
(_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':')
|
||||
# define FILE_SYSTEM_PREFIX_LEN(Filename) (HAS_DEVICE (Filename) ? 2 : 0)
|
||||
# ifdef __CYGWIN__
|
||||
# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
|
||||
# else
|
||||
/* On native Windows, OS/2, DOS, the system has the notion of a
|
||||
"current directory" on each drive. */
|
||||
# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1
|
||||
# endif
|
||||
# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
|
||||
# define IS_ABSOLUTE_FILE_NAME(Filename) \
|
||||
ISSLASH ((Filename)[FILE_SYSTEM_PREFIX_LEN (Filename)])
|
||||
# else
|
||||
# define IS_ABSOLUTE_FILE_NAME(Filename) \
|
||||
(ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename))
|
||||
# endif
|
||||
# define IS_RELATIVE_FILE_NAME(Filename) \
|
||||
(! (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename)))
|
||||
# define IS_FILE_NAME_WITH_DIR(Filename) \
|
||||
(strchr ((Filename), '/') != NULL || strchr ((Filename), '\\') != NULL \
|
||||
|| HAS_DEVICE (Filename))
|
||||
#else
|
||||
/* Unix */
|
||||
# define ISSLASH(C) ((C) == '/')
|
||||
# define HAS_DEVICE(Filename) ((void) (Filename), 0)
|
||||
# define FILE_SYSTEM_PREFIX_LEN(Filename) ((void) (Filename), 0)
|
||||
# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
|
||||
# define IS_ABSOLUTE_FILE_NAME(Filename) ISSLASH ((Filename)[0])
|
||||
# define IS_RELATIVE_FILE_NAME(Filename) (! ISSLASH ((Filename)[0]))
|
||||
# define IS_FILE_NAME_WITH_DIR(Filename) (strchr ((Filename), '/') != NULL)
|
||||
#endif
|
||||
|
||||
/* Deprecated macros. For backward compatibility with old users of the
|
||||
'filename' module. */
|
||||
#define IS_ABSOLUTE_PATH IS_ABSOLUTE_FILE_NAME
|
||||
#define IS_PATH_WITH_DIR IS_FILE_NAME_WITH_DIR
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _FILENAME_H */
|
||||
@@ -1,94 +0,0 @@
|
||||
/* fstat() replacement.
|
||||
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* If the user's config.h happens to include <sys/stat.h>, let it include only
|
||||
the system's <sys/stat.h> here, so that orig_fstat doesn't recurse to
|
||||
rpl_fstat. */
|
||||
#define __need_system_sys_stat_h
|
||||
#include <config.h>
|
||||
|
||||
/* Get the original definition of fstat. It might be defined as a macro. */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#undef __need_system_sys_stat_h
|
||||
|
||||
#if defined _WIN32 && ! defined __CYGWIN__
|
||||
# define WINDOWS_NATIVE
|
||||
#endif
|
||||
|
||||
#if !defined WINDOWS_NATIVE
|
||||
|
||||
static int
|
||||
orig_fstat (int fd, struct stat *buf)
|
||||
{
|
||||
return fstat (fd, buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#ifdef __osf__
|
||||
/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
|
||||
eliminates this include because of the preliminary #include <sys/stat.h>
|
||||
above. */
|
||||
# include "sys/stat.h"
|
||||
#else
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include "stat-time.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#ifdef WINDOWS_NATIVE
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# if GNULIB_MSVC_NOTHROW
|
||||
# include "msvc-nothrow.h"
|
||||
# else
|
||||
# include <io.h>
|
||||
# endif
|
||||
# include "stat-w32.h"
|
||||
#endif
|
||||
|
||||
int
|
||||
rpl_fstat (int fd, struct stat *buf)
|
||||
{
|
||||
#if REPLACE_FCHDIR && REPLACE_OPEN_DIRECTORY
|
||||
/* Handle the case when rpl_open() used a dummy file descriptor to work
|
||||
around an open() that can't normally visit directories. */
|
||||
const char *name = _gl_directory_name (fd);
|
||||
if (name != NULL)
|
||||
return stat (name, buf);
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_NATIVE
|
||||
/* Fill the fields ourselves, because the original fstat function returns
|
||||
values for st_atime, st_mtime, st_ctime that depend on the current time
|
||||
zone. See
|
||||
<https://lists.gnu.org/r/bug-gnulib/2017-04/msg00134.html> */
|
||||
HANDLE h = (HANDLE) _get_osfhandle (fd);
|
||||
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
return _gl_fstat_by_handle (h, NULL, buf);
|
||||
#else
|
||||
return stat_time_normalize (orig_fstat (fd, buf), buf);
|
||||
#endif
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/* Program name management.
|
||||
Copyright (C) 2016-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GL_GETPROGNAME_H
|
||||
#define _GL_GETPROGNAME_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Return the base name of the executing program.
|
||||
On native Windows this will usually end in ".exe" or ".EXE". */
|
||||
#ifndef HAVE_GETPROGNAME
|
||||
extern char const *getprogname (void)
|
||||
# ifdef HAVE_DECL_PROGRAM_INVOCATION_NAME
|
||||
_GL_ATTRIBUTE_PURE
|
||||
# endif
|
||||
;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,300 +0,0 @@
|
||||
/* Convenience header for conditional use of GNU <libintl.h>.
|
||||
Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2022 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _LIBGETTEXT_H
|
||||
#define _LIBGETTEXT_H 1
|
||||
|
||||
/* NLS can be disabled through the configure --disable-nls option
|
||||
or through "#define ENABLE NLS 0" before including this file. */
|
||||
#if defined ENABLE_NLS && ENABLE_NLS
|
||||
|
||||
/* Get declarations of GNU message catalog functions. */
|
||||
# include <libintl.h>
|
||||
|
||||
/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
|
||||
the gettext() and ngettext() macros. This is an alternative to calling
|
||||
textdomain(), and is useful for libraries. */
|
||||
# ifdef DEFAULT_TEXT_DOMAIN
|
||||
# undef gettext
|
||||
# define gettext(Msgid) \
|
||||
dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
|
||||
# undef ngettext
|
||||
# define ngettext(Msgid1, Msgid2, N) \
|
||||
dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
|
||||
chokes if dcgettext is defined as a macro. So include it now, to make
|
||||
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
|
||||
as well because people using "gettext.h" will not include <libintl.h>,
|
||||
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
|
||||
is OK. */
|
||||
#if defined(__sun)
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
|
||||
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
|
||||
it now, to make later inclusions of <libintl.h> a NOP. */
|
||||
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
|
||||
# include <cstdlib>
|
||||
# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H
|
||||
# include <libintl.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Disabled NLS.
|
||||
The casts to 'const char *' serve the purpose of producing warnings
|
||||
for invalid uses of the value returned from these functions.
|
||||
On pre-ANSI systems without 'const', the config.h file is supposed to
|
||||
contain "#define const". */
|
||||
# undef gettext
|
||||
# define gettext(Msgid) ((const char *) (Msgid))
|
||||
# undef dgettext
|
||||
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
|
||||
# undef dcgettext
|
||||
# define dcgettext(Domainname, Msgid, Category) \
|
||||
((void) (Category), dgettext (Domainname, Msgid))
|
||||
# undef ngettext
|
||||
# define ngettext(Msgid1, Msgid2, N) \
|
||||
((N) == 1 \
|
||||
? ((void) (Msgid2), (const char *) (Msgid1)) \
|
||||
: ((void) (Msgid1), (const char *) (Msgid2)))
|
||||
# undef dngettext
|
||||
# define dngettext(Domainname, Msgid1, Msgid2, N) \
|
||||
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
|
||||
# undef dcngettext
|
||||
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
|
||||
((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
|
||||
# undef textdomain
|
||||
# define textdomain(Domainname) ((const char *) (Domainname))
|
||||
# undef bindtextdomain
|
||||
# define bindtextdomain(Domainname, Dirname) \
|
||||
((void) (Domainname), (const char *) (Dirname))
|
||||
# undef bind_textdomain_codeset
|
||||
# define bind_textdomain_codeset(Domainname, Codeset) \
|
||||
((void) (Domainname), (const char *) (Codeset))
|
||||
|
||||
#endif
|
||||
|
||||
/* Prefer gnulib's setlocale override over libintl's setlocale override. */
|
||||
#ifdef GNULIB_defined_setlocale
|
||||
# undef setlocale
|
||||
# define setlocale rpl_setlocale
|
||||
#endif
|
||||
|
||||
/* A pseudo function call that serves as a marker for the automated
|
||||
extraction of messages, but does not call gettext(). The run-time
|
||||
translation is done at a different place in the code.
|
||||
The argument, String, should be a literal string. Concatenated strings
|
||||
and other string expressions won't work.
|
||||
The macro's expansion is not parenthesized, so that it is suitable as
|
||||
initializer for static 'char[]' or 'const char[]' variables. */
|
||||
#define gettext_noop(String) String
|
||||
|
||||
/* The separator between msgctxt and msgid in a .mo file. */
|
||||
#define GETTEXT_CONTEXT_GLUE "\004"
|
||||
|
||||
/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
|
||||
MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
|
||||
short and rarely need to change.
|
||||
The letter 'p' stands for 'particular' or 'special'. */
|
||||
#ifdef DEFAULT_TEXT_DOMAIN
|
||||
# define pgettext(Msgctxt, Msgid) \
|
||||
pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
|
||||
#else
|
||||
# define pgettext(Msgctxt, Msgid) \
|
||||
pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
|
||||
#endif
|
||||
#define dpgettext(Domainname, Msgctxt, Msgid) \
|
||||
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
|
||||
#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
|
||||
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
|
||||
#ifdef DEFAULT_TEXT_DOMAIN
|
||||
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
|
||||
npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
|
||||
#else
|
||||
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
|
||||
npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
|
||||
#endif
|
||||
#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
|
||||
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
|
||||
#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
|
||||
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
|
||||
|
||||
#if defined __GNUC__ || defined __clang__
|
||||
__inline
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
inline
|
||||
#endif
|
||||
#endif
|
||||
static const char *
|
||||
pgettext_aux (const char *domain,
|
||||
const char *msg_ctxt_id, const char *msgid,
|
||||
int category)
|
||||
{
|
||||
const char *translation = dcgettext (domain, msg_ctxt_id, category);
|
||||
if (translation == msg_ctxt_id)
|
||||
return msgid;
|
||||
else
|
||||
return translation;
|
||||
}
|
||||
|
||||
#if defined __GNUC__ || defined __clang__
|
||||
__inline
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
inline
|
||||
#endif
|
||||
#endif
|
||||
static const char *
|
||||
npgettext_aux (const char *domain,
|
||||
const char *msg_ctxt_id, const char *msgid,
|
||||
const char *msgid_plural, unsigned long int n,
|
||||
int category)
|
||||
{
|
||||
const char *translation =
|
||||
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
|
||||
if (translation == msg_ctxt_id || translation == msgid_plural)
|
||||
return (n == 1 ? msgid : msgid_plural);
|
||||
else
|
||||
return translation;
|
||||
}
|
||||
|
||||
/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
|
||||
can be arbitrary expressions. But for string literals these macros are
|
||||
less efficient than those above. */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* GNULIB_NO_VLA can be defined to disable use of VLAs even if supported.
|
||||
This relates to the -Wvla and -Wvla-larger-than warnings, enabled in
|
||||
the default GCC many warnings set. This allows programs to disable use
|
||||
of VLAs, which may be unintended, or may be awkward to support portably,
|
||||
or may have security implications due to non-deterministic stack usage. */
|
||||
|
||||
#if (!defined GNULIB_NO_VLA \
|
||||
&& defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
|
||||
&& !defined __STDC_NO_VLA__)
|
||||
# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
|
||||
#else
|
||||
# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
|
||||
#endif
|
||||
|
||||
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#define pgettext_expr(Msgctxt, Msgid) \
|
||||
dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
|
||||
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
|
||||
dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
|
||||
|
||||
#if defined __GNUC__ || defined __clang__
|
||||
__inline
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
inline
|
||||
#endif
|
||||
#endif
|
||||
static const char *
|
||||
dcpgettext_expr (const char *domain,
|
||||
const char *msgctxt, const char *msgid,
|
||||
int category)
|
||||
{
|
||||
size_t msgctxt_len = strlen (msgctxt) + 1;
|
||||
size_t msgid_len = strlen (msgid) + 1;
|
||||
const char *translation;
|
||||
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
char msg_ctxt_id[msgctxt_len + msgid_len];
|
||||
#else
|
||||
char buf[1024];
|
||||
char *msg_ctxt_id =
|
||||
(msgctxt_len + msgid_len <= sizeof (buf)
|
||||
? buf
|
||||
: (char *) malloc (msgctxt_len + msgid_len));
|
||||
if (msg_ctxt_id != NULL)
|
||||
#endif
|
||||
{
|
||||
int found_translation;
|
||||
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
|
||||
msg_ctxt_id[msgctxt_len - 1] = '\004';
|
||||
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
|
||||
translation = dcgettext (domain, msg_ctxt_id, category);
|
||||
found_translation = (translation != msg_ctxt_id);
|
||||
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
if (msg_ctxt_id != buf)
|
||||
free (msg_ctxt_id);
|
||||
#endif
|
||||
if (found_translation)
|
||||
return translation;
|
||||
}
|
||||
return msgid;
|
||||
}
|
||||
|
||||
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
|
||||
dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
|
||||
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
|
||||
dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
|
||||
|
||||
#if defined __GNUC__ || defined __clang__
|
||||
__inline
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
inline
|
||||
#endif
|
||||
#endif
|
||||
static const char *
|
||||
dcnpgettext_expr (const char *domain,
|
||||
const char *msgctxt, const char *msgid,
|
||||
const char *msgid_plural, unsigned long int n,
|
||||
int category)
|
||||
{
|
||||
size_t msgctxt_len = strlen (msgctxt) + 1;
|
||||
size_t msgid_len = strlen (msgid) + 1;
|
||||
const char *translation;
|
||||
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
char msg_ctxt_id[msgctxt_len + msgid_len];
|
||||
#else
|
||||
char buf[1024];
|
||||
char *msg_ctxt_id =
|
||||
(msgctxt_len + msgid_len <= sizeof (buf)
|
||||
? buf
|
||||
: (char *) malloc (msgctxt_len + msgid_len));
|
||||
if (msg_ctxt_id != NULL)
|
||||
#endif
|
||||
{
|
||||
int found_translation;
|
||||
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
|
||||
msg_ctxt_id[msgctxt_len - 1] = '\004';
|
||||
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
|
||||
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
|
||||
found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
|
||||
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
if (msg_ctxt_id != buf)
|
||||
free (msg_ctxt_id);
|
||||
#endif
|
||||
if (found_translation)
|
||||
return translation;
|
||||
}
|
||||
return (n == 1 ? msgid : msgid_plural);
|
||||
}
|
||||
|
||||
#endif /* _LIBGETTEXT_H */
|
||||
@@ -1,134 +0,0 @@
|
||||
/* A type for indices and sizes.
|
||||
Copyright (C) 2020-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _IDX_H
|
||||
#define _IDX_H
|
||||
|
||||
/* Get ptrdiff_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Get PTRDIFF_MAX. */
|
||||
#include <stdint.h>
|
||||
|
||||
/* The type 'idx_t' holds an (array) index or an (object) size.
|
||||
Its implementation promotes to a signed integer type,
|
||||
which can hold the values
|
||||
0..2^63-1 (on 64-bit platforms) or
|
||||
0..2^31-1 (on 32-bit platforms).
|
||||
|
||||
Why a signed integer type?
|
||||
|
||||
* Security: Signed types can be checked for overflow via
|
||||
'-fsanitize=undefined', but unsigned types cannot.
|
||||
|
||||
* Comparisons without surprises: ISO C99 § 6.3.1.8 specifies a few
|
||||
surprising results for comparisons, such as
|
||||
|
||||
(int) -3 < (unsigned long) 7 => false
|
||||
(int) -3 < (unsigned int) 7 => false
|
||||
and on 32-bit machines:
|
||||
(long) -3 < (unsigned int) 7 => false
|
||||
|
||||
This is surprising because the natural comparison order is by
|
||||
value in the realm of infinite-precision signed integers (ℤ).
|
||||
|
||||
The best way to get rid of such surprises is to use signed types
|
||||
for numerical integer values, and use unsigned types only for
|
||||
bit masks and enums.
|
||||
|
||||
Why not use 'size_t' directly?
|
||||
|
||||
* Because 'size_t' is an unsigned type, and a signed type is better.
|
||||
See above.
|
||||
|
||||
Why not use 'ssize_t'?
|
||||
|
||||
* 'ptrdiff_t' is more portable; it is standardized by ISO C
|
||||
whereas 'ssize_t' is standardized only by POSIX.
|
||||
|
||||
* 'ssize_t' is not required to be as wide as 'size_t', and some
|
||||
now-obsolete POSIX platforms had 'size_t' wider than 'ssize_t'.
|
||||
|
||||
* Conversely, some now-obsolete platforms had 'ptrdiff_t' wider
|
||||
than 'size_t', which can be a win and conforms to POSIX.
|
||||
|
||||
Won't this cause a problem with objects larger than PTRDIFF_MAX?
|
||||
|
||||
* Typical modern or large platforms do not allocate such objects,
|
||||
so this is not much of a problem in practice; for example, you
|
||||
can safely write 'idx_t len = strlen (s);'. To port to older
|
||||
small platforms where allocations larger than PTRDIFF_MAX could
|
||||
in theory be a problem, you can use Gnulib's ialloc module, or
|
||||
functions like ximalloc in Gnulib's xalloc module.
|
||||
|
||||
Why not use 'ptrdiff_t' directly?
|
||||
|
||||
* Maintainability: When reading and modifying code, it helps to know that
|
||||
a certain variable cannot have negative values. For example, when you
|
||||
have a loop
|
||||
|
||||
int n = ...;
|
||||
for (int i = 0; i < n; i++) ...
|
||||
|
||||
or
|
||||
|
||||
ptrdiff_t n = ...;
|
||||
for (ptrdiff_t i = 0; i < n; i++) ...
|
||||
|
||||
you have to ask yourself "what if n < 0?". Whereas in
|
||||
|
||||
idx_t n = ...;
|
||||
for (idx_t i = 0; i < n; i++) ...
|
||||
|
||||
you know that this case cannot happen.
|
||||
|
||||
Similarly, when a programmer writes
|
||||
|
||||
idx_t = ptr2 - ptr1;
|
||||
|
||||
there is an implied assertion that ptr1 and ptr2 point into the same
|
||||
object and that ptr1 <= ptr2.
|
||||
|
||||
* Being future-proof: In the future, range types (integers which are
|
||||
constrained to a certain range of values) may be added to C compilers
|
||||
or to the C standard. Several programming languages (Ada, Haskell,
|
||||
Common Lisp, Pascal) already have range types. Such range types may
|
||||
help producing good code and good warnings. The type 'idx_t' could
|
||||
then be typedef'ed to a range type that is signed after promotion. */
|
||||
|
||||
/* In the future, idx_t could be typedef'ed to a signed range type.
|
||||
The clang "extended integer types", supported in Clang 11 or newer
|
||||
<https://clang.llvm.org/docs/LanguageExtensions.html#extended-integer-types>,
|
||||
are a special case of range types. However, these types don't support binary
|
||||
operators with plain integer types (e.g. expressions such as x > 1).
|
||||
Therefore, they don't behave like signed types (and not like unsigned types
|
||||
either). So, we cannot use them here. */
|
||||
|
||||
/* Use the signed type 'ptrdiff_t'. */
|
||||
/* Note: ISO C does not mandate that 'size_t' and 'ptrdiff_t' have the same
|
||||
size, but it is so on all platforms we have seen since 1990. */
|
||||
typedef ptrdiff_t idx_t;
|
||||
|
||||
/* IDX_MAX is the maximum value of an idx_t. */
|
||||
#define IDX_MAX PTRDIFF_MAX
|
||||
|
||||
/* So far no need has been found for an IDX_WIDTH macro.
|
||||
Perhaps there should be another macro IDX_VALUE_BITS that does not
|
||||
count the sign bit and is therefore one less than PTRDIFF_WIDTH. */
|
||||
|
||||
#endif /* _IDX_H */
|
||||
@@ -1,642 +0,0 @@
|
||||
/* intprops.h -- properties of integer types
|
||||
|
||||
Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
#ifndef _GL_INTPROPS_H
|
||||
#define _GL_INTPROPS_H
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
/* Return a value with the common real type of E and V and the value of V.
|
||||
Do not evaluate E. */
|
||||
#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
|
||||
|
||||
/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see
|
||||
<https://lists.gnu.org/r/bug-gnulib/2011-05/msg00406.html>. */
|
||||
#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v))
|
||||
|
||||
/* The extra casts in the following macros work around compiler bugs,
|
||||
e.g., in Cray C 5.0.3.0. */
|
||||
|
||||
/* True if the arithmetic type T is an integer type. bool counts as
|
||||
an integer. */
|
||||
#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
|
||||
|
||||
/* True if the real type T is signed. */
|
||||
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
|
||||
|
||||
/* Return 1 if the real expression E, after promotion, has a
|
||||
signed or floating type. Do not evaluate E. */
|
||||
#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
|
||||
|
||||
|
||||
/* Minimum and maximum values for integer types and expressions. */
|
||||
|
||||
/* The width in bits of the integer type or expression T.
|
||||
Do not evaluate T. T must not be a bit-field expression.
|
||||
Padding bits are not supported; this is checked at compile-time below. */
|
||||
#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
|
||||
|
||||
/* The maximum and minimum values for the integer type T. */
|
||||
#define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t))
|
||||
#define TYPE_MAXIMUM(t) \
|
||||
((t) (! TYPE_SIGNED (t) \
|
||||
? (t) -1 \
|
||||
: ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1)))
|
||||
|
||||
/* The maximum and minimum values for the type of the expression E,
|
||||
after integer promotion. E is not evaluated. */
|
||||
#define _GL_INT_MINIMUM(e) \
|
||||
(EXPR_SIGNED (e) \
|
||||
? ~ _GL_SIGNED_INT_MAXIMUM (e) \
|
||||
: _GL_INT_CONVERT (e, 0))
|
||||
#define _GL_INT_MAXIMUM(e) \
|
||||
(EXPR_SIGNED (e) \
|
||||
? _GL_SIGNED_INT_MAXIMUM (e) \
|
||||
: _GL_INT_NEGATE_CONVERT (e, 1))
|
||||
#define _GL_SIGNED_INT_MAXIMUM(e) \
|
||||
(((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
|
||||
|
||||
/* Work around OpenVMS incompatibility with C99. */
|
||||
#if !defined LLONG_MAX && defined __INT64_MAX
|
||||
# define LLONG_MAX __INT64_MAX
|
||||
# define LLONG_MIN __INT64_MIN
|
||||
#endif
|
||||
|
||||
/* This include file assumes that signed types are two's complement without
|
||||
padding bits; the above macros have undefined behavior otherwise.
|
||||
If this is a problem for you, please let us know how to fix it for your host.
|
||||
This assumption is tested by the intprops-tests module. */
|
||||
|
||||
/* Does the __typeof__ keyword work? This could be done by
|
||||
'configure', but for now it's easier to do it by hand. */
|
||||
#if (2 <= __GNUC__ \
|
||||
|| (4 <= __clang_major__) \
|
||||
|| (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \
|
||||
|| (0x5110 <= __SUNPRO_C && !__STDC__))
|
||||
# define _GL_HAVE___TYPEOF__ 1
|
||||
#else
|
||||
# define _GL_HAVE___TYPEOF__ 0
|
||||
#endif
|
||||
|
||||
/* Return 1 if the integer type or expression T might be signed. Return 0
|
||||
if it is definitely unsigned. T must not be a bit-field expression.
|
||||
This macro does not evaluate its argument, and expands to an
|
||||
integer constant expression. */
|
||||
#if _GL_HAVE___TYPEOF__
|
||||
# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t))
|
||||
#else
|
||||
# define _GL_SIGNED_TYPE_OR_EXPR(t) 1
|
||||
#endif
|
||||
|
||||
/* Bound on length of the string representing an unsigned integer
|
||||
value representable in B bits. log10 (2.0) < 146/485. The
|
||||
smallest value of B where this bound is not tight is 2621. */
|
||||
#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
|
||||
|
||||
/* Bound on length of the string representing an integer type or expression T.
|
||||
T must not be a bit-field expression.
|
||||
|
||||
Subtract 1 for the sign bit if T is signed, and then add 1 more for
|
||||
a minus sign if needed.
|
||||
|
||||
Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 1 when its argument is
|
||||
unsigned, this macro may overestimate the true bound by one byte when
|
||||
applied to unsigned types of size 2, 4, 16, ... bytes. */
|
||||
#define INT_STRLEN_BOUND(t) \
|
||||
(INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - _GL_SIGNED_TYPE_OR_EXPR (t)) \
|
||||
+ _GL_SIGNED_TYPE_OR_EXPR (t))
|
||||
|
||||
/* Bound on buffer size needed to represent an integer type or expression T,
|
||||
including the terminating null. T must not be a bit-field expression. */
|
||||
#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
|
||||
|
||||
|
||||
/* Range overflow checks.
|
||||
|
||||
The INT_<op>_RANGE_OVERFLOW macros return 1 if the corresponding C
|
||||
operators might not yield numerically correct answers due to
|
||||
arithmetic overflow. They do not rely on undefined or
|
||||
implementation-defined behavior. Their implementations are simple
|
||||
and straightforward, but they are harder to use and may be less
|
||||
efficient than the INT_<op>_WRAPV, INT_<op>_OK, and
|
||||
INT_<op>_OVERFLOW macros described below.
|
||||
|
||||
Example usage:
|
||||
|
||||
long int i = ...;
|
||||
long int j = ...;
|
||||
if (INT_MULTIPLY_RANGE_OVERFLOW (i, j, LONG_MIN, LONG_MAX))
|
||||
printf ("multiply would overflow");
|
||||
else
|
||||
printf ("product is %ld", i * j);
|
||||
|
||||
Restrictions on *_RANGE_OVERFLOW macros:
|
||||
|
||||
These macros do not check for all possible numerical problems or
|
||||
undefined or unspecified behavior: they do not check for division
|
||||
by zero, for bad shift counts, or for shifting negative numbers.
|
||||
|
||||
These macros may evaluate their arguments zero or multiple times,
|
||||
so the arguments should not have side effects. The arithmetic
|
||||
arguments (including the MIN and MAX arguments) must be of the same
|
||||
integer type after the usual arithmetic conversions, and the type
|
||||
must have minimum value MIN and maximum MAX. Unsigned types should
|
||||
use a zero MIN of the proper type.
|
||||
|
||||
Because all arguments are subject to integer promotions, these
|
||||
macros typically do not work on types narrower than 'int'.
|
||||
|
||||
These macros are tuned for constant MIN and MAX. For commutative
|
||||
operations such as A + B, they are also tuned for constant B. */
|
||||
|
||||
/* Return 1 if A + B would overflow in [MIN,MAX] arithmetic.
|
||||
See above for restrictions. */
|
||||
#define INT_ADD_RANGE_OVERFLOW(a, b, min, max) \
|
||||
((b) < 0 \
|
||||
? (a) < (min) - (b) \
|
||||
: (max) - (b) < (a))
|
||||
|
||||
/* Return 1 if A - B would overflow in [MIN,MAX] arithmetic.
|
||||
See above for restrictions. */
|
||||
#define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max) \
|
||||
((b) < 0 \
|
||||
? (max) + (b) < (a) \
|
||||
: (a) < (min) + (b))
|
||||
|
||||
/* Return 1 if - A would overflow in [MIN,MAX] arithmetic.
|
||||
See above for restrictions. */
|
||||
#define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \
|
||||
((min) < 0 \
|
||||
? (a) < - (max) \
|
||||
: 0 < (a))
|
||||
|
||||
/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic.
|
||||
See above for restrictions. Avoid && and || as they tickle
|
||||
bugs in Sun C 5.11 2010/08/13 and other compilers; see
|
||||
<https://lists.gnu.org/r/bug-gnulib/2011-05/msg00401.html>. */
|
||||
#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \
|
||||
((b) < 0 \
|
||||
? ((a) < 0 \
|
||||
? (a) < (max) / (b) \
|
||||
: (b) == -1 \
|
||||
? 0 \
|
||||
: (min) / (b) < (a)) \
|
||||
: (b) == 0 \
|
||||
? 0 \
|
||||
: ((a) < 0 \
|
||||
? (a) < (min) / (b) \
|
||||
: (max) / (b) < (a)))
|
||||
|
||||
/* Return 1 if A / B would overflow in [MIN,MAX] arithmetic.
|
||||
See above for restrictions. Do not check for division by zero. */
|
||||
#define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max) \
|
||||
((min) < 0 && (b) == -1 && (a) < - (max))
|
||||
|
||||
/* Return 1 if A % B would overflow in [MIN,MAX] arithmetic.
|
||||
See above for restrictions. Do not check for division by zero.
|
||||
Mathematically, % should never overflow, but on x86-like hosts
|
||||
INT_MIN % -1 traps, and the C standard permits this, so treat this
|
||||
as an overflow too. */
|
||||
#define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max) \
|
||||
INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max)
|
||||
|
||||
/* Return 1 if A << B would overflow in [MIN,MAX] arithmetic.
|
||||
See above for restrictions. Here, MIN and MAX are for A only, and B need
|
||||
not be of the same type as the other arguments. The C standard says that
|
||||
behavior is undefined for shifts unless 0 <= B < wordwidth, and that when
|
||||
A is negative then A << B has undefined behavior and A >> B has
|
||||
implementation-defined behavior, but do not check these other
|
||||
restrictions. */
|
||||
#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \
|
||||
((a) < 0 \
|
||||
? (a) < (min) >> (b) \
|
||||
: (max) >> (b) < (a))
|
||||
|
||||
/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow
|
||||
(A, B, P) work when P is non-null. */
|
||||
#ifdef __EDG__
|
||||
/* EDG-based compilers like nvc 22.1 cannot add 64-bit signed to unsigned
|
||||
<https://bugs.gnu.org/53256>. */
|
||||
# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0
|
||||
#elif defined __has_builtin
|
||||
# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow)
|
||||
/* __builtin_{add,sub}_overflow exists but is not reliable in GCC 5.x and 6.x,
|
||||
see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269>. */
|
||||
#elif 7 <= __GNUC__
|
||||
# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1
|
||||
#else
|
||||
# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0
|
||||
#endif
|
||||
|
||||
/* True if __builtin_mul_overflow (A, B, P) works when P is non-null. */
|
||||
#if defined __clang_major__ && __clang_major__ < 14
|
||||
/* Work around Clang bug <https://bugs.llvm.org/show_bug.cgi?id=16404>. */
|
||||
# define _GL_HAS_BUILTIN_MUL_OVERFLOW 0
|
||||
#else
|
||||
# define _GL_HAS_BUILTIN_MUL_OVERFLOW _GL_HAS_BUILTIN_ADD_OVERFLOW
|
||||
#endif
|
||||
|
||||
/* True if __builtin_add_overflow_p (A, B, C) works, and similarly for
|
||||
__builtin_sub_overflow_p and __builtin_mul_overflow_p. */
|
||||
#ifdef __EDG__
|
||||
/* In EDG-based compilers like ICC 2021.3 and earlier,
|
||||
__builtin_add_overflow_p etc. are not treated as integral constant
|
||||
expressions even when all arguments are. */
|
||||
# define _GL_HAS_BUILTIN_OVERFLOW_P 0
|
||||
#elif defined __has_builtin
|
||||
# define _GL_HAS_BUILTIN_OVERFLOW_P __has_builtin (__builtin_mul_overflow_p)
|
||||
#else
|
||||
# define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
|
||||
#endif
|
||||
|
||||
/* The _GL*_OVERFLOW macros have the same restrictions as the
|
||||
*_RANGE_OVERFLOW macros, except that they do not assume that operands
|
||||
(e.g., A and B) have the same type as MIN and MAX. Instead, they assume
|
||||
that the result (e.g., A + B) has that type. */
|
||||
#if _GL_HAS_BUILTIN_OVERFLOW_P
|
||||
# define _GL_ADD_OVERFLOW(a, b, min, max) \
|
||||
__builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0)
|
||||
# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
|
||||
__builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0)
|
||||
# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
|
||||
__builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0)
|
||||
#else
|
||||
# define _GL_ADD_OVERFLOW(a, b, min, max) \
|
||||
((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \
|
||||
: (a) < 0 ? (b) <= (a) + (b) \
|
||||
: (b) < 0 ? (a) <= (a) + (b) \
|
||||
: (a) + (b) < (b))
|
||||
# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
|
||||
((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \
|
||||
: (a) < 0 ? 1 \
|
||||
: (b) < 0 ? (a) - (b) <= (a) \
|
||||
: (a) < (b))
|
||||
# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
|
||||
(((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
|
||||
|| INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))
|
||||
#endif
|
||||
#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \
|
||||
((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
|
||||
: (a) < 0 ? (b) <= (a) + (b) - 1 \
|
||||
: (b) < 0 && (a) + (b) <= (a))
|
||||
#define _GL_REMAINDER_OVERFLOW(a, b, min, max) \
|
||||
((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
|
||||
: (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \
|
||||
: (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max))
|
||||
|
||||
/* Return a nonzero value if A is a mathematical multiple of B, where
|
||||
A is unsigned, B is negative, and MAX is the maximum value of A's
|
||||
type. A's type must be the same as (A % B)'s type. Normally (A %
|
||||
-B == 0) suffices, but things get tricky if -B would overflow. */
|
||||
#define _GL_UNSIGNED_NEG_MULTIPLE(a, b, max) \
|
||||
(((b) < -_GL_SIGNED_INT_MAXIMUM (b) \
|
||||
? (_GL_SIGNED_INT_MAXIMUM (b) == (max) \
|
||||
? (a) \
|
||||
: (a) % (_GL_INT_CONVERT (a, _GL_SIGNED_INT_MAXIMUM (b)) + 1)) \
|
||||
: (a) % - (b)) \
|
||||
== 0)
|
||||
|
||||
/* Check for integer overflow, and report low order bits of answer.
|
||||
|
||||
The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators
|
||||
might not yield numerically correct answers due to arithmetic overflow.
|
||||
The INT_<op>_WRAPV macros compute the low-order bits of the sum,
|
||||
difference, and product of two C integers, and return 1 if these
|
||||
low-order bits are not numerically correct.
|
||||
These macros work correctly on all known practical hosts, and do not rely
|
||||
on undefined behavior due to signed arithmetic overflow.
|
||||
|
||||
Example usage, assuming A and B are long int:
|
||||
|
||||
if (INT_MULTIPLY_OVERFLOW (a, b))
|
||||
printf ("result would overflow\n");
|
||||
else
|
||||
printf ("result is %ld (no overflow)\n", a * b);
|
||||
|
||||
Example usage with WRAPV flavor:
|
||||
|
||||
long int result;
|
||||
bool overflow = INT_MULTIPLY_WRAPV (a, b, &result);
|
||||
printf ("result is %ld (%s)\n", result,
|
||||
overflow ? "after overflow" : "no overflow");
|
||||
|
||||
Restrictions on these macros:
|
||||
|
||||
These macros do not check for all possible numerical problems or
|
||||
undefined or unspecified behavior: they do not check for division
|
||||
by zero, for bad shift counts, or for shifting negative numbers.
|
||||
|
||||
These macros may evaluate their arguments zero or multiple times, so the
|
||||
arguments should not have side effects.
|
||||
|
||||
The WRAPV macros are not constant expressions. They support only
|
||||
+, binary -, and *.
|
||||
|
||||
Because the WRAPV macros convert the result, they report overflow
|
||||
in different circumstances than the OVERFLOW macros do. For
|
||||
example, in the typical case with 16-bit 'short' and 32-bit 'int',
|
||||
if A, B and R are all of type 'short' then INT_ADD_OVERFLOW (A, B)
|
||||
returns false because the addition cannot overflow after A and B
|
||||
are converted to 'int', whereas INT_ADD_WRAPV (A, B, &R) returns
|
||||
true or false depending on whether the sum fits into 'short'.
|
||||
|
||||
These macros are tuned for their last input argument being a constant.
|
||||
|
||||
Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B,
|
||||
A % B, and A << B would overflow, respectively. */
|
||||
|
||||
#define INT_ADD_OVERFLOW(a, b) \
|
||||
_GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
|
||||
#define INT_SUBTRACT_OVERFLOW(a, b) \
|
||||
_GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
|
||||
#if _GL_HAS_BUILTIN_OVERFLOW_P
|
||||
# define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a)
|
||||
#else
|
||||
# define INT_NEGATE_OVERFLOW(a) \
|
||||
INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
|
||||
#endif
|
||||
#define INT_MULTIPLY_OVERFLOW(a, b) \
|
||||
_GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
|
||||
#define INT_DIVIDE_OVERFLOW(a, b) \
|
||||
_GL_BINARY_OP_OVERFLOW (a, b, _GL_DIVIDE_OVERFLOW)
|
||||
#define INT_REMAINDER_OVERFLOW(a, b) \
|
||||
_GL_BINARY_OP_OVERFLOW (a, b, _GL_REMAINDER_OVERFLOW)
|
||||
#define INT_LEFT_SHIFT_OVERFLOW(a, b) \
|
||||
INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \
|
||||
_GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
|
||||
|
||||
/* Return 1 if the expression A <op> B would overflow,
|
||||
where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test,
|
||||
assuming MIN and MAX are the minimum and maximum for the result type.
|
||||
Arguments should be free of side effects. */
|
||||
#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \
|
||||
op_result_overflow (a, b, \
|
||||
_GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \
|
||||
_GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b)))
|
||||
|
||||
/* Store the low-order bits of A + B, A - B, A * B, respectively, into *R.
|
||||
Return 1 if the result overflows. See above for restrictions. */
|
||||
#if _GL_HAS_BUILTIN_ADD_OVERFLOW
|
||||
# define INT_ADD_WRAPV(a, b, r) __builtin_add_overflow (a, b, r)
|
||||
# define INT_SUBTRACT_WRAPV(a, b, r) __builtin_sub_overflow (a, b, r)
|
||||
#else
|
||||
# define INT_ADD_WRAPV(a, b, r) \
|
||||
_GL_INT_OP_WRAPV (a, b, r, +, _GL_INT_ADD_RANGE_OVERFLOW)
|
||||
# define INT_SUBTRACT_WRAPV(a, b, r) \
|
||||
_GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
|
||||
#endif
|
||||
#if _GL_HAS_BUILTIN_MUL_OVERFLOW
|
||||
# if ((9 < __GNUC__ + (3 <= __GNUC_MINOR__) \
|
||||
|| (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) \
|
||||
&& !defined __EDG__)
|
||||
# define INT_MULTIPLY_WRAPV(a, b, r) __builtin_mul_overflow (a, b, r)
|
||||
# else
|
||||
/* Work around GCC bug 91450. */
|
||||
# define INT_MULTIPLY_WRAPV(a, b, r) \
|
||||
((!_GL_SIGNED_TYPE_OR_EXPR (*(r)) && EXPR_SIGNED (a) && EXPR_SIGNED (b) \
|
||||
&& _GL_INT_MULTIPLY_RANGE_OVERFLOW (a, b, 0, (__typeof__ (*(r))) -1)) \
|
||||
? ((void) __builtin_mul_overflow (a, b, r), 1) \
|
||||
: __builtin_mul_overflow (a, b, r))
|
||||
# endif
|
||||
#else
|
||||
# define INT_MULTIPLY_WRAPV(a, b, r) \
|
||||
_GL_INT_OP_WRAPV (a, b, r, *, _GL_INT_MULTIPLY_RANGE_OVERFLOW)
|
||||
#endif
|
||||
|
||||
/* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See:
|
||||
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193
|
||||
https://llvm.org/bugs/show_bug.cgi?id=25390
|
||||
For now, assume all versions of GCC-like compilers generate bogus
|
||||
warnings for _Generic. This matters only for compilers that
|
||||
lack relevant builtins. */
|
||||
#if __GNUC__ || defined __clang__
|
||||
# define _GL__GENERIC_BOGUS 1
|
||||
#else
|
||||
# define _GL__GENERIC_BOGUS 0
|
||||
#endif
|
||||
|
||||
/* Store the low-order bits of A <op> B into *R, where OP specifies
|
||||
the operation and OVERFLOW the overflow predicate. Return 1 if the
|
||||
result overflows. See above for restrictions. */
|
||||
#if 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS
|
||||
# define _GL_INT_OP_WRAPV(a, b, r, op, overflow) \
|
||||
(_Generic \
|
||||
(*(r), \
|
||||
signed char: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
signed char, SCHAR_MIN, SCHAR_MAX), \
|
||||
unsigned char: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
unsigned char, 0, UCHAR_MAX), \
|
||||
short int: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
short int, SHRT_MIN, SHRT_MAX), \
|
||||
unsigned short int: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
unsigned short int, 0, USHRT_MAX), \
|
||||
int: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
int, INT_MIN, INT_MAX), \
|
||||
unsigned int: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
unsigned int, 0, UINT_MAX), \
|
||||
long int: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
|
||||
long int, LONG_MIN, LONG_MAX), \
|
||||
unsigned long int: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
|
||||
unsigned long int, 0, ULONG_MAX), \
|
||||
long long int: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
|
||||
long long int, LLONG_MIN, LLONG_MAX), \
|
||||
unsigned long long int: \
|
||||
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
|
||||
unsigned long long int, 0, ULLONG_MAX)))
|
||||
#else
|
||||
/* Store the low-order bits of A <op> B into *R, where OP specifies
|
||||
the operation and OVERFLOW the overflow predicate. If *R is
|
||||
signed, its type is ST with bounds SMIN..SMAX; otherwise its type
|
||||
is UT with bounds U..UMAX. ST and UT are narrower than int.
|
||||
Return 1 if the result overflows. See above for restrictions. */
|
||||
# if _GL_HAVE___TYPEOF__
|
||||
# define _GL_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax) \
|
||||
(TYPE_SIGNED (__typeof__ (*(r))) \
|
||||
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, st, smin, smax) \
|
||||
: _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, ut, 0, umax))
|
||||
# else
|
||||
# define _GL_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax) \
|
||||
(overflow (a, b, smin, smax) \
|
||||
? (overflow (a, b, 0, umax) \
|
||||
? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st), 1) \
|
||||
: (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st)) < 0) \
|
||||
: (overflow (a, b, 0, umax) \
|
||||
? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st)) >= 0 \
|
||||
: (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st), 0)))
|
||||
# endif
|
||||
|
||||
# define _GL_INT_OP_WRAPV(a, b, r, op, overflow) \
|
||||
(sizeof *(r) == sizeof (signed char) \
|
||||
? _GL_INT_OP_WRAPV_SMALLISH (a, b, r, op, overflow, \
|
||||
signed char, SCHAR_MIN, SCHAR_MAX, \
|
||||
unsigned char, UCHAR_MAX) \
|
||||
: sizeof *(r) == sizeof (short int) \
|
||||
? _GL_INT_OP_WRAPV_SMALLISH (a, b, r, op, overflow, \
|
||||
short int, SHRT_MIN, SHRT_MAX, \
|
||||
unsigned short int, USHRT_MAX) \
|
||||
: sizeof *(r) == sizeof (int) \
|
||||
? (EXPR_SIGNED (*(r)) \
|
||||
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
int, INT_MIN, INT_MAX) \
|
||||
: _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
|
||||
unsigned int, 0, UINT_MAX)) \
|
||||
: _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow))
|
||||
# ifdef LLONG_MAX
|
||||
# define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \
|
||||
(sizeof *(r) == sizeof (long int) \
|
||||
? (EXPR_SIGNED (*(r)) \
|
||||
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
|
||||
long int, LONG_MIN, LONG_MAX) \
|
||||
: _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
|
||||
unsigned long int, 0, ULONG_MAX)) \
|
||||
: (EXPR_SIGNED (*(r)) \
|
||||
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
|
||||
long long int, LLONG_MIN, LLONG_MAX) \
|
||||
: _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
|
||||
unsigned long long int, 0, ULLONG_MAX)))
|
||||
# else
|
||||
# define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \
|
||||
(EXPR_SIGNED (*(r)) \
|
||||
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
|
||||
long int, LONG_MIN, LONG_MAX) \
|
||||
: _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
|
||||
unsigned long int, 0, ULONG_MAX))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Store the low-order bits of A <op> B into *R, where the operation
|
||||
is given by OP. Use the unsigned type UT for calculation to avoid
|
||||
overflow problems. *R's type is T, with extrema TMIN and TMAX.
|
||||
T must be a signed integer type. Return 1 if the result overflows. */
|
||||
#define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \
|
||||
(overflow (a, b, tmin, tmax) \
|
||||
? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 1) \
|
||||
: (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 0))
|
||||
|
||||
/* Return the low-order bits of A <op> B, where the operation is given
|
||||
by OP. Use the unsigned type UT for calculation to avoid undefined
|
||||
behavior on signed integer overflow, and convert the result to type T.
|
||||
UT is at least as wide as T and is no narrower than unsigned int,
|
||||
T is two's complement, and there is no padding or trap representations.
|
||||
Assume that converting UT to T yields the low-order bits, as is
|
||||
done in all known two's-complement C compilers. E.g., see:
|
||||
https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
|
||||
|
||||
According to the C standard, converting UT to T yields an
|
||||
implementation-defined result or signal for values outside T's
|
||||
range. However, code that works around this theoretical problem
|
||||
runs afoul of a compiler bug in Oracle Studio 12.3 x86. See:
|
||||
https://lists.gnu.org/r/bug-gnulib/2017-04/msg00049.html
|
||||
As the compiler bug is real, don't try to work around the
|
||||
theoretical problem. */
|
||||
|
||||
#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t) \
|
||||
((t) ((ut) (a) op (ut) (b)))
|
||||
|
||||
/* Return true if the numeric values A + B, A - B, A * B fall outside
|
||||
the range TMIN..TMAX. Arguments should be integer expressions
|
||||
without side effects. TMIN should be signed and nonpositive.
|
||||
TMAX should be positive, and should be signed unless TMIN is zero. */
|
||||
#define _GL_INT_ADD_RANGE_OVERFLOW(a, b, tmin, tmax) \
|
||||
((b) < 0 \
|
||||
? (((tmin) \
|
||||
? ((EXPR_SIGNED (_GL_INT_CONVERT (a, (tmin) - (b))) || (b) < (tmin)) \
|
||||
&& (a) < (tmin) - (b)) \
|
||||
: (a) <= -1 - (b)) \
|
||||
|| ((EXPR_SIGNED (a) ? 0 <= (a) : (tmax) < (a)) && (tmax) < (a) + (b))) \
|
||||
: (a) < 0 \
|
||||
? (((tmin) \
|
||||
? ((EXPR_SIGNED (_GL_INT_CONVERT (b, (tmin) - (a))) || (a) < (tmin)) \
|
||||
&& (b) < (tmin) - (a)) \
|
||||
: (b) <= -1 - (a)) \
|
||||
|| ((EXPR_SIGNED (_GL_INT_CONVERT (a, b)) || (tmax) < (b)) \
|
||||
&& (tmax) < (a) + (b))) \
|
||||
: (tmax) < (b) || (tmax) - (b) < (a))
|
||||
#define _GL_INT_SUBTRACT_RANGE_OVERFLOW(a, b, tmin, tmax) \
|
||||
(((a) < 0) == ((b) < 0) \
|
||||
? ((a) < (b) \
|
||||
? !(tmin) || -1 - (tmin) < (b) - (a) - 1 \
|
||||
: (tmax) < (a) - (b)) \
|
||||
: (a) < 0 \
|
||||
? ((!EXPR_SIGNED (_GL_INT_CONVERT ((a) - (tmin), b)) && (a) - (tmin) < 0) \
|
||||
|| (a) - (tmin) < (b)) \
|
||||
: ((! (EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \
|
||||
&& EXPR_SIGNED (_GL_INT_CONVERT ((tmax) + (b), a))) \
|
||||
&& (tmax) <= -1 - (b)) \
|
||||
|| (tmax) + (b) < (a)))
|
||||
#define _GL_INT_MULTIPLY_RANGE_OVERFLOW(a, b, tmin, tmax) \
|
||||
((b) < 0 \
|
||||
? ((a) < 0 \
|
||||
? (EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \
|
||||
? (a) < (tmax) / (b) \
|
||||
: ((INT_NEGATE_OVERFLOW (b) \
|
||||
? _GL_INT_CONVERT (b, tmax) >> (TYPE_WIDTH (+ (b)) - 1) \
|
||||
: (tmax) / -(b)) \
|
||||
<= -1 - (a))) \
|
||||
: INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (b, tmin)) && (b) == -1 \
|
||||
? (EXPR_SIGNED (a) \
|
||||
? 0 < (a) + (tmin) \
|
||||
: 0 < (a) && -1 - (tmin) < (a) - 1) \
|
||||
: (tmin) / (b) < (a)) \
|
||||
: (b) == 0 \
|
||||
? 0 \
|
||||
: ((a) < 0 \
|
||||
? (INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (a, tmin)) && (a) == -1 \
|
||||
? (EXPR_SIGNED (b) ? 0 < (b) + (tmin) : -1 - (tmin) < (b) - 1) \
|
||||
: (tmin) / (a) < (b)) \
|
||||
: (tmax) / (b) < (a)))
|
||||
|
||||
/* The following macros compute A + B, A - B, and A * B, respectively.
|
||||
If no overflow occurs, they set *R to the result and return 1;
|
||||
otherwise, they return 0 and may modify *R.
|
||||
|
||||
Example usage:
|
||||
|
||||
long int result;
|
||||
if (INT_ADD_OK (a, b, &result))
|
||||
printf ("result is %ld\n", result);
|
||||
else
|
||||
printf ("overflow\n");
|
||||
|
||||
A, B, and *R should be integers; they need not be the same type,
|
||||
and they need not be all signed or all unsigned.
|
||||
|
||||
These macros work correctly on all known practical hosts, and do not rely
|
||||
on undefined behavior due to signed arithmetic overflow.
|
||||
|
||||
These macros are not constant expressions.
|
||||
|
||||
These macros may evaluate their arguments zero or multiple times, so the
|
||||
arguments should not have side effects.
|
||||
|
||||
These macros are tuned for B being a constant. */
|
||||
|
||||
#define INT_ADD_OK(a, b, r) ! INT_ADD_WRAPV (a, b, r)
|
||||
#define INT_SUBTRACT_OK(a, b, r) ! INT_SUBTRACT_WRAPV (a, b, r)
|
||||
#define INT_MULTIPLY_OK(a, b, r) ! INT_MULTIPLY_WRAPV (a, b, r)
|
||||
|
||||
#endif /* _GL_INTPROPS_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,202 +0,0 @@
|
||||
/* System definitions for code taken from the GNU C Library
|
||||
|
||||
Copyright 2017-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this program; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
/* This is intended to be a good-enough substitute for glibc system
|
||||
macros like those defined in <sys/cdefs.h>, so that Gnulib code
|
||||
shared with glibc can do this as the first #include:
|
||||
|
||||
#ifndef _LIBC
|
||||
# include <libc-config.h>
|
||||
#endif
|
||||
|
||||
When compiled as part of glibc this is a no-op; when compiled as
|
||||
part of Gnulib this includes Gnulib's <config.h> and defines macros
|
||||
that glibc library code would normally assume.
|
||||
|
||||
Note: This header file MUST NOT be included by public header files
|
||||
of Gnulib. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* On glibc this includes <features.h> and <sys/cdefs.h> and #defines
|
||||
_FEATURES_H, __WORDSIZE, and __set_errno. On FreeBSD 11 and
|
||||
DragonFlyBSD 5.9 it includes <sys/cdefs.h> which defines __nonnull.
|
||||
Elsewhere it is harmless. */
|
||||
#include <errno.h>
|
||||
|
||||
/* From glibc <errno.h>. */
|
||||
#ifndef __set_errno
|
||||
# define __set_errno(val) (errno = (val))
|
||||
#endif
|
||||
|
||||
/* From glibc <features.h>. */
|
||||
|
||||
#ifndef __GNUC_PREREQ
|
||||
# if defined __GNUC__ && defined __GNUC_MINOR__
|
||||
# define __GNUC_PREREQ(maj, min) ((maj) < __GNUC__ + ((min) <= __GNUC_MINOR__))
|
||||
# else
|
||||
# define __GNUC_PREREQ(maj, min) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __glibc_clang_prereq
|
||||
# if defined __clang_major__ && defined __clang_minor__
|
||||
# ifdef __apple_build_version__
|
||||
/* Apple for some reason renumbers __clang_major__ and __clang_minor__.
|
||||
Gnulib code uses only __glibc_clang_prereq (3, 5); map it to
|
||||
6000000 <= __apple_build_version__. Support for other calls to
|
||||
__glibc_clang_prereq can be added here as needed. */
|
||||
# define __glibc_clang_prereq(maj, min) \
|
||||
((maj) == 3 && (min) == 5 ? 6000000 <= __apple_build_version__ : 0)
|
||||
# else
|
||||
# define __glibc_clang_prereq(maj, min) \
|
||||
((maj) < __clang_major__ + ((min) <= __clang_minor__))
|
||||
# endif
|
||||
# else
|
||||
# define __glibc_clang_prereq(maj, min) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __attribute_nonnull__
|
||||
/* <sys/cdefs.h> either does not exist, or is too old for Gnulib.
|
||||
Prepare to include <cdefs.h>, which is Gnulib's version of a
|
||||
more-recent glibc <sys/cdefs.h>. */
|
||||
|
||||
/* Define _FEATURES_H so that <cdefs.h> does not include <features.h>. */
|
||||
# ifndef _FEATURES_H
|
||||
# define _FEATURES_H 1
|
||||
# endif
|
||||
/* Define __GNULIB_CDEFS so that <cdefs.h> does not attempt to include
|
||||
nonexistent files. */
|
||||
# define __GNULIB_CDEFS
|
||||
/* Undef the macros unconditionally defined by our copy of glibc
|
||||
<sys/cdefs.h>, so that they do not clash with any system-defined
|
||||
versions. */
|
||||
# undef _SYS_CDEFS_H
|
||||
# undef __ASMNAME
|
||||
# undef __ASMNAME2
|
||||
# undef __BEGIN_DECLS
|
||||
# undef __CONCAT
|
||||
# undef __END_DECLS
|
||||
# undef __HAVE_GENERIC_SELECTION
|
||||
# undef __LDBL_COMPAT
|
||||
# undef __LDBL_REDIR
|
||||
# undef __LDBL_REDIR1
|
||||
# undef __LDBL_REDIR1_DECL
|
||||
# undef __LDBL_REDIR1_NTH
|
||||
# undef __LDBL_REDIR2_DECL
|
||||
# undef __LDBL_REDIR_DECL
|
||||
# undef __LDBL_REDIR_NTH
|
||||
# undef __LEAF
|
||||
# undef __LEAF_ATTR
|
||||
# undef __NTH
|
||||
# undef __NTHNL
|
||||
# undef __REDIRECT
|
||||
# undef __REDIRECT_LDBL
|
||||
# undef __REDIRECT_NTH
|
||||
# undef __REDIRECT_NTHNL
|
||||
# undef __REDIRECT_NTH_LDBL
|
||||
# undef __STRING
|
||||
# undef __THROW
|
||||
# undef __THROWNL
|
||||
# undef __attr_access
|
||||
# undef __attr_access_none
|
||||
# undef __attr_dealloc
|
||||
# undef __attr_dealloc_free
|
||||
# undef __attribute__
|
||||
# undef __attribute_alloc_align__
|
||||
# undef __attribute_alloc_size__
|
||||
# undef __attribute_artificial__
|
||||
# undef __attribute_const__
|
||||
# undef __attribute_deprecated__
|
||||
# undef __attribute_deprecated_msg__
|
||||
# undef __attribute_format_arg__
|
||||
# undef __attribute_format_strfmon__
|
||||
# undef __attribute_malloc__
|
||||
# undef __attribute_maybe_unused__
|
||||
# undef __attribute_noinline__
|
||||
# undef __attribute_nonstring__
|
||||
# undef __attribute_pure__
|
||||
# undef __attribute_returns_twice__
|
||||
# undef __attribute_used__
|
||||
# undef __attribute_warn_unused_result__
|
||||
# undef __bos
|
||||
# undef __bos0
|
||||
# undef __errordecl
|
||||
# undef __extension__
|
||||
# undef __extern_always_inline
|
||||
# undef __extern_inline
|
||||
# undef __flexarr
|
||||
# undef __fortified_attr_access
|
||||
# undef __fortify_function
|
||||
# undef __glibc_c99_flexarr_available
|
||||
# undef __glibc_fortify
|
||||
# undef __glibc_fortify_n
|
||||
# undef __glibc_has_attribute
|
||||
# undef __glibc_has_builtin
|
||||
# undef __glibc_has_extension
|
||||
# undef __glibc_likely
|
||||
# undef __glibc_macro_warning
|
||||
# undef __glibc_macro_warning1
|
||||
# undef __glibc_objsize
|
||||
# undef __glibc_objsize0
|
||||
# undef __glibc_safe_len_cond
|
||||
# undef __glibc_safe_or_unknown_len
|
||||
# undef __glibc_unlikely
|
||||
# undef __glibc_unsafe_len
|
||||
# undef __glibc_unsigned_or_positive
|
||||
# undef __inline
|
||||
# undef __ptr_t
|
||||
# undef __restrict
|
||||
# undef __restrict_arr
|
||||
# undef __va_arg_pack
|
||||
# undef __va_arg_pack_len
|
||||
# undef __warnattr
|
||||
# undef __wur
|
||||
|
||||
/* Include our copy of glibc <sys/cdefs.h>. */
|
||||
# include <cdefs.h>
|
||||
|
||||
/* <cdefs.h> __inline is too pessimistic for non-GCC. */
|
||||
# undef __inline
|
||||
# ifndef HAVE___INLINE
|
||||
# if 199901 <= __STDC_VERSION__ || defined inline
|
||||
# define __inline inline
|
||||
# else
|
||||
# define __inline
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif /* defined __glibc_likely */
|
||||
|
||||
|
||||
/* A substitute for glibc <libc-symbols.h>, good enough for Gnulib. */
|
||||
#define attribute_hidden
|
||||
#define libc_hidden_proto(name)
|
||||
#define libc_hidden_def(name)
|
||||
#define libc_hidden_weak(name)
|
||||
#define libc_hidden_ver(local, name)
|
||||
#define strong_alias(name, aliasname)
|
||||
#define weak_alias(name, aliasname)
|
||||
|
||||
/* A substitute for glibc <shlib-compat.h>, good enough for Gnulib. */
|
||||
#define SHLIB_COMPAT(lib, introduced, obsoleted) 0
|
||||
#define compat_symbol(lib, local, symbol, version) extern int dummy
|
||||
#define versioned_symbol(lib, local, symbol, version) extern int dummy
|
||||
@@ -1,132 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* A GNU-like <limits.h>.
|
||||
|
||||
Copyright 2016-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
|
||||
#if defined _GL_ALREADY_INCLUDING_LIMITS_H
|
||||
/* Special invocation convention:
|
||||
On Haiku/x86_64, we have a sequence of nested includes
|
||||
<limits.h> -> <syslimits.h> -> <limits.h>.
|
||||
In this situation, LONG_MAX and INT_MAX are not yet defined,
|
||||
therefore we should not attempt to define LONG_BIT. */
|
||||
|
||||
#include_next <limits.h>
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
#ifndef _GL_LIMITS_H
|
||||
|
||||
# define _GL_ALREADY_INCLUDING_LIMITS_H
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
# include_next <limits.h>
|
||||
|
||||
# undef _GL_ALREADY_INCLUDING_LIMITS_H
|
||||
|
||||
#ifndef _GL_LIMITS_H
|
||||
#define _GL_LIMITS_H
|
||||
|
||||
#ifndef LLONG_MIN
|
||||
# if defined LONG_LONG_MIN /* HP-UX 11.31 */
|
||||
# define LLONG_MIN LONG_LONG_MIN
|
||||
# elif defined LONGLONG_MIN /* IRIX 6.5 */
|
||||
# define LLONG_MIN LONGLONG_MIN
|
||||
# elif defined __GNUC__
|
||||
# define LLONG_MIN (- __LONG_LONG_MAX__ - 1LL)
|
||||
# endif
|
||||
#endif
|
||||
#ifndef LLONG_MAX
|
||||
# if defined LONG_LONG_MAX /* HP-UX 11.31 */
|
||||
# define LLONG_MAX LONG_LONG_MAX
|
||||
# elif defined LONGLONG_MAX /* IRIX 6.5 */
|
||||
# define LLONG_MAX LONGLONG_MAX
|
||||
# elif defined __GNUC__
|
||||
# define LLONG_MAX __LONG_LONG_MAX__
|
||||
# endif
|
||||
#endif
|
||||
#ifndef ULLONG_MAX
|
||||
# if defined ULONG_LONG_MAX /* HP-UX 11.31 */
|
||||
# define ULLONG_MAX ULONG_LONG_MAX
|
||||
# elif defined ULONGLONG_MAX /* IRIX 6.5 */
|
||||
# define ULLONG_MAX ULONGLONG_MAX
|
||||
# elif defined __GNUC__
|
||||
# define ULLONG_MAX (__LONG_LONG_MAX__ * 2ULL + 1ULL)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The number of usable bits in an unsigned or signed integer type
|
||||
with minimum value MIN and maximum value MAX, as an int expression
|
||||
suitable in #if. Cover all known practical hosts. This
|
||||
implementation exploits the fact that MAX is 1 less than a power of
|
||||
2, and merely counts the number of 1 bits in MAX; "COBn" means
|
||||
"count the number of 1 bits in the low-order n bits"). */
|
||||
#define _GL_INTEGER_WIDTH(min, max) (((min) < 0) + _GL_COB128 (max))
|
||||
#define _GL_COB128(n) (_GL_COB64 ((n) >> 31 >> 31 >> 2) + _GL_COB64 (n))
|
||||
#define _GL_COB64(n) (_GL_COB32 ((n) >> 31 >> 1) + _GL_COB32 (n))
|
||||
#define _GL_COB32(n) (_GL_COB16 ((n) >> 16) + _GL_COB16 (n))
|
||||
#define _GL_COB16(n) (_GL_COB8 ((n) >> 8) + _GL_COB8 (n))
|
||||
#define _GL_COB8(n) (_GL_COB4 ((n) >> 4) + _GL_COB4 (n))
|
||||
#define _GL_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + !!((n) & 1))
|
||||
|
||||
#ifndef WORD_BIT
|
||||
/* Assume 'int' is 32 bits wide. */
|
||||
# define WORD_BIT 32
|
||||
#endif
|
||||
#ifndef LONG_BIT
|
||||
/* Assume 'long' is 32 or 64 bits wide. */
|
||||
# if LONG_MAX == INT_MAX
|
||||
# define LONG_BIT 32
|
||||
# else
|
||||
# define LONG_BIT 64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Macros specified by C2x and by ISO/IEC TS 18661-1:2014. */
|
||||
|
||||
#if (! defined ULLONG_WIDTH \
|
||||
&& (defined _GNU_SOURCE || defined __STDC_WANT_IEC_60559_BFP_EXT__ \
|
||||
|| (defined __STDC_VERSION__ && 201710 < __STDC_VERSION__)))
|
||||
# define CHAR_WIDTH _GL_INTEGER_WIDTH (CHAR_MIN, CHAR_MAX)
|
||||
# define SCHAR_WIDTH _GL_INTEGER_WIDTH (SCHAR_MIN, SCHAR_MAX)
|
||||
# define UCHAR_WIDTH _GL_INTEGER_WIDTH (0, UCHAR_MAX)
|
||||
# define SHRT_WIDTH _GL_INTEGER_WIDTH (SHRT_MIN, SHRT_MAX)
|
||||
# define USHRT_WIDTH _GL_INTEGER_WIDTH (0, USHRT_MAX)
|
||||
# define INT_WIDTH _GL_INTEGER_WIDTH (INT_MIN, INT_MAX)
|
||||
# define UINT_WIDTH _GL_INTEGER_WIDTH (0, UINT_MAX)
|
||||
# define LONG_WIDTH _GL_INTEGER_WIDTH (LONG_MIN, LONG_MAX)
|
||||
# define ULONG_WIDTH _GL_INTEGER_WIDTH (0, ULONG_MAX)
|
||||
# define LLONG_WIDTH _GL_INTEGER_WIDTH (LLONG_MIN, LLONG_MAX)
|
||||
# define ULLONG_WIDTH _GL_INTEGER_WIDTH (0, ULLONG_MAX)
|
||||
#endif
|
||||
|
||||
/* Macros specified by C2x. */
|
||||
|
||||
#if (! defined BOOL_WIDTH \
|
||||
&& (defined _GNU_SOURCE \
|
||||
|| (defined __STDC_VERSION__ && 201710 < __STDC_VERSION__)))
|
||||
# define BOOL_MAX 1
|
||||
# define BOOL_WIDTH 1
|
||||
#endif
|
||||
|
||||
#endif /* _GL_LIMITS_H */
|
||||
#endif /* _GL_LIMITS_H */
|
||||
#endif
|
||||
@@ -1,137 +0,0 @@
|
||||
/* Determine a canonical name for the current locale's character encoding.
|
||||
Copyright (C) 2000-2003, 2009-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU CHARSET Library.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _LOCALCHARSET_H
|
||||
#define _LOCALCHARSET_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Determine the current locale's character encoding, and canonicalize it
|
||||
into one of the canonical names listed below.
|
||||
The result must not be freed; it is statically allocated. The result
|
||||
becomes invalid when setlocale() is used to change the global locale, or
|
||||
when the value of one of the environment variables LC_ALL, LC_CTYPE, LANG
|
||||
is changed; threads in multithreaded programs should not do this.
|
||||
If the canonical name cannot be determined, the result is a non-canonical
|
||||
name. */
|
||||
extern const char * locale_charset (void);
|
||||
|
||||
/* About GNU canonical names for character encodings:
|
||||
|
||||
Every canonical name must be supported by GNU libiconv. Support by GNU libc
|
||||
is also desirable.
|
||||
|
||||
The name is case insensitive. Usually an upper case MIME charset name is
|
||||
preferred.
|
||||
|
||||
The current list of these GNU canonical names is:
|
||||
|
||||
name MIME? used by which systems
|
||||
(darwin = Mac OS X, windows = native Windows)
|
||||
|
||||
ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin minix cygwin
|
||||
ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos
|
||||
ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos
|
||||
ISO-8859-3 Y glibc solaris cygwin
|
||||
ISO-8859-4 Y hpux osf solaris freebsd netbsd openbsd darwin
|
||||
ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos
|
||||
ISO-8859-6 Y glibc aix hpux solaris cygwin
|
||||
ISO-8859-7 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos
|
||||
ISO-8859-8 Y glibc aix hpux osf solaris cygwin zos
|
||||
ISO-8859-9 Y glibc aix hpux irix osf solaris freebsd darwin cygwin zos
|
||||
ISO-8859-13 glibc hpux solaris freebsd netbsd openbsd darwin cygwin
|
||||
ISO-8859-14 glibc cygwin
|
||||
ISO-8859-15 glibc aix irix osf solaris freebsd netbsd openbsd darwin cygwin
|
||||
KOI8-R Y glibc hpux solaris freebsd netbsd openbsd darwin
|
||||
KOI8-U Y glibc freebsd netbsd openbsd darwin cygwin
|
||||
KOI8-T glibc
|
||||
CP437 dos
|
||||
CP775 dos
|
||||
CP850 aix osf dos
|
||||
CP852 dos
|
||||
CP855 dos
|
||||
CP856 aix
|
||||
CP857 dos
|
||||
CP861 dos
|
||||
CP862 dos
|
||||
CP864 dos
|
||||
CP865 dos
|
||||
CP866 freebsd netbsd openbsd darwin dos
|
||||
CP869 dos
|
||||
CP874 windows dos
|
||||
CP922 aix
|
||||
CP932 aix cygwin windows dos
|
||||
CP943 aix zos
|
||||
CP949 osf darwin windows dos
|
||||
CP950 windows dos
|
||||
CP1046 aix
|
||||
CP1124 aix
|
||||
CP1125 dos
|
||||
CP1129 aix
|
||||
CP1131 freebsd darwin
|
||||
CP1250 windows
|
||||
CP1251 glibc hpux solaris freebsd netbsd openbsd darwin cygwin windows
|
||||
CP1252 aix windows
|
||||
CP1253 windows
|
||||
CP1254 windows
|
||||
CP1255 glibc windows
|
||||
CP1256 windows
|
||||
CP1257 windows
|
||||
GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin cygwin zos
|
||||
EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin
|
||||
EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin zos
|
||||
EUC-TW glibc aix hpux irix osf solaris netbsd
|
||||
BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin cygwin zos
|
||||
BIG5-HKSCS glibc hpux solaris netbsd darwin
|
||||
GBK glibc aix osf solaris freebsd darwin cygwin windows dos
|
||||
GB18030 glibc hpux solaris freebsd netbsd darwin
|
||||
SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin
|
||||
JOHAB glibc solaris windows
|
||||
TIS-620 glibc aix hpux osf solaris cygwin zos
|
||||
VISCII Y glibc
|
||||
TCVN5712-1 glibc
|
||||
ARMSCII-8 glibc freebsd netbsd darwin
|
||||
GEORGIAN-PS glibc cygwin
|
||||
PT154 glibc netbsd cygwin
|
||||
HP-ROMAN8 hpux
|
||||
HP-ARABIC8 hpux
|
||||
HP-GREEK8 hpux
|
||||
HP-HEBREW8 hpux
|
||||
HP-TURKISH8 hpux
|
||||
HP-KANA8 hpux
|
||||
DEC-KANJI osf
|
||||
DEC-HANYU osf
|
||||
UTF-8 Y glibc aix hpux osf solaris netbsd darwin cygwin zos
|
||||
|
||||
Note: Names which are not marked as being a MIME name should not be used in
|
||||
Internet protocols for information interchange (mail, news, etc.).
|
||||
|
||||
Note: ASCII and ANSI_X3.4-1968 are synonymous canonical names. Applications
|
||||
must understand both names and treat them as equivalent.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _LOCALCHARSET_H */
|
||||
@@ -1,51 +0,0 @@
|
||||
/* malloc() function that is glibc compatible.
|
||||
|
||||
Copyright (C) 1997-1998, 2006-2007, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* written by Jim Meyering and Bruno Haible */
|
||||
|
||||
#define _GL_USE_STDLIB_ALLOC 1
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "xalloc-oversized.h"
|
||||
|
||||
/* Allocate an N-byte block of memory from the heap, even if N is 0. */
|
||||
|
||||
void *
|
||||
rpl_malloc (size_t n)
|
||||
{
|
||||
if (n == 0)
|
||||
n = 1;
|
||||
|
||||
if (xalloc_oversized (n, 1))
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *result = malloc (n);
|
||||
|
||||
#if !HAVE_MALLOC_POSIX
|
||||
if (result == NULL)
|
||||
errno = ENOMEM;
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/* Variable-sized buffer with on-stack default allocation.
|
||||
Copyright (C) 2015-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _SCRATCH_BUFFER_H
|
||||
#define _SCRATCH_BUFFER_H
|
||||
|
||||
/* Scratch buffers with a default stack allocation and fallback to
|
||||
heap allocation. It is expected that this function is used in this
|
||||
way:
|
||||
|
||||
struct scratch_buffer tmpbuf;
|
||||
scratch_buffer_init (&tmpbuf);
|
||||
|
||||
while (!function_that_uses_buffer (tmpbuf.data, tmpbuf.length))
|
||||
if (!scratch_buffer_grow (&tmpbuf))
|
||||
return -1;
|
||||
|
||||
scratch_buffer_free (&tmpbuf);
|
||||
return 0;
|
||||
|
||||
The allocation functions (scratch_buffer_grow,
|
||||
scratch_buffer_grow_preserve, scratch_buffer_set_array_size) make
|
||||
sure that the heap allocation, if any, is freed, so that the code
|
||||
above does not have a memory leak. The buffer still remains in a
|
||||
state that can be deallocated using scratch_buffer_free, so a loop
|
||||
like this is valid as well:
|
||||
|
||||
struct scratch_buffer tmpbuf;
|
||||
scratch_buffer_init (&tmpbuf);
|
||||
|
||||
while (!function_that_uses_buffer (tmpbuf.data, tmpbuf.length))
|
||||
if (!scratch_buffer_grow (&tmpbuf))
|
||||
break;
|
||||
|
||||
scratch_buffer_free (&tmpbuf);
|
||||
|
||||
scratch_buffer_grow and scratch_buffer_grow_preserve are guaranteed
|
||||
to grow the buffer by at least 512 bytes. This means that when
|
||||
using the scratch buffer as a backing store for a non-character
|
||||
array whose element size, in bytes, is 512 or smaller, the scratch
|
||||
buffer only has to grow once to make room for at least one more
|
||||
element.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Scratch buffer. Must be initialized with scratch_buffer_init
|
||||
before its use. */
|
||||
struct scratch_buffer {
|
||||
void *data; /* Pointer to the beginning of the scratch area. */
|
||||
size_t length; /* Allocated space at the data pointer, in bytes. */
|
||||
union { max_align_t __align; char __c[1024]; } __space;
|
||||
};
|
||||
|
||||
/* Initializes *BUFFER so that BUFFER->data points to BUFFER->__space
|
||||
and BUFFER->length reflects the available space. */
|
||||
static inline void
|
||||
scratch_buffer_init (struct scratch_buffer *buffer)
|
||||
{
|
||||
buffer->data = buffer->__space.__c;
|
||||
buffer->length = sizeof (buffer->__space);
|
||||
}
|
||||
|
||||
/* Deallocates *BUFFER (if it was heap-allocated). */
|
||||
static inline void
|
||||
scratch_buffer_free (struct scratch_buffer *buffer)
|
||||
{
|
||||
if (buffer->data != buffer->__space.__c)
|
||||
free (buffer->data);
|
||||
}
|
||||
|
||||
/* Grow *BUFFER by some arbitrary amount. The buffer contents is NOT
|
||||
preserved. Return true on success, false on allocation failure (in
|
||||
which case the old buffer is freed). On success, the new buffer is
|
||||
larger than the previous size. On failure, *BUFFER is deallocated,
|
||||
but remains in a free-able state, and errno is set. */
|
||||
bool __libc_scratch_buffer_grow (struct scratch_buffer *buffer);
|
||||
libc_hidden_proto (__libc_scratch_buffer_grow)
|
||||
|
||||
/* Alias for __libc_scratch_buffer_grow. */
|
||||
static __always_inline bool
|
||||
scratch_buffer_grow (struct scratch_buffer *buffer)
|
||||
{
|
||||
return __glibc_likely (__libc_scratch_buffer_grow (buffer));
|
||||
}
|
||||
|
||||
/* Like __libc_scratch_buffer_grow, but preserve the old buffer
|
||||
contents on success, as a prefix of the new buffer. */
|
||||
bool __libc_scratch_buffer_grow_preserve (struct scratch_buffer *buffer);
|
||||
libc_hidden_proto (__libc_scratch_buffer_grow_preserve)
|
||||
|
||||
/* Alias for __libc_scratch_buffer_grow_preserve. */
|
||||
static __always_inline bool
|
||||
scratch_buffer_grow_preserve (struct scratch_buffer *buffer)
|
||||
{
|
||||
return __glibc_likely (__libc_scratch_buffer_grow_preserve (buffer));
|
||||
}
|
||||
|
||||
/* Grow *BUFFER so that it can store at least NELEM elements of SIZE
|
||||
bytes. The buffer contents are NOT preserved. Both NELEM and SIZE
|
||||
can be zero. Return true on success, false on allocation failure
|
||||
(in which case the old buffer is freed, but *BUFFER remains in a
|
||||
free-able state, and errno is set). It is unspecified whether this
|
||||
function can reduce the array size. */
|
||||
bool __libc_scratch_buffer_set_array_size (struct scratch_buffer *buffer,
|
||||
size_t nelem, size_t size);
|
||||
libc_hidden_proto (__libc_scratch_buffer_set_array_size)
|
||||
|
||||
/* Alias for __libc_scratch_set_array_size. */
|
||||
static __always_inline bool
|
||||
scratch_buffer_set_array_size (struct scratch_buffer *buffer,
|
||||
size_t nelem, size_t size)
|
||||
{
|
||||
return __glibc_likely (__libc_scratch_buffer_set_array_size
|
||||
(buffer, nelem, size));
|
||||
}
|
||||
|
||||
/* Return a copy of *BUFFER's first SIZE bytes as a heap-allocated block,
|
||||
deallocating *BUFFER if it was heap-allocated. SIZE must be at
|
||||
most *BUFFER's size. Return NULL (setting errno) on memory
|
||||
exhaustion. */
|
||||
void *__libc_scratch_buffer_dupfree (struct scratch_buffer *buffer,
|
||||
size_t size);
|
||||
libc_hidden_proto (__libc_scratch_buffer_dupfree)
|
||||
|
||||
/* Alias for __libc_scratch_dupfree. */
|
||||
static __always_inline void *
|
||||
scratch_buffer_dupfree (struct scratch_buffer *buffer, size_t size)
|
||||
{
|
||||
void *r = __libc_scratch_buffer_dupfree (buffer, size);
|
||||
return __glibc_likely (r != NULL) ? r : NULL;
|
||||
}
|
||||
|
||||
#endif /* _SCRATCH_BUFFER_H */
|
||||
@@ -1,41 +0,0 @@
|
||||
/* Variable-sized buffer with on-stack default allocation.
|
||||
Copyright (C) 2020-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _LIBC
|
||||
# include <libc-config.h>
|
||||
#endif
|
||||
|
||||
#include <scratch_buffer.h>
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
__libc_scratch_buffer_dupfree (struct scratch_buffer *buffer, size_t size)
|
||||
{
|
||||
void *data = buffer->data;
|
||||
if (data == buffer->__space.__c)
|
||||
{
|
||||
void *copy = malloc (size);
|
||||
return copy != NULL ? memcpy (copy, data, size) : NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
void *copy = realloc (data, size);
|
||||
return copy != NULL ? copy : data;
|
||||
}
|
||||
}
|
||||
libc_hidden_def (__libc_scratch_buffer_dupfree)
|
||||
@@ -1,56 +0,0 @@
|
||||
/* Variable-sized buffer with on-stack default allocation.
|
||||
Copyright (C) 2015-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _LIBC
|
||||
# include <libc-config.h>
|
||||
#endif
|
||||
|
||||
#include <scratch_buffer.h>
|
||||
#include <errno.h>
|
||||
|
||||
bool
|
||||
__libc_scratch_buffer_grow (struct scratch_buffer *buffer)
|
||||
{
|
||||
void *new_ptr;
|
||||
size_t new_length = buffer->length * 2;
|
||||
|
||||
/* Discard old buffer. */
|
||||
scratch_buffer_free (buffer);
|
||||
|
||||
/* Check for overflow. */
|
||||
if (__glibc_likely (new_length >= buffer->length))
|
||||
new_ptr = malloc (new_length);
|
||||
else
|
||||
{
|
||||
__set_errno (ENOMEM);
|
||||
new_ptr = NULL;
|
||||
}
|
||||
|
||||
if (__glibc_unlikely (new_ptr == NULL))
|
||||
{
|
||||
/* Buffer must remain valid to free. */
|
||||
scratch_buffer_init (buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Install new heap-based buffer. */
|
||||
buffer->data = new_ptr;
|
||||
buffer->length = new_length;
|
||||
return true;
|
||||
}
|
||||
libc_hidden_def (__libc_scratch_buffer_grow)
|
||||
@@ -1,67 +0,0 @@
|
||||
/* Variable-sized buffer with on-stack default allocation.
|
||||
Copyright (C) 2015-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _LIBC
|
||||
# include <libc-config.h>
|
||||
#endif
|
||||
|
||||
#include <scratch_buffer.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
bool
|
||||
__libc_scratch_buffer_grow_preserve (struct scratch_buffer *buffer)
|
||||
{
|
||||
size_t new_length = 2 * buffer->length;
|
||||
void *new_ptr;
|
||||
|
||||
if (buffer->data == buffer->__space.__c)
|
||||
{
|
||||
/* Move buffer to the heap. No overflow is possible because
|
||||
buffer->length describes a small buffer on the stack. */
|
||||
new_ptr = malloc (new_length);
|
||||
if (new_ptr == NULL)
|
||||
return false;
|
||||
memcpy (new_ptr, buffer->__space.__c, buffer->length);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Buffer was already on the heap. Check for overflow. */
|
||||
if (__glibc_likely (new_length >= buffer->length))
|
||||
new_ptr = realloc (buffer->data, new_length);
|
||||
else
|
||||
{
|
||||
__set_errno (ENOMEM);
|
||||
new_ptr = NULL;
|
||||
}
|
||||
|
||||
if (__glibc_unlikely (new_ptr == NULL))
|
||||
{
|
||||
/* Deallocate, but buffer must remain valid to free. */
|
||||
free (buffer->data);
|
||||
scratch_buffer_init (buffer);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Install new heap-based buffer. */
|
||||
buffer->data = new_ptr;
|
||||
buffer->length = new_length;
|
||||
return true;
|
||||
}
|
||||
libc_hidden_def (__libc_scratch_buffer_grow_preserve)
|
||||
@@ -1,64 +0,0 @@
|
||||
/* Variable-sized buffer with on-stack default allocation.
|
||||
Copyright (C) 2015-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _LIBC
|
||||
# include <libc-config.h>
|
||||
#endif
|
||||
|
||||
#include <scratch_buffer.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
bool
|
||||
__libc_scratch_buffer_set_array_size (struct scratch_buffer *buffer,
|
||||
size_t nelem, size_t size)
|
||||
{
|
||||
size_t new_length = nelem * size;
|
||||
|
||||
/* Avoid overflow check if both values are small. */
|
||||
if ((nelem | size) >> (sizeof (size_t) * CHAR_BIT / 2) != 0
|
||||
&& nelem != 0 && size != new_length / nelem)
|
||||
{
|
||||
/* Overflow. Discard the old buffer, but it must remain valid
|
||||
to free. */
|
||||
scratch_buffer_free (buffer);
|
||||
scratch_buffer_init (buffer);
|
||||
__set_errno (ENOMEM);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (new_length <= buffer->length)
|
||||
return true;
|
||||
|
||||
/* Discard old buffer. */
|
||||
scratch_buffer_free (buffer);
|
||||
|
||||
char *new_ptr = malloc (new_length);
|
||||
if (new_ptr == NULL)
|
||||
{
|
||||
/* Buffer must remain valid to free. */
|
||||
scratch_buffer_init (buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Install new heap-based buffer. */
|
||||
buffer->data = new_ptr;
|
||||
buffer->length = new_length;
|
||||
return true;
|
||||
}
|
||||
libc_hidden_def (__libc_scratch_buffer_set_array_size)
|
||||
@@ -1,126 +0,0 @@
|
||||
/* Safe automatic memory allocation.
|
||||
Copyright (C) 2003-2007, 2009-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _MALLOCA_H
|
||||
#define _MALLOCA_H
|
||||
|
||||
#include <alloca.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "xalloc-oversized.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* safe_alloca(N) is equivalent to alloca(N) when it is safe to call
|
||||
alloca(N); otherwise it returns NULL. It either returns N bytes of
|
||||
memory allocated on the stack, that lasts until the function returns,
|
||||
or NULL.
|
||||
Use of safe_alloca should be avoided:
|
||||
- inside arguments of function calls - undefined behaviour,
|
||||
- in inline functions - the allocation may actually last until the
|
||||
calling function returns.
|
||||
*/
|
||||
#if HAVE_ALLOCA
|
||||
/* The OS usually guarantees only one guard page at the bottom of the stack,
|
||||
and a page size can be as small as 4096 bytes. So we cannot safely
|
||||
allocate anything larger than 4096 bytes. Also care for the possibility
|
||||
of a few compiler-allocated temporary stack slots.
|
||||
This must be a macro, not a function. */
|
||||
# define safe_alloca(N) ((N) < 4032 ? alloca (N) : NULL)
|
||||
#else
|
||||
# define safe_alloca(N) ((void) (N), NULL)
|
||||
#endif
|
||||
|
||||
/* Free a block of memory allocated through malloca(). */
|
||||
#if HAVE_ALLOCA
|
||||
extern void freea (void *p);
|
||||
#else
|
||||
# define freea free
|
||||
#endif
|
||||
|
||||
/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of
|
||||
memory allocated on the stack, that must be freed using freea() before
|
||||
the function returns. Upon failure, it returns NULL. */
|
||||
#if HAVE_ALLOCA
|
||||
# define malloca(N) \
|
||||
((N) < 4032 - (2 * sa_alignment_max - 1) \
|
||||
? (void *) (((uintptr_t) (char *) alloca ((N) + 2 * sa_alignment_max - 1) \
|
||||
+ (2 * sa_alignment_max - 1)) \
|
||||
& ~(uintptr_t)(2 * sa_alignment_max - 1)) \
|
||||
: mmalloca (N))
|
||||
#else
|
||||
# define malloca(N) \
|
||||
mmalloca (N)
|
||||
#endif
|
||||
extern void *mmalloca (size_t n)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (freea, 1)
|
||||
_GL_ATTRIBUTE_ALLOC_SIZE ((1));
|
||||
|
||||
/* nmalloca(N,S) is an overflow-safe variant of malloca (N * S).
|
||||
It allocates an array of N objects, each with S bytes of memory,
|
||||
on the stack. N and S should be nonnegative and free of side effects.
|
||||
The array must be freed using freea() before the function returns. */
|
||||
#define nmalloca(n, s) \
|
||||
(xalloc_oversized (n, s) ? NULL : malloca ((n) * (size_t) (s)))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* ------------------- Auxiliary, non-public definitions ------------------- */
|
||||
|
||||
/* Determine the alignment of a type at compile time. */
|
||||
#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
|
||||
# define sa_alignof __alignof__
|
||||
#elif defined __cplusplus
|
||||
template <class type> struct sa_alignof_helper { char __slot1; type __slot2; };
|
||||
# define sa_alignof(type) offsetof (sa_alignof_helper<type>, __slot2)
|
||||
#elif defined __hpux
|
||||
/* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
|
||||
values. */
|
||||
# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
|
||||
#elif defined _AIX
|
||||
/* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
|
||||
values. */
|
||||
# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
|
||||
#else
|
||||
# define sa_alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
/* The desired alignment of memory allocations is the maximum alignment
|
||||
among all elementary types. */
|
||||
sa_alignment_long = sa_alignof (long),
|
||||
sa_alignment_double = sa_alignof (double),
|
||||
sa_alignment_longlong = sa_alignof (long long),
|
||||
sa_alignment_longdouble = sa_alignof (long double),
|
||||
sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
|
||||
| (sa_alignment_longlong - 1)
|
||||
| (sa_alignment_longdouble - 1)
|
||||
) + 1
|
||||
};
|
||||
|
||||
#endif /* _MALLOCA_H */
|
||||
@@ -1,33 +0,0 @@
|
||||
/* Copy memory area and return pointer after last written byte.
|
||||
Copyright (C) 2003, 2007, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <string.h>
|
||||
|
||||
/* A function definition is only needed if HAVE_MEMPCPY is not defined. */
|
||||
#if !HAVE_MEMPCPY
|
||||
|
||||
/* Copy N bytes of SRC to DEST, return pointer to bytes after the
|
||||
last written byte. */
|
||||
void *
|
||||
mempcpy (void *dest, const void *src, size_t n)
|
||||
{
|
||||
return (char *) memcpy (dest, src, n) + n;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,60 +0,0 @@
|
||||
/* MIN, MAX macros.
|
||||
Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009-2022 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _MINMAX_H
|
||||
#define _MINMAX_H
|
||||
|
||||
/* Note: MIN, MAX are also defined in <sys/param.h> on some systems
|
||||
(glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about
|
||||
MIN, MAX macro redefinitions on some systems; the workaround is to
|
||||
#include this file as the last one among the #include list. */
|
||||
|
||||
/* Before we define the following symbols we get the <limits.h> file
|
||||
since otherwise we get redefinitions on some systems if <limits.h> is
|
||||
included after this file. Likewise for <sys/param.h>.
|
||||
If more than one of these system headers define MIN and MAX, pick just
|
||||
one of the headers (because the definitions most likely are the same). */
|
||||
#if HAVE_MINMAX_IN_LIMITS_H
|
||||
# include <limits.h>
|
||||
#elif HAVE_MINMAX_IN_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
/* Note: MIN and MAX should be used with two arguments of the
|
||||
same type. They might not return the minimum and maximum of their two
|
||||
arguments, if the arguments have different types or have unusual
|
||||
floating-point values. For example, on a typical host with 32-bit 'int',
|
||||
64-bit 'long long', and 64-bit IEEE 754 'double' types:
|
||||
|
||||
MAX (-1, 2147483648) returns 4294967295.
|
||||
MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0.
|
||||
MAX (NaN, 0.0) returns 0.0.
|
||||
MAX (+0.0, -0.0) returns -0.0.
|
||||
|
||||
and in each case the answer is in some sense bogus. */
|
||||
|
||||
/* MAX(a,b) returns the maximum of A and B. */
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/* MIN(a,b) returns the minimum of A and B. */
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#endif /* _MINMAX_H */
|
||||
@@ -1,129 +0,0 @@
|
||||
/* Invalid parameter handler for MSVC runtime libraries.
|
||||
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "msvc-inval.h"
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
|
||||
&& !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
|
||||
|
||||
/* Get _invalid_parameter_handler type and _set_invalid_parameter_handler
|
||||
declaration. */
|
||||
# include <stdlib.h>
|
||||
|
||||
# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
|
||||
|
||||
static void __cdecl
|
||||
gl_msvc_invalid_parameter_handler (const wchar_t *expression,
|
||||
const wchar_t *function,
|
||||
const wchar_t *file,
|
||||
unsigned int line,
|
||||
uintptr_t dummy)
|
||||
{
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
|
||||
# if defined _MSC_VER
|
||||
|
||||
static void __cdecl
|
||||
gl_msvc_invalid_parameter_handler (const wchar_t *expression,
|
||||
const wchar_t *function,
|
||||
const wchar_t *file,
|
||||
unsigned int line,
|
||||
uintptr_t dummy)
|
||||
{
|
||||
RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
/* An index to thread-local storage. */
|
||||
static DWORD tls_index;
|
||||
static int tls_initialized /* = 0 */;
|
||||
|
||||
/* Used as a fallback only. */
|
||||
static struct gl_msvc_inval_per_thread not_per_thread;
|
||||
|
||||
struct gl_msvc_inval_per_thread *
|
||||
gl_msvc_inval_current (void)
|
||||
{
|
||||
if (!tls_initialized)
|
||||
{
|
||||
tls_index = TlsAlloc ();
|
||||
tls_initialized = 1;
|
||||
}
|
||||
if (tls_index == TLS_OUT_OF_INDEXES)
|
||||
/* TlsAlloc had failed. */
|
||||
return ¬_per_thread;
|
||||
else
|
||||
{
|
||||
struct gl_msvc_inval_per_thread *pointer =
|
||||
(struct gl_msvc_inval_per_thread *) TlsGetValue (tls_index);
|
||||
if (pointer == NULL)
|
||||
{
|
||||
/* First call. Allocate a new 'struct gl_msvc_inval_per_thread'. */
|
||||
pointer =
|
||||
(struct gl_msvc_inval_per_thread *)
|
||||
malloc (sizeof (struct gl_msvc_inval_per_thread));
|
||||
if (pointer == NULL)
|
||||
/* Could not allocate memory. Use the global storage. */
|
||||
pointer = ¬_per_thread;
|
||||
TlsSetValue (tls_index, pointer);
|
||||
}
|
||||
return pointer;
|
||||
}
|
||||
}
|
||||
|
||||
static void __cdecl
|
||||
gl_msvc_invalid_parameter_handler (const wchar_t *expression,
|
||||
const wchar_t *function,
|
||||
const wchar_t *file,
|
||||
unsigned int line,
|
||||
uintptr_t dummy)
|
||||
{
|
||||
struct gl_msvc_inval_per_thread *current = gl_msvc_inval_current ();
|
||||
if (current->restart_valid)
|
||||
longjmp (current->restart, 1);
|
||||
else
|
||||
/* An invalid parameter notification from outside the gnulib code.
|
||||
Give the caller a chance to intervene. */
|
||||
RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
static int gl_msvc_inval_initialized /* = 0 */;
|
||||
|
||||
void
|
||||
gl_msvc_inval_ensure_handler (void)
|
||||
{
|
||||
if (gl_msvc_inval_initialized == 0)
|
||||
{
|
||||
_set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
|
||||
gl_msvc_inval_initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,222 +0,0 @@
|
||||
/* Invalid parameter handler for MSVC runtime libraries.
|
||||
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _MSVC_INVAL_H
|
||||
#define _MSVC_INVAL_H
|
||||
|
||||
/* With MSVC runtime libraries with the "invalid parameter handler" concept,
|
||||
functions like fprintf(), dup2(), or close() crash when the caller passes
|
||||
an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
|
||||
instead.
|
||||
This file defines macros that turn such an invalid parameter notification
|
||||
into a non-local exit. An error code can then be produced at the target
|
||||
of this exit. You can thus write code like
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
<Code that can trigger an invalid parameter notification
|
||||
but does not do 'return', 'break', 'continue', nor 'goto'.>
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
<Code that handles an invalid parameter notification
|
||||
but does not do 'return', 'break', 'continue', nor 'goto'.>
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
This entire block expands to a single statement.
|
||||
|
||||
The handling of invalid parameters can be done in three ways:
|
||||
|
||||
* The default way, which is reasonable for programs (not libraries):
|
||||
AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [DEFAULT_HANDLING])
|
||||
|
||||
* The way for libraries that make "hairy" calls (like close(-1), or
|
||||
fclose(fp) where fileno(fp) is closed, or simply getdtablesize()):
|
||||
AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [HAIRY_LIBRARY_HANDLING])
|
||||
|
||||
* The way for libraries that make no "hairy" calls:
|
||||
AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [SANE_LIBRARY_HANDLING])
|
||||
*/
|
||||
|
||||
#define DEFAULT_HANDLING 0
|
||||
#define HAIRY_LIBRARY_HANDLING 1
|
||||
#define SANE_LIBRARY_HANDLING 2
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
|
||||
&& !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
|
||||
/* A native Windows platform with the "invalid parameter handler" concept,
|
||||
and either DEFAULT_HANDLING or HAIRY_LIBRARY_HANDLING. */
|
||||
|
||||
# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
|
||||
/* Default handling. */
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/* Ensure that the invalid parameter handler in installed that just returns.
|
||||
Because we assume no other part of the program installs a different
|
||||
invalid parameter handler, this solution is multithread-safe. */
|
||||
extern void gl_msvc_inval_ensure_handler (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
gl_msvc_inval_ensure_handler (); \
|
||||
if (1)
|
||||
# define CATCH_MSVC_INVAL \
|
||||
else
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# else
|
||||
/* Handling for hairy libraries. */
|
||||
|
||||
# include <excpt.h>
|
||||
|
||||
/* Gnulib can define its own status codes, as described in the page
|
||||
"Raising Software Exceptions" on microsoft.com
|
||||
<https://docs.microsoft.com/en-us/cpp/cpp/raising-software-exceptions>.
|
||||
Our status codes are composed of
|
||||
- 0xE0000000, mandatory for all user-defined status codes,
|
||||
- 0x474E550, a API identifier ("GNU"),
|
||||
- 0, 1, 2, ..., used to distinguish different status codes from the
|
||||
same API. */
|
||||
# define STATUS_GNULIB_INVALID_PARAMETER (0xE0000000 + 0x474E550 + 0)
|
||||
|
||||
# if defined _MSC_VER
|
||||
/* A compiler that supports __try/__except, as described in the page
|
||||
"try-except statement" on microsoft.com
|
||||
<https://docs.microsoft.com/en-us/cpp/cpp/try-except-statement>.
|
||||
With __try/__except, we can use the multithread-safe exception handling. */
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/* Ensure that the invalid parameter handler in installed that raises a
|
||||
software exception with code STATUS_GNULIB_INVALID_PARAMETER.
|
||||
Because we assume no other part of the program installs a different
|
||||
invalid parameter handler, this solution is multithread-safe. */
|
||||
extern void gl_msvc_inval_ensure_handler (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
gl_msvc_inval_ensure_handler (); \
|
||||
__try
|
||||
# define CATCH_MSVC_INVAL \
|
||||
__except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER \
|
||||
? EXCEPTION_EXECUTE_HANDLER \
|
||||
: EXCEPTION_CONTINUE_SEARCH)
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# else
|
||||
/* Any compiler.
|
||||
We can only use setjmp/longjmp. */
|
||||
|
||||
# include <setjmp.h>
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
struct gl_msvc_inval_per_thread
|
||||
{
|
||||
/* The restart that will resume execution at the code between
|
||||
CATCH_MSVC_INVAL and DONE_MSVC_INVAL. It is enabled only between
|
||||
TRY_MSVC_INVAL and CATCH_MSVC_INVAL. */
|
||||
jmp_buf restart;
|
||||
|
||||
/* Tells whether the contents of restart is valid. */
|
||||
int restart_valid;
|
||||
};
|
||||
|
||||
/* Ensure that the invalid parameter handler in installed that passes
|
||||
control to the gl_msvc_inval_restart if it is valid, or raises a
|
||||
software exception with code STATUS_GNULIB_INVALID_PARAMETER otherwise.
|
||||
Because we assume no other part of the program installs a different
|
||||
invalid parameter handler, this solution is multithread-safe. */
|
||||
extern void gl_msvc_inval_ensure_handler (void);
|
||||
|
||||
/* Return a pointer to the per-thread data for the current thread. */
|
||||
extern struct gl_msvc_inval_per_thread *gl_msvc_inval_current (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
struct gl_msvc_inval_per_thread *msvc_inval_current; \
|
||||
gl_msvc_inval_ensure_handler (); \
|
||||
msvc_inval_current = gl_msvc_inval_current (); \
|
||||
/* First, initialize gl_msvc_inval_restart. */ \
|
||||
if (setjmp (msvc_inval_current->restart) == 0) \
|
||||
{ \
|
||||
/* Then, mark it as valid. */ \
|
||||
msvc_inval_current->restart_valid = 1;
|
||||
# define CATCH_MSVC_INVAL \
|
||||
/* Execution completed. \
|
||||
Mark gl_msvc_inval_restart as invalid. */ \
|
||||
msvc_inval_current->restart_valid = 0; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Execution triggered an invalid parameter notification. \
|
||||
Mark gl_msvc_inval_restart as invalid. */ \
|
||||
msvc_inval_current->restart_valid = 0;
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
#else
|
||||
/* A platform that does not need to the invalid parameter handler,
|
||||
or when SANE_LIBRARY_HANDLING is desired. */
|
||||
|
||||
/* The braces here avoid GCC warnings like
|
||||
"warning: suggest explicit braces to avoid ambiguous 'else'". */
|
||||
# define TRY_MSVC_INVAL \
|
||||
do \
|
||||
{ \
|
||||
if (1)
|
||||
# define CATCH_MSVC_INVAL \
|
||||
else
|
||||
# define DONE_MSVC_INVAL \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _MSVC_INVAL_H */
|
||||
@@ -1,51 +0,0 @@
|
||||
/* Wrappers that don't throw invalid parameter notifications
|
||||
with MSVC runtime libraries.
|
||||
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "msvc-nothrow.h"
|
||||
|
||||
/* Get declarations of the native Windows API functions. */
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
# include "msvc-inval.h"
|
||||
#endif
|
||||
|
||||
#undef _get_osfhandle
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
intptr_t
|
||||
_gl_nothrow_get_osfhandle (int fd)
|
||||
{
|
||||
intptr_t result;
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = _get_osfhandle (fd);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
result = (intptr_t) INVALID_HANDLE_VALUE;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -1,43 +0,0 @@
|
||||
/* Wrappers that don't throw invalid parameter notifications
|
||||
with MSVC runtime libraries.
|
||||
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _MSVC_NOTHROW_H
|
||||
#define _MSVC_NOTHROW_H
|
||||
|
||||
/* With MSVC runtime libraries with the "invalid parameter handler" concept,
|
||||
functions like fprintf(), dup2(), or close() crash when the caller passes
|
||||
an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
|
||||
instead.
|
||||
This file defines wrappers that turn such an invalid parameter notification
|
||||
into an error code. */
|
||||
|
||||
#if defined _WIN32 && ! defined __CYGWIN__
|
||||
|
||||
/* Get original declaration of _get_osfhandle. */
|
||||
# include <io.h>
|
||||
|
||||
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
|
||||
/* Override _get_osfhandle. */
|
||||
extern intptr_t _gl_nothrow_get_osfhandle (int fd);
|
||||
# define _get_osfhandle _gl_nothrow_get_osfhandle
|
||||
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _MSVC_NOTHROW_H */
|
||||
@@ -1,209 +0,0 @@
|
||||
/* Open a descriptor to a file.
|
||||
Copyright (C) 2007-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
|
||||
|
||||
/* If the user's config.h happens to include <fcntl.h>, let it include only
|
||||
the system's <fcntl.h> here, so that orig_open doesn't recurse to
|
||||
rpl_open. */
|
||||
#define __need_system_fcntl_h
|
||||
#include <config.h>
|
||||
|
||||
/* Get the original definition of open. It might be defined as a macro. */
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#undef __need_system_fcntl_h
|
||||
|
||||
static int
|
||||
orig_open (const char *filename, int flags, mode_t mode)
|
||||
{
|
||||
#if defined _WIN32 && !defined __CYGWIN__
|
||||
return _open (filename, flags, mode);
|
||||
#else
|
||||
return open (filename, flags, mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Specification. */
|
||||
/* Write "fcntl.h" here, not <fcntl.h>, otherwise OSF/1 5.1 DTK cc eliminates
|
||||
this include because of the preliminary #include <fcntl.h> above. */
|
||||
#include "fcntl.h"
|
||||
|
||||
#include "cloexec.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef REPLACE_OPEN_DIRECTORY
|
||||
# define REPLACE_OPEN_DIRECTORY 0
|
||||
#endif
|
||||
|
||||
int
|
||||
open (const char *filename, int flags, ...)
|
||||
{
|
||||
/* 0 = unknown, 1 = yes, -1 = no. */
|
||||
#if GNULIB_defined_O_CLOEXEC
|
||||
int have_cloexec = -1;
|
||||
#else
|
||||
static int have_cloexec;
|
||||
#endif
|
||||
|
||||
mode_t mode;
|
||||
int fd;
|
||||
|
||||
mode = 0;
|
||||
if (flags & O_CREAT)
|
||||
{
|
||||
va_list arg;
|
||||
va_start (arg, flags);
|
||||
|
||||
/* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4
|
||||
creates crashing code when 'mode_t' is smaller than 'int'. */
|
||||
mode = va_arg (arg, PROMOTED_MODE_T);
|
||||
|
||||
va_end (arg);
|
||||
}
|
||||
|
||||
#if GNULIB_defined_O_NONBLOCK
|
||||
/* The only known platform that lacks O_NONBLOCK is mingw, but it
|
||||
also lacks named pipes and Unix sockets, which are the only two
|
||||
file types that require non-blocking handling in open().
|
||||
Therefore, it is safe to ignore O_NONBLOCK here. It is handy
|
||||
that mingw also lacks openat(), so that is also covered here. */
|
||||
flags &= ~O_NONBLOCK;
|
||||
#endif
|
||||
|
||||
#if defined _WIN32 && ! defined __CYGWIN__
|
||||
if (strcmp (filename, "/dev/null") == 0)
|
||||
filename = "NUL";
|
||||
#endif
|
||||
|
||||
#if OPEN_TRAILING_SLASH_BUG
|
||||
/* Fail if one of O_CREAT, O_WRONLY, O_RDWR is specified and the filename
|
||||
ends in a slash, as POSIX says such a filename must name a directory
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
|
||||
"A pathname that contains at least one non-<slash> character and that
|
||||
ends with one or more trailing <slash> characters shall not be resolved
|
||||
successfully unless the last pathname component before the trailing
|
||||
<slash> characters names an existing directory"
|
||||
If the named file already exists as a directory, then
|
||||
- if O_CREAT is specified, open() must fail because of the semantics
|
||||
of O_CREAT,
|
||||
- if O_WRONLY or O_RDWR is specified, open() must fail because POSIX
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html>
|
||||
says that it fails with errno = EISDIR in this case.
|
||||
If the named file does not exist or does not name a directory, then
|
||||
- if O_CREAT is specified, open() must fail since open() cannot create
|
||||
directories,
|
||||
- if O_WRONLY or O_RDWR is specified, open() must fail because the
|
||||
file does not contain a '.' directory. */
|
||||
if ((flags & O_CREAT)
|
||||
|| (flags & O_ACCMODE) == O_RDWR
|
||||
|| (flags & O_ACCMODE) == O_WRONLY)
|
||||
{
|
||||
size_t len = strlen (filename);
|
||||
if (len > 0 && filename[len - 1] == '/')
|
||||
{
|
||||
errno = EISDIR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
fd = orig_open (filename,
|
||||
flags & ~(have_cloexec < 0 ? O_CLOEXEC : 0), mode);
|
||||
|
||||
if (flags & O_CLOEXEC)
|
||||
{
|
||||
if (! have_cloexec)
|
||||
{
|
||||
if (0 <= fd)
|
||||
have_cloexec = 1;
|
||||
else if (errno == EINVAL)
|
||||
{
|
||||
fd = orig_open (filename, flags & ~O_CLOEXEC, mode);
|
||||
have_cloexec = -1;
|
||||
}
|
||||
}
|
||||
if (have_cloexec < 0 && 0 <= fd)
|
||||
set_cloexec_flag (fd, true);
|
||||
}
|
||||
|
||||
|
||||
#if REPLACE_FCHDIR
|
||||
/* Implementing fchdir and fdopendir requires the ability to open a
|
||||
directory file descriptor. If open doesn't support that (as on
|
||||
mingw), we use a dummy file that behaves the same as directories
|
||||
on Linux (ie. always reports EOF on attempts to read()), and
|
||||
override fstat() in fchdir.c to hide the fact that we have a
|
||||
dummy. */
|
||||
if (REPLACE_OPEN_DIRECTORY && fd < 0 && errno == EACCES
|
||||
&& ((flags & O_ACCMODE) == O_RDONLY
|
||||
|| (O_SEARCH != O_RDONLY && (flags & O_ACCMODE) == O_SEARCH)))
|
||||
{
|
||||
struct stat statbuf;
|
||||
if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
|
||||
{
|
||||
/* Maximum recursion depth of 1. */
|
||||
fd = open ("/dev/null", flags, mode);
|
||||
if (0 <= fd)
|
||||
fd = _gl_register_fd (fd, filename);
|
||||
}
|
||||
else
|
||||
errno = EACCES;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPEN_TRAILING_SLASH_BUG
|
||||
/* If the filename ends in a slash and fd does not refer to a directory,
|
||||
then fail.
|
||||
Rationale: POSIX says such a filename must name a directory
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
|
||||
"A pathname that contains at least one non-<slash> character and that
|
||||
ends with one or more trailing <slash> characters shall not be resolved
|
||||
successfully unless the last pathname component before the trailing
|
||||
<slash> characters names an existing directory"
|
||||
If the named file without the slash is not a directory, open() must fail
|
||||
with ENOTDIR. */
|
||||
if (fd >= 0)
|
||||
{
|
||||
/* We know len is positive, since open did not fail with ENOENT. */
|
||||
size_t len = strlen (filename);
|
||||
if (filename[len - 1] == '/')
|
||||
{
|
||||
struct stat statbuf;
|
||||
|
||||
if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
|
||||
{
|
||||
close (fd);
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if REPLACE_FCHDIR
|
||||
if (!REPLACE_OPEN_DIRECTORY && 0 <= fd)
|
||||
fd = _gl_register_fd (fd, filename);
|
||||
#endif
|
||||
|
||||
return fd;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/* Define PATH_MAX somehow. Requires sys/types.h.
|
||||
Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2022 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _PATHMAX_H
|
||||
# define _PATHMAX_H
|
||||
|
||||
/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename,
|
||||
including the terminating NUL byte.
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
|
||||
PATH_MAX is not defined on systems which have no limit on filename length,
|
||||
such as GNU/Hurd.
|
||||
|
||||
This file does *not* define PATH_MAX always. Programs that use this file
|
||||
can handle the GNU/Hurd case in several ways:
|
||||
- Either with a package-wide handling, or with a per-file handling,
|
||||
- Either through a
|
||||
#ifdef PATH_MAX
|
||||
or through a fallback like
|
||||
#ifndef PATH_MAX
|
||||
# define PATH_MAX 8192
|
||||
#endif
|
||||
or through a fallback like
|
||||
#ifndef PATH_MAX
|
||||
# define PATH_MAX pathconf ("/", _PC_PATH_MAX)
|
||||
#endif
|
||||
*/
|
||||
|
||||
# include <unistd.h>
|
||||
|
||||
# include <limits.h>
|
||||
|
||||
# ifndef _POSIX_PATH_MAX
|
||||
# define _POSIX_PATH_MAX 256
|
||||
# endif
|
||||
|
||||
/* Don't include sys/param.h if it already has been. */
|
||||
# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
|
||||
# include <sys/param.h>
|
||||
# endif
|
||||
|
||||
# if !defined PATH_MAX && defined MAXPATHLEN
|
||||
# define PATH_MAX MAXPATHLEN
|
||||
# endif
|
||||
|
||||
# ifdef __hpux
|
||||
/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename,
|
||||
*not* including the terminating NUL byte, and is set to 1023.
|
||||
Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is
|
||||
not defined at all any more. */
|
||||
# undef PATH_MAX
|
||||
# define PATH_MAX 1024
|
||||
# endif
|
||||
|
||||
# if defined _WIN32 && ! defined __CYGWIN__
|
||||
/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com,
|
||||
section "Maximum Path Length Limitation",
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation>
|
||||
explains that the maximum size of a filename, including the terminating
|
||||
NUL byte, is 260 = 3 + 256 + 1.
|
||||
This is the same value as
|
||||
- FILENAME_MAX in <stdio.h>,
|
||||
- _MAX_PATH in <stdlib.h>,
|
||||
- MAX_PATH in <windef.h>.
|
||||
Undefine the original value, because mingw's <limits.h> gets it wrong. */
|
||||
# undef PATH_MAX
|
||||
# define PATH_MAX 260
|
||||
# endif
|
||||
|
||||
#endif /* _PATHMAX_H */
|
||||
@@ -1,62 +0,0 @@
|
||||
/* Program name management.
|
||||
Copyright (C) 2001-2004, 2006, 2009-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2001.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _PROGNAME_H
|
||||
#define _PROGNAME_H
|
||||
|
||||
/* Programs using this file should do the following in main():
|
||||
set_program_name (argv[0]);
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* String containing name the program is called with. */
|
||||
extern DLL_VARIABLE const char *program_name;
|
||||
|
||||
/* Set program_name, based on argv[0].
|
||||
argv0 must be a string allocated with indefinite extent, and must not be
|
||||
modified after this call. */
|
||||
extern void set_program_name (const char *argv0);
|
||||
|
||||
#if ENABLE_RELOCATABLE
|
||||
|
||||
/* Set program_name, based on argv[0], and original installation prefix and
|
||||
directory, for relocatability. */
|
||||
extern void set_program_name_and_installdir (const char *argv0,
|
||||
const char *orig_installprefix,
|
||||
const char *orig_installdir);
|
||||
#undef set_program_name
|
||||
#define set_program_name(ARG0) \
|
||||
set_program_name_and_installdir (ARG0, INSTALLPREFIX, INSTALLDIR)
|
||||
|
||||
/* Return the full pathname of the current executable, based on the earlier
|
||||
call to set_program_name_and_installdir. Return NULL if unknown. */
|
||||
extern char *get_full_program_name (void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _PROGNAME_H */
|
||||
@@ -1,511 +0,0 @@
|
||||
/* Provide relocatable programs.
|
||||
Copyright (C) 2003-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
#define _GL_USE_STDLIB_ALLOC 1
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "progname.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* Get declaration of _NSGetExecutablePath on Mac OS X 10.2 or newer. */
|
||||
#if HAVE_MACH_O_DYLD_H
|
||||
# include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
#if defined _WIN32 && !defined __CYGWIN__
|
||||
# define WINDOWS_NATIVE
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_NATIVE
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef __EMX__
|
||||
# define INCL_DOS
|
||||
# include <os2.h>
|
||||
#endif
|
||||
|
||||
#include "relocatable.h"
|
||||
|
||||
#ifdef NO_XMALLOC
|
||||
# include "areadlink.h"
|
||||
# define xreadlink areadlink
|
||||
#else
|
||||
# include "xreadlink.h"
|
||||
#endif
|
||||
|
||||
#ifdef NO_XMALLOC
|
||||
# define xmalloc malloc
|
||||
# define xstrdup strdup
|
||||
#else
|
||||
# include "xalloc.h"
|
||||
#endif
|
||||
|
||||
#ifndef O_EXEC
|
||||
# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
|
||||
#endif
|
||||
|
||||
#if defined IN_RELOCWRAPPER && (!defined O_CLOEXEC || GNULIB_defined_O_CLOEXEC)
|
||||
# undef O_CLOEXEC
|
||||
# define O_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
/* Declare canonicalize_file_name.
|
||||
The <stdlib.h> included above may be the system's one, not the gnulib
|
||||
one. */
|
||||
extern char * canonicalize_file_name (const char *name);
|
||||
|
||||
#if defined WINDOWS_NATIVE
|
||||
/* Don't assume that UNICODE is not defined. */
|
||||
# undef GetModuleFileName
|
||||
# define GetModuleFileName GetModuleFileNameA
|
||||
#endif
|
||||
|
||||
/* Pathname support.
|
||||
ISSLASH(C) tests whether C is a directory separator character.
|
||||
IS_FILE_NAME_WITH_DIR(P) tests whether P contains a directory specification.
|
||||
*/
|
||||
#if (defined _WIN32 && !defined __CYGWIN__) || defined __EMX__ || defined __DJGPP__
|
||||
/* Native Windows, OS/2, DOS */
|
||||
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
|
||||
# define HAS_DEVICE(P) \
|
||||
((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
|
||||
&& (P)[1] == ':')
|
||||
# define IS_FILE_NAME_WITH_DIR(P) \
|
||||
(strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
|
||||
# define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
|
||||
#else
|
||||
/* Unix */
|
||||
# define ISSLASH(C) ((C) == '/')
|
||||
# define IS_FILE_NAME_WITH_DIR(P) (strchr (P, '/') != NULL)
|
||||
# define FILE_SYSTEM_PREFIX_LEN(P) 0
|
||||
#endif
|
||||
|
||||
/* Use the system functions, not the gnulib overrides in this file. */
|
||||
#undef sprintf
|
||||
|
||||
#undef set_program_name
|
||||
|
||||
|
||||
#if ENABLE_RELOCATABLE
|
||||
|
||||
#ifdef __sun
|
||||
|
||||
/* Helper function, from gnulib module 'safe-read'. */
|
||||
static size_t
|
||||
safe_read (int fd, void *buf, size_t count)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
ssize_t result = read (fd, buf, count);
|
||||
|
||||
if (0 <= result || errno != EINTR)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/* Helper function, from gnulib module 'full-read'. */
|
||||
static size_t
|
||||
full_read (int fd, void *buf, size_t count)
|
||||
{
|
||||
size_t total = 0;
|
||||
const char *ptr = (const char *) buf;
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
size_t n = safe_read (fd, ptr, count);
|
||||
if (n == (size_t) -1)
|
||||
break;
|
||||
if (n == 0)
|
||||
{
|
||||
errno = 0;
|
||||
break;
|
||||
}
|
||||
total += n;
|
||||
ptr += n;
|
||||
count -= n;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined __linux__ || defined __CYGWIN__
|
||||
/* File descriptor of the executable.
|
||||
(Only used to verify that we find the correct executable.) */
|
||||
static int executable_fd = -1;
|
||||
#endif
|
||||
|
||||
/* Define this function only when it's needed. */
|
||||
#if !(defined WINDOWS_NATIVE || defined __EMX__)
|
||||
|
||||
/* Tests whether a given filename may belong to the executable. */
|
||||
static bool
|
||||
maybe_executable (const char *filename)
|
||||
{
|
||||
/* The native Windows API lacks the access() function. */
|
||||
# if !defined WINDOWS_NATIVE
|
||||
if (access (filename, X_OK) < 0)
|
||||
return false;
|
||||
# endif
|
||||
|
||||
# if defined __linux__ || defined __CYGWIN__
|
||||
if (executable_fd >= 0)
|
||||
{
|
||||
/* If we already have an executable_fd, check that filename points to
|
||||
the same inode. */
|
||||
struct stat statexe;
|
||||
struct stat statfile;
|
||||
|
||||
if (fstat (executable_fd, &statexe) >= 0)
|
||||
return (stat (filename, &statfile) >= 0
|
||||
&& statfile.st_dev
|
||||
&& statfile.st_dev == statexe.st_dev
|
||||
&& statfile.st_ino == statexe.st_ino);
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Check that the filename does not point to a directory. */
|
||||
{
|
||||
struct stat statfile;
|
||||
|
||||
return (stat (filename, &statfile) >= 0
|
||||
&& ! S_ISDIR (statfile.st_mode));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Determine the full pathname of the current executable, freshly allocated.
|
||||
Return NULL if unknown.
|
||||
Guaranteed to work on Linux and native Windows. Likely to work on the
|
||||
other Unixes (maybe except BeOS), under most conditions. */
|
||||
static char *
|
||||
find_executable (const char *argv0)
|
||||
{
|
||||
#if defined WINDOWS_NATIVE
|
||||
/* Native Windows only.
|
||||
On Cygwin, it is better to use the Cygwin provided /proc interface, than
|
||||
to use native Windows API and cygwin_conv_to_posix_path, because it
|
||||
supports longer file names
|
||||
(see <https://cygwin.com/ml/cygwin/2011-01/msg00410.html>). */
|
||||
char location[MAX_PATH];
|
||||
int length = GetModuleFileName (NULL, location, sizeof (location));
|
||||
if (length < 0)
|
||||
return NULL;
|
||||
if (!IS_FILE_NAME_WITH_DIR (location))
|
||||
/* Shouldn't happen. */
|
||||
return NULL;
|
||||
return xstrdup (location);
|
||||
#elif defined __EMX__
|
||||
PPIB ppib;
|
||||
char location[CCHMAXPATH];
|
||||
|
||||
/* See http://cyberkinetica.homeunix.net/os2tk45/cp1/619_L2H_DosGetInfoBlocksSynt.html
|
||||
for specification of DosGetInfoBlocks(). */
|
||||
if (DosGetInfoBlocks (NULL, &ppib))
|
||||
return NULL;
|
||||
|
||||
/* See http://cyberkinetica.homeunix.net/os2tk45/cp1/1247_L2H_DosQueryModuleNameSy.html
|
||||
for specification of DosQueryModuleName(). */
|
||||
if (DosQueryModuleName (ppib->pib_hmte, sizeof (location), location))
|
||||
return NULL;
|
||||
|
||||
_fnslashify (location);
|
||||
|
||||
return xstrdup (location);
|
||||
#else /* Unix */
|
||||
# if defined __linux__
|
||||
/* The executable is accessible as /proc/<pid>/exe. In newer Linux
|
||||
versions, also as /proc/self/exe. Linux >= 2.1 provides a symlink
|
||||
to the true pathname; older Linux versions give only device and ino,
|
||||
enclosed in brackets, which we cannot use here. */
|
||||
{
|
||||
char *link;
|
||||
|
||||
link = xreadlink ("/proc/self/exe");
|
||||
if (link != NULL && link[0] != '[')
|
||||
return link;
|
||||
if (executable_fd < 0)
|
||||
executable_fd = open ("/proc/self/exe", O_EXEC | O_CLOEXEC, 0);
|
||||
|
||||
{
|
||||
char buf[6+10+5];
|
||||
sprintf (buf, "/proc/%d/exe", getpid ());
|
||||
link = xreadlink (buf);
|
||||
if (link != NULL && link[0] != '[')
|
||||
return link;
|
||||
if (executable_fd < 0)
|
||||
executable_fd = open (buf, O_EXEC | O_CLOEXEC, 0);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
# if defined __ANDROID__ || defined __FreeBSD_kernel__
|
||||
/* On Android and GNU/kFreeBSD, the executable is accessible as
|
||||
/proc/<pid>/exe and /proc/self/exe. */
|
||||
{
|
||||
char *link;
|
||||
|
||||
link = xreadlink ("/proc/self/exe");
|
||||
if (link != NULL)
|
||||
return link;
|
||||
}
|
||||
# endif
|
||||
# if defined __FreeBSD__ || defined __DragonFly__
|
||||
/* In FreeBSD >= 5.0, the executable is accessible as /proc/<pid>/file and
|
||||
/proc/curproc/file. */
|
||||
{
|
||||
char *link;
|
||||
|
||||
link = xreadlink ("/proc/curproc/file");
|
||||
if (link != NULL)
|
||||
{
|
||||
if (strcmp (link, "unknown") != 0)
|
||||
return link;
|
||||
free (link);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
# if defined __NetBSD__
|
||||
/* In NetBSD >= 4.0, the executable is accessible as /proc/<pid>/exe and
|
||||
/proc/curproc/exe. */
|
||||
{
|
||||
char *link;
|
||||
|
||||
link = xreadlink ("/proc/curproc/exe");
|
||||
if (link != NULL)
|
||||
return link;
|
||||
}
|
||||
# endif
|
||||
# if defined __sun
|
||||
/* On Solaris >= 11.4, /proc/<pid>/execname and /proc/self/execname contains
|
||||
the name of the executable, either as an absolute file name or relative to
|
||||
the current directory. */
|
||||
{
|
||||
char namebuf[4096];
|
||||
int fd = open ("/proc/self/execname", O_RDONLY | O_CLOEXEC, 0);
|
||||
if (fd >= 0)
|
||||
{
|
||||
size_t len = full_read (fd, namebuf, sizeof (namebuf));
|
||||
close (fd);
|
||||
if (len > 0 && len < sizeof (namebuf))
|
||||
{
|
||||
namebuf[len] = '\0';
|
||||
return canonicalize_file_name (namebuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
# endif
|
||||
# if defined __CYGWIN__
|
||||
/* The executable is accessible as /proc/<pid>/exe, at least in
|
||||
Cygwin >= 1.5. */
|
||||
{
|
||||
char *link;
|
||||
|
||||
link = xreadlink ("/proc/self/exe");
|
||||
if (link != NULL)
|
||||
return link;
|
||||
if (executable_fd < 0)
|
||||
executable_fd = open ("/proc/self/exe", O_EXEC | O_CLOEXEC, 0);
|
||||
}
|
||||
# endif
|
||||
# if HAVE_MACH_O_DYLD_H && HAVE__NSGETEXECUTABLEPATH
|
||||
/* On Mac OS X 10.2 or newer, the function
|
||||
int _NSGetExecutablePath (char *buf, uint32_t *bufsize);
|
||||
can be used to retrieve the executable's full path. */
|
||||
char location[4096];
|
||||
unsigned int length = sizeof (location);
|
||||
if (_NSGetExecutablePath (location, &length) == 0
|
||||
&& location[0] == '/')
|
||||
return canonicalize_file_name (location);
|
||||
# endif
|
||||
/* Guess the executable's full path. We assume the executable has been
|
||||
called via execlp() or execvp() with properly set up argv[0]. The
|
||||
login(1) convention to add a '-' prefix to argv[0] is not supported. */
|
||||
{
|
||||
bool has_slash = false;
|
||||
{
|
||||
const char *p;
|
||||
for (p = argv0; *p; p++)
|
||||
if (*p == '/')
|
||||
{
|
||||
has_slash = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has_slash)
|
||||
{
|
||||
/* exec searches paths without slashes in the directory list given
|
||||
by $PATH. */
|
||||
const char *path = getenv ("PATH");
|
||||
|
||||
if (path != NULL)
|
||||
{
|
||||
const char *p;
|
||||
const char *p_next;
|
||||
|
||||
for (p = path; *p; p = p_next)
|
||||
{
|
||||
const char *q;
|
||||
size_t p_len;
|
||||
char *concat_name;
|
||||
|
||||
for (q = p; *q; q++)
|
||||
if (*q == ':')
|
||||
break;
|
||||
p_len = q - p;
|
||||
p_next = (*q == '\0' ? q : q + 1);
|
||||
|
||||
/* We have a path item at p, of length p_len.
|
||||
Now concatenate the path item and argv0. */
|
||||
concat_name = (char *) xmalloc (p_len + strlen (argv0) + 2);
|
||||
# ifdef NO_XMALLOC
|
||||
if (concat_name == NULL)
|
||||
return NULL;
|
||||
# endif
|
||||
if (p_len == 0)
|
||||
/* An empty PATH element designates the current directory. */
|
||||
strcpy (concat_name, argv0);
|
||||
else
|
||||
{
|
||||
memcpy (concat_name, p, p_len);
|
||||
concat_name[p_len] = '/';
|
||||
strcpy (concat_name + p_len + 1, argv0);
|
||||
}
|
||||
if (maybe_executable (concat_name))
|
||||
return canonicalize_file_name (concat_name);
|
||||
free (concat_name);
|
||||
}
|
||||
}
|
||||
/* Not found in the PATH, assume the current directory. */
|
||||
}
|
||||
/* exec treats paths containing slashes as relative to the current
|
||||
directory. */
|
||||
if (maybe_executable (argv0))
|
||||
return canonicalize_file_name (argv0);
|
||||
}
|
||||
/* No way to find the executable. */
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Full pathname of executable, or NULL. */
|
||||
static char *executable_fullname;
|
||||
|
||||
static void
|
||||
prepare_relocate (const char *orig_installprefix, const char *orig_installdir,
|
||||
const char *argv0)
|
||||
{
|
||||
char *curr_prefix;
|
||||
|
||||
/* Determine the full pathname of the current executable. */
|
||||
executable_fullname = find_executable (argv0);
|
||||
|
||||
/* Determine the current installation prefix from it. */
|
||||
curr_prefix = compute_curr_prefix (orig_installprefix, orig_installdir,
|
||||
executable_fullname);
|
||||
if (curr_prefix != NULL)
|
||||
{
|
||||
/* Now pass this prefix to all copies of the relocate.c source file. */
|
||||
set_relocation_prefix (orig_installprefix, curr_prefix);
|
||||
|
||||
free (curr_prefix);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set program_name, based on argv[0], and original installation prefix and
|
||||
directory, for relocatability. */
|
||||
void
|
||||
set_program_name_and_installdir (const char *argv0,
|
||||
const char *orig_installprefix,
|
||||
const char *orig_installdir)
|
||||
{
|
||||
const char *argv0_stripped = argv0;
|
||||
|
||||
/* Relocatable programs are renamed to .bin by install-reloc. Or, more
|
||||
generally, their suffix is changed from $exeext to .bin$exeext.
|
||||
Remove the ".bin" here. */
|
||||
{
|
||||
size_t argv0_len = strlen (argv0);
|
||||
const size_t exeext_len = sizeof (EXEEXT) - sizeof ("");
|
||||
if (argv0_len > 4 + exeext_len)
|
||||
if (memcmp (argv0 + argv0_len - exeext_len - 4, ".bin", 4) == 0)
|
||||
{
|
||||
if (sizeof (EXEEXT) > sizeof (""))
|
||||
{
|
||||
/* Compare using an inlined copy of c_strncasecmp(), because
|
||||
the filenames may have undergone a case conversion since
|
||||
they were packaged. In other words, EXEEXT may be ".exe"
|
||||
on one system and ".EXE" on another. */
|
||||
static const char exeext[] = EXEEXT;
|
||||
const char *s1 = argv0 + argv0_len - exeext_len;
|
||||
const char *s2 = exeext;
|
||||
for (; *s1 != '\0'; s1++, s2++)
|
||||
{
|
||||
unsigned char c1 = *s1;
|
||||
unsigned char c2 = *s2;
|
||||
if ((c1 >= 'A' && c1 <= 'Z' ? c1 - 'A' + 'a' : c1)
|
||||
!= (c2 >= 'A' && c2 <= 'Z' ? c2 - 'A' + 'a' : c2))
|
||||
goto done_stripping;
|
||||
}
|
||||
}
|
||||
/* Remove ".bin" before EXEEXT or its equivalent. */
|
||||
{
|
||||
char *shorter = (char *) xmalloc (argv0_len - 4 + 1);
|
||||
#ifdef NO_XMALLOC
|
||||
if (shorter != NULL)
|
||||
#endif
|
||||
{
|
||||
memcpy (shorter, argv0, argv0_len - exeext_len - 4);
|
||||
if (sizeof (EXEEXT) > sizeof (""))
|
||||
memcpy (shorter + argv0_len - exeext_len - 4,
|
||||
argv0 + argv0_len - exeext_len - 4,
|
||||
exeext_len);
|
||||
shorter[argv0_len - 4] = '\0';
|
||||
argv0_stripped = shorter;
|
||||
}
|
||||
}
|
||||
done_stripping: ;
|
||||
}
|
||||
}
|
||||
|
||||
set_program_name (argv0_stripped);
|
||||
|
||||
prepare_relocate (orig_installprefix, orig_installdir, argv0);
|
||||
}
|
||||
|
||||
/* Return the full pathname of the current executable, based on the earlier
|
||||
call to set_program_name_and_installdir. Return NULL if unknown. */
|
||||
char *
|
||||
get_full_program_name (void)
|
||||
{
|
||||
return executable_fullname;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,83 +0,0 @@
|
||||
/* Provide a non-threads replacement for the POSIX raise function.
|
||||
|
||||
Copyright (C) 2002-2003, 2005-2006, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* written by Jim Meyering and Bruno Haible */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <signal.h>
|
||||
|
||||
#if HAVE_RAISE
|
||||
/* Native Windows platform. */
|
||||
|
||||
# include <errno.h>
|
||||
|
||||
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
# include "msvc-inval.h"
|
||||
# endif
|
||||
|
||||
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
/* Forward declaration. */
|
||||
static int raise_nothrow (int sig);
|
||||
# else
|
||||
# define raise_nothrow raise
|
||||
# endif
|
||||
|
||||
#else
|
||||
/* An old Unix platform. */
|
||||
|
||||
# include <unistd.h>
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
raise (int sig)
|
||||
#undef raise
|
||||
{
|
||||
#if GNULIB_defined_signal_blocking && GNULIB_defined_SIGPIPE
|
||||
if (sig == SIGPIPE)
|
||||
return _gl_raise_SIGPIPE ();
|
||||
#endif
|
||||
|
||||
#if HAVE_RAISE
|
||||
return raise_nothrow (sig);
|
||||
#else
|
||||
return kill (getpid (), sig);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if HAVE_RAISE && HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
static int
|
||||
raise_nothrow (int sig)
|
||||
{
|
||||
int result;
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = raise (sig);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
result = -1;
|
||||
errno = EINVAL;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -1,95 +0,0 @@
|
||||
/* POSIX compatible read() function.
|
||||
Copyright (C) 2008-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2011.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined _WIN32 && ! defined __CYGWIN__
|
||||
|
||||
# include <errno.h>
|
||||
# include <io.h>
|
||||
|
||||
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
|
||||
# include <windows.h>
|
||||
|
||||
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
# include "msvc-inval.h"
|
||||
# endif
|
||||
# if GNULIB_MSVC_NOTHROW
|
||||
# include "msvc-nothrow.h"
|
||||
# else
|
||||
# include <io.h>
|
||||
# endif
|
||||
|
||||
/* Don't assume that UNICODE is not defined. */
|
||||
# undef GetNamedPipeHandleState
|
||||
# define GetNamedPipeHandleState GetNamedPipeHandleStateA
|
||||
|
||||
# undef read
|
||||
|
||||
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
static ssize_t
|
||||
read_nothrow (int fd, void *buf, size_t count)
|
||||
{
|
||||
ssize_t result;
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = _read (fd, buf, count);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
result = -1;
|
||||
errno = EBADF;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
return result;
|
||||
}
|
||||
# else
|
||||
# define read_nothrow _read
|
||||
# endif
|
||||
|
||||
ssize_t
|
||||
rpl_read (int fd, void *buf, size_t count)
|
||||
{
|
||||
ssize_t ret = read_nothrow (fd, buf, count);
|
||||
|
||||
# if GNULIB_NONBLOCKING
|
||||
if (ret < 0
|
||||
&& GetLastError () == ERROR_NO_DATA)
|
||||
{
|
||||
HANDLE h = (HANDLE) _get_osfhandle (fd);
|
||||
if (GetFileType (h) == FILE_TYPE_PIPE)
|
||||
{
|
||||
/* h is a pipe or socket. */
|
||||
DWORD state;
|
||||
if (GetNamedPipeHandleState (h, &state, NULL, NULL, NULL, NULL, 0)
|
||||
&& (state & PIPE_NOWAIT) != 0)
|
||||
/* h is a pipe in non-blocking mode.
|
||||
Change errno from EINVAL to EAGAIN. */
|
||||
errno = EAGAIN;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,104 +0,0 @@
|
||||
/* Read the contents of a symbolic link.
|
||||
Copyright (C) 2003-2007, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <unistd.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if !HAVE_READLINK
|
||||
|
||||
/* readlink() substitute for systems that don't have a readlink() function,
|
||||
such as DJGPP 2.03 and mingw32. */
|
||||
|
||||
ssize_t
|
||||
readlink (char const *file, _GL_UNUSED char *buf,
|
||||
_GL_UNUSED size_t bufsize)
|
||||
{
|
||||
struct stat statbuf;
|
||||
|
||||
/* In general we should use lstat() here, not stat(). But on platforms
|
||||
without symbolic links, lstat() - if it exists - would be equivalent to
|
||||
stat(), therefore we can use stat(). This saves us a configure check. */
|
||||
if (stat (file, &statbuf) >= 0)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else /* HAVE_READLINK */
|
||||
|
||||
# undef readlink
|
||||
|
||||
/* readlink() wrapper that uses correct types, for systems like cygwin
|
||||
1.5.x where readlink returns int, and which rejects trailing slash,
|
||||
for Solaris 9. */
|
||||
|
||||
ssize_t
|
||||
rpl_readlink (char const *file, char *buf, size_t bufsize)
|
||||
{
|
||||
# if READLINK_TRAILING_SLASH_BUG
|
||||
size_t file_len = strlen (file);
|
||||
if (file_len && file[file_len - 1] == '/')
|
||||
{
|
||||
/* Even if FILE without the slash is a symlink to a directory,
|
||||
both lstat() and stat() must resolve the trailing slash to
|
||||
the directory rather than the symlink. We can therefore
|
||||
safely use stat() to distinguish between EINVAL and
|
||||
ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */
|
||||
struct stat st;
|
||||
if (stat (file, &st) == 0 || errno == EOVERFLOW)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
# endif /* READLINK_TRAILING_SLASH_BUG */
|
||||
|
||||
ssize_t r = readlink (file, buf, bufsize);
|
||||
|
||||
# if READLINK_TRUNCATE_BUG
|
||||
if (r < 0 && errno == ERANGE)
|
||||
{
|
||||
/* Try again with a bigger buffer. This is just for test cases;
|
||||
real code invariably discards short reads. */
|
||||
char stackbuf[4032];
|
||||
r = readlink (file, stackbuf, sizeof stackbuf);
|
||||
if (r < 0)
|
||||
{
|
||||
if (errno == ERANGE)
|
||||
{
|
||||
/* Clear the buffer, which is good enough for real code.
|
||||
Thankfully, no test cases try short reads of enormous
|
||||
symlinks and what would be the point anyway? */
|
||||
r = bufsize;
|
||||
memset (buf, 0, r);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bufsize < r)
|
||||
r = bufsize;
|
||||
memcpy (buf, stackbuf, r);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* HAVE_READLINK */
|
||||
@@ -1,63 +0,0 @@
|
||||
/* realloc() function that is glibc compatible.
|
||||
|
||||
Copyright (C) 1997, 2003-2004, 2006-2007, 2009-2022 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* written by Jim Meyering and Bruno Haible */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "xalloc-oversized.h"
|
||||
|
||||
/* Call the system's realloc below. This file does not define
|
||||
_GL_USE_STDLIB_ALLOC because it needs Gnulib's malloc if present. */
|
||||
#undef realloc
|
||||
|
||||
/* Change the size of an allocated block of memory P to N bytes,
|
||||
with error checking. If P is NULL, use malloc. Otherwise if N is zero,
|
||||
free P and return NULL. */
|
||||
|
||||
void *
|
||||
rpl_realloc (void *p, size_t n)
|
||||
{
|
||||
if (p == NULL)
|
||||
return malloc (n);
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
free (p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (xalloc_oversized (n, 1))
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *result = realloc (p, n);
|
||||
|
||||
#if !HAVE_MALLOC_POSIX
|
||||
if (result == NULL)
|
||||
errno = ENOMEM;
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,603 +0,0 @@
|
||||
/* Provide relocatable packages.
|
||||
Copyright (C) 2003-2006, 2008-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
/* Tell glibc's <stdio.h> to provide a prototype for getline().
|
||||
This must come before <config.h> because <config.h> may include
|
||||
<features.h>, and once <features.h> has been included, it's too late. */
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
#define _GL_USE_STDLIB_ALLOC 1
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "relocatable.h"
|
||||
|
||||
#if ENABLE_RELOCATABLE
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef NO_XMALLOC
|
||||
# define xmalloc malloc
|
||||
#else
|
||||
# include "xalloc.h"
|
||||
#endif
|
||||
|
||||
#if defined _WIN32 && !defined __CYGWIN__
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef __EMX__
|
||||
# define INCL_DOS
|
||||
# include <os2.h>
|
||||
|
||||
# define strcmp stricmp
|
||||
# define strncmp strnicmp
|
||||
#endif
|
||||
|
||||
#if DEPENDS_ON_LIBCHARSET
|
||||
# include <libcharset.h>
|
||||
#endif
|
||||
#if DEPENDS_ON_LIBICONV && HAVE_ICONV
|
||||
# include <iconv.h>
|
||||
#endif
|
||||
#if DEPENDS_ON_LIBINTL && ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
#endif
|
||||
|
||||
#if defined _WIN32 && !defined __CYGWIN__
|
||||
/* Don't assume that UNICODE is not defined. */
|
||||
# undef GetModuleFileName
|
||||
# define GetModuleFileName GetModuleFileNameA
|
||||
#endif
|
||||
|
||||
/* Faked cheap 'bool'. */
|
||||
#undef bool
|
||||
#undef false
|
||||
#undef true
|
||||
#define bool int
|
||||
#define false 0
|
||||
#define true 1
|
||||
|
||||
/* Pathname support.
|
||||
ISSLASH(C) tests whether C is a directory separator character.
|
||||
IS_FILE_NAME_WITH_DIR(P) tests whether P contains a directory specification.
|
||||
*/
|
||||
#if (defined _WIN32 && !defined __CYGWIN__) || defined __EMX__ || defined __DJGPP__
|
||||
/* Native Windows, OS/2, DOS */
|
||||
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
|
||||
# define HAS_DEVICE(P) \
|
||||
((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
|
||||
&& (P)[1] == ':')
|
||||
# define IS_FILE_NAME_WITH_DIR(P) \
|
||||
(strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
|
||||
# define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
|
||||
#else
|
||||
/* Unix */
|
||||
# define ISSLASH(C) ((C) == '/')
|
||||
# define IS_FILE_NAME_WITH_DIR(P) (strchr (P, '/') != NULL)
|
||||
# define FILE_SYSTEM_PREFIX_LEN(P) 0
|
||||
#endif
|
||||
|
||||
/* Whether to enable the more costly support for relocatable libraries.
|
||||
It allows libraries to be have been installed with a different original
|
||||
prefix than the program. But it is quite costly, especially on Cygwin
|
||||
platforms, see below. Therefore we enable it by default only on native
|
||||
Windows platforms. */
|
||||
#ifndef ENABLE_COSTLY_RELOCATABLE
|
||||
# if defined _WIN32 && !defined __CYGWIN__
|
||||
# define ENABLE_COSTLY_RELOCATABLE 1
|
||||
# else
|
||||
# define ENABLE_COSTLY_RELOCATABLE 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Original installation prefix. */
|
||||
static char *orig_prefix;
|
||||
static size_t orig_prefix_len;
|
||||
/* Current installation prefix. */
|
||||
static char *curr_prefix;
|
||||
static size_t curr_prefix_len;
|
||||
/* These prefixes do not end in a slash. Anything that will be concatenated
|
||||
to them must start with a slash. */
|
||||
|
||||
/* Sets the original and the current installation prefix of this module.
|
||||
Relocation simply replaces a pathname starting with the original prefix
|
||||
by the corresponding pathname with the current prefix instead. Both
|
||||
prefixes should be directory names without trailing slash (i.e. use ""
|
||||
instead of "/"). */
|
||||
static void
|
||||
set_this_relocation_prefix (const char *orig_prefix_arg,
|
||||
const char *curr_prefix_arg)
|
||||
{
|
||||
if (orig_prefix_arg != NULL && curr_prefix_arg != NULL
|
||||
/* Optimization: if orig_prefix and curr_prefix are equal, the
|
||||
relocation is a nop. */
|
||||
&& strcmp (orig_prefix_arg, curr_prefix_arg) != 0)
|
||||
{
|
||||
/* Duplicate the argument strings. */
|
||||
char *memory;
|
||||
|
||||
orig_prefix_len = strlen (orig_prefix_arg);
|
||||
curr_prefix_len = strlen (curr_prefix_arg);
|
||||
memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1);
|
||||
#ifdef NO_XMALLOC
|
||||
if (memory != NULL)
|
||||
#endif
|
||||
{
|
||||
memcpy (memory, orig_prefix_arg, orig_prefix_len + 1);
|
||||
orig_prefix = memory;
|
||||
memory += orig_prefix_len + 1;
|
||||
memcpy (memory, curr_prefix_arg, curr_prefix_len + 1);
|
||||
curr_prefix = memory;
|
||||
return;
|
||||
}
|
||||
}
|
||||
orig_prefix = NULL;
|
||||
curr_prefix = NULL;
|
||||
/* Don't worry about wasted memory here - this function is usually only
|
||||
called once. */
|
||||
}
|
||||
|
||||
/* Sets the original and the current installation prefix of the package.
|
||||
Relocation simply replaces a pathname starting with the original prefix
|
||||
by the corresponding pathname with the current prefix instead. Both
|
||||
prefixes should be directory names without trailing slash (i.e. use ""
|
||||
instead of "/"). */
|
||||
void
|
||||
set_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg)
|
||||
{
|
||||
set_this_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
|
||||
|
||||
/* Now notify all dependent libraries. */
|
||||
#if DEPENDS_ON_LIBCHARSET
|
||||
libcharset_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
|
||||
#endif
|
||||
#if DEPENDS_ON_LIBICONV && HAVE_ICONV && _LIBICONV_VERSION >= 0x0109
|
||||
libiconv_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
|
||||
#endif
|
||||
#if DEPENDS_ON_LIBINTL && ENABLE_NLS && defined libintl_set_relocation_prefix
|
||||
libintl_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined IN_LIBRARY || (defined PIC && defined INSTALLDIR && ENABLE_COSTLY_RELOCATABLE)
|
||||
|
||||
/* Convenience function:
|
||||
Computes the current installation prefix, based on the original
|
||||
installation prefix, the original installation directory of a particular
|
||||
file, and the current pathname of this file.
|
||||
Returns it, freshly allocated. Returns NULL upon failure. */
|
||||
#ifdef IN_LIBRARY
|
||||
#define compute_curr_prefix local_compute_curr_prefix
|
||||
static
|
||||
#endif
|
||||
char *
|
||||
compute_curr_prefix (const char *orig_installprefix,
|
||||
const char *orig_installdir,
|
||||
const char *curr_pathname)
|
||||
{
|
||||
char *curr_installdir;
|
||||
const char *rel_installdir;
|
||||
|
||||
if (curr_pathname == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Determine the relative installation directory, relative to the prefix.
|
||||
This is simply the difference between orig_installprefix and
|
||||
orig_installdir. */
|
||||
if (strncmp (orig_installprefix, orig_installdir, strlen (orig_installprefix))
|
||||
!= 0)
|
||||
/* Shouldn't happen - nothing should be installed outside $(prefix). */
|
||||
return NULL;
|
||||
rel_installdir = orig_installdir + strlen (orig_installprefix);
|
||||
|
||||
/* Determine the current installation directory. */
|
||||
{
|
||||
const char *p_base = curr_pathname + FILE_SYSTEM_PREFIX_LEN (curr_pathname);
|
||||
const char *p = curr_pathname + strlen (curr_pathname);
|
||||
char *q;
|
||||
|
||||
while (p > p_base)
|
||||
{
|
||||
p--;
|
||||
if (ISSLASH (*p))
|
||||
break;
|
||||
}
|
||||
|
||||
q = (char *) xmalloc (p - curr_pathname + 1);
|
||||
#ifdef NO_XMALLOC
|
||||
if (q == NULL)
|
||||
return NULL;
|
||||
#endif
|
||||
memcpy (q, curr_pathname, p - curr_pathname);
|
||||
q[p - curr_pathname] = '\0';
|
||||
curr_installdir = q;
|
||||
}
|
||||
|
||||
/* Compute the current installation prefix by removing the trailing
|
||||
rel_installdir from it. */
|
||||
{
|
||||
const char *rp = rel_installdir + strlen (rel_installdir);
|
||||
const char *cp = curr_installdir + strlen (curr_installdir);
|
||||
const char *cp_base =
|
||||
curr_installdir + FILE_SYSTEM_PREFIX_LEN (curr_installdir);
|
||||
|
||||
while (rp > rel_installdir && cp > cp_base)
|
||||
{
|
||||
bool same = false;
|
||||
const char *rpi = rp;
|
||||
const char *cpi = cp;
|
||||
|
||||
while (rpi > rel_installdir && cpi > cp_base)
|
||||
{
|
||||
rpi--;
|
||||
cpi--;
|
||||
if (ISSLASH (*rpi) || ISSLASH (*cpi))
|
||||
{
|
||||
if (ISSLASH (*rpi) && ISSLASH (*cpi))
|
||||
same = true;
|
||||
break;
|
||||
}
|
||||
/* Do case-insensitive comparison if the file system is always or
|
||||
often case-insensitive. It's better to accept the comparison
|
||||
if the difference is only in case, rather than to fail. */
|
||||
#if defined _WIN32 || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
|
||||
/* Native Windows, Cygwin, OS/2, DOS - case insignificant file system */
|
||||
if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi)
|
||||
!= (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi))
|
||||
break;
|
||||
#else
|
||||
if (*rpi != *cpi)
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
if (!same)
|
||||
break;
|
||||
/* The last pathname component was the same. rpi and cpi now point
|
||||
to the slash before it. */
|
||||
rp = rpi;
|
||||
cp = cpi;
|
||||
}
|
||||
|
||||
if (rp > rel_installdir)
|
||||
{
|
||||
/* Unexpected: The curr_installdir does not end with rel_installdir. */
|
||||
free (curr_installdir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
{
|
||||
size_t computed_curr_prefix_len = cp - curr_installdir;
|
||||
char *computed_curr_prefix;
|
||||
|
||||
computed_curr_prefix = (char *) xmalloc (computed_curr_prefix_len + 1);
|
||||
#ifdef NO_XMALLOC
|
||||
if (computed_curr_prefix == NULL)
|
||||
{
|
||||
free (curr_installdir);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
memcpy (computed_curr_prefix, curr_installdir, computed_curr_prefix_len);
|
||||
computed_curr_prefix[computed_curr_prefix_len] = '\0';
|
||||
|
||||
free (curr_installdir);
|
||||
|
||||
return computed_curr_prefix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* !IN_LIBRARY || PIC */
|
||||
|
||||
#if defined PIC && defined INSTALLDIR && ENABLE_COSTLY_RELOCATABLE
|
||||
|
||||
/* Full pathname of shared library, or NULL. */
|
||||
static char *shared_library_fullname;
|
||||
|
||||
#if defined _WIN32 && !defined __CYGWIN__
|
||||
/* Native Windows only.
|
||||
On Cygwin, it is better to use the Cygwin provided /proc interface, than
|
||||
to use native Windows API and cygwin_conv_to_posix_path, because it
|
||||
supports longer file names
|
||||
(see <https://cygwin.com/ml/cygwin/2011-01/msg00410.html>). */
|
||||
|
||||
/* Determine the full pathname of the shared library when it is loaded.
|
||||
|
||||
Documentation:
|
||||
<https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain> */
|
||||
|
||||
BOOL WINAPI
|
||||
DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
|
||||
{
|
||||
(void) reserved;
|
||||
|
||||
if (event == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
/* The DLL is being loaded into an application's address range. */
|
||||
static char location[MAX_PATH];
|
||||
|
||||
if (!GetModuleFileName (module_handle, location, sizeof (location)))
|
||||
/* Shouldn't happen. */
|
||||
return FALSE;
|
||||
|
||||
if (!IS_FILE_NAME_WITH_DIR (location))
|
||||
/* Shouldn't happen. */
|
||||
return FALSE;
|
||||
|
||||
/* Avoid a memory leak when the same DLL get attached, detached,
|
||||
attached, detached, and so on. This happens e.g. when a spell
|
||||
checker DLL is used repeatedly by a mail program. */
|
||||
if (!(shared_library_fullname != NULL
|
||||
&& strcmp (shared_library_fullname, location) == 0))
|
||||
/* Remember the full pathname of the shared library. */
|
||||
shared_library_fullname = strdup (location);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#elif defined __EMX__
|
||||
|
||||
extern int _CRT_init (void);
|
||||
extern void _CRT_term (void);
|
||||
extern void __ctordtorInit (void);
|
||||
extern void __ctordtorTerm (void);
|
||||
|
||||
unsigned long _System
|
||||
_DLL_InitTerm (unsigned long hModule, unsigned long ulFlag)
|
||||
{
|
||||
static char location[CCHMAXPATH];
|
||||
|
||||
switch (ulFlag)
|
||||
{
|
||||
case 0:
|
||||
if (_CRT_init () == -1)
|
||||
return 0;
|
||||
|
||||
__ctordtorInit();
|
||||
|
||||
/* See http://cyberkinetica.homeunix.net/os2tk45/cp1/1247_L2H_DosQueryModuleNameSy.html
|
||||
for specification of DosQueryModuleName(). */
|
||||
if (DosQueryModuleName (hModule, sizeof (location), location))
|
||||
return 0;
|
||||
|
||||
_fnslashify (location);
|
||||
shared_library_fullname = strdup (location);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
__ctordtorTerm();
|
||||
|
||||
_CRT_term ();
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else /* Unix */
|
||||
|
||||
static void
|
||||
find_shared_library_fullname ()
|
||||
{
|
||||
#if (defined __linux__ && (__GLIBC__ >= 2 || defined __UCLIBC__)) || defined __CYGWIN__
|
||||
/* Linux has /proc/self/maps. glibc 2 and uClibc have the getline()
|
||||
function.
|
||||
Cygwin >= 1.5 has /proc/self/maps and the getline() function too.
|
||||
But it is costly: ca. 0.3 ms on Linux, 3 ms on Cygwin 1.5, and 5 ms on
|
||||
Cygwin 1.7. */
|
||||
FILE *fp;
|
||||
|
||||
/* Open the current process' maps file. It describes one VMA per line. */
|
||||
fp = fopen ("/proc/self/maps", "r");
|
||||
if (fp)
|
||||
{
|
||||
unsigned long address = (unsigned long) &find_shared_library_fullname;
|
||||
for (;;)
|
||||
{
|
||||
unsigned long start, end;
|
||||
int c;
|
||||
|
||||
if (fscanf (fp, "%lx-%lx", &start, &end) != 2)
|
||||
break;
|
||||
if (address >= start && address <= end - 1)
|
||||
{
|
||||
/* Found it. Now see if this line contains a filename. */
|
||||
while (c = getc (fp), c != EOF && c != '\n' && c != '/')
|
||||
continue;
|
||||
if (c == '/')
|
||||
{
|
||||
size_t size;
|
||||
int len;
|
||||
|
||||
ungetc (c, fp);
|
||||
shared_library_fullname = NULL; size = 0;
|
||||
len = getline (&shared_library_fullname, &size, fp);
|
||||
if (len >= 0)
|
||||
{
|
||||
/* Success: filled shared_library_fullname. */
|
||||
if (len > 0 && shared_library_fullname[len - 1] == '\n')
|
||||
shared_library_fullname[len - 1] = '\0';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
while (c = getc (fp), c != EOF && c != '\n')
|
||||
continue;
|
||||
}
|
||||
fclose (fp);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* Native Windows / EMX / Unix */
|
||||
|
||||
/* Return the full pathname of the current shared library.
|
||||
Return NULL if unknown.
|
||||
Guaranteed to work only on Linux, EMX, Cygwin, and native Windows. */
|
||||
static char *
|
||||
get_shared_library_fullname ()
|
||||
{
|
||||
#if !(defined _WIN32 && !defined __CYGWIN__) && !defined __EMX__
|
||||
static bool tried_find_shared_library_fullname;
|
||||
if (!tried_find_shared_library_fullname)
|
||||
{
|
||||
find_shared_library_fullname ();
|
||||
tried_find_shared_library_fullname = true;
|
||||
}
|
||||
#endif
|
||||
return shared_library_fullname;
|
||||
}
|
||||
|
||||
#endif /* PIC */
|
||||
|
||||
/* Returns the pathname, relocated according to the current installation
|
||||
directory.
|
||||
The returned string is either PATHNAME unmodified or a freshly allocated
|
||||
string that you can free with free() after casting it to 'char *'. */
|
||||
const char *
|
||||
relocate (const char *pathname)
|
||||
{
|
||||
#if defined PIC && defined INSTALLDIR && ENABLE_COSTLY_RELOCATABLE
|
||||
static int initialized;
|
||||
|
||||
/* Initialization code for a shared library. */
|
||||
if (!initialized)
|
||||
{
|
||||
/* At this point, orig_prefix and curr_prefix likely have already been
|
||||
set through the main program's set_program_name_and_installdir
|
||||
function. This is sufficient in the case that the library has
|
||||
initially been installed in the same orig_prefix. But we can do
|
||||
better, to also cover the cases that 1. it has been installed
|
||||
in a different prefix before being moved to orig_prefix and (later)
|
||||
to curr_prefix, 2. unlike the program, it has not moved away from
|
||||
orig_prefix. */
|
||||
const char *orig_installprefix = INSTALLPREFIX;
|
||||
const char *orig_installdir = INSTALLDIR;
|
||||
char *curr_prefix_better;
|
||||
|
||||
curr_prefix_better =
|
||||
compute_curr_prefix (orig_installprefix, orig_installdir,
|
||||
get_shared_library_fullname ());
|
||||
|
||||
set_relocation_prefix (orig_installprefix,
|
||||
curr_prefix_better != NULL
|
||||
? curr_prefix_better
|
||||
: curr_prefix);
|
||||
|
||||
if (curr_prefix_better != NULL)
|
||||
free (curr_prefix_better);
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Note: It is not necessary to perform case insensitive comparison here,
|
||||
even for DOS-like file systems, because the pathname argument was
|
||||
typically created from the same Makefile variable as orig_prefix came
|
||||
from. */
|
||||
if (orig_prefix != NULL && curr_prefix != NULL
|
||||
&& strncmp (pathname, orig_prefix, orig_prefix_len) == 0)
|
||||
{
|
||||
if (pathname[orig_prefix_len] == '\0')
|
||||
{
|
||||
/* pathname equals orig_prefix. */
|
||||
char *result = (char *) xmalloc (strlen (curr_prefix) + 1);
|
||||
|
||||
#ifdef NO_XMALLOC
|
||||
if (result != NULL)
|
||||
#endif
|
||||
{
|
||||
strcpy (result, curr_prefix);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (ISSLASH (pathname[orig_prefix_len]))
|
||||
{
|
||||
/* pathname starts with orig_prefix. */
|
||||
const char *pathname_tail = &pathname[orig_prefix_len];
|
||||
char *result =
|
||||
(char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1);
|
||||
|
||||
#ifdef NO_XMALLOC
|
||||
if (result != NULL)
|
||||
#endif
|
||||
{
|
||||
memcpy (result, curr_prefix, curr_prefix_len);
|
||||
strcpy (result + curr_prefix_len, pathname_tail);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __EMX__
|
||||
# ifdef __KLIBC__
|
||||
# undef strncmp
|
||||
|
||||
if (strncmp (pathname, "/@unixroot", 10) == 0
|
||||
&& (pathname[10] == '\0' || ISSLASH (pathname[10])))
|
||||
{
|
||||
/* kLIBC itself processes /@unixroot prefix */
|
||||
return pathname;
|
||||
}
|
||||
else
|
||||
# endif
|
||||
if (ISSLASH (pathname[0]))
|
||||
{
|
||||
const char *unixroot = getenv ("UNIXROOT");
|
||||
|
||||
if (unixroot && HAS_DEVICE (unixroot) && unixroot[2] == '\0')
|
||||
{
|
||||
char *result = (char *) xmalloc (2 + strlen (pathname) + 1);
|
||||
#ifdef NO_XMALLOC
|
||||
if (result != NULL)
|
||||
#endif
|
||||
{
|
||||
memcpy (result, unixroot, 2);
|
||||
strcpy (result + 2, pathname);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Nothing to relocate. */
|
||||
return pathname;
|
||||
}
|
||||
|
||||
/* Returns the pathname, relocated according to the current installation
|
||||
directory.
|
||||
This function sets *ALLOCATEDP to the allocated memory, or to NULL if
|
||||
no memory allocation occurs. So that, after you're done with the return
|
||||
value, to reclaim allocated memory, you can do: free (*ALLOCATEDP). */
|
||||
const char *
|
||||
relocate2 (const char *pathname, char **allocatedp)
|
||||
{
|
||||
const char *result = relocate (pathname);
|
||||
*allocatedp = (result != pathname ? (char *) result : NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,104 +0,0 @@
|
||||
/* Provide relocatable packages.
|
||||
Copyright (C) 2003, 2005, 2008-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _RELOCATABLE_H
|
||||
#define _RELOCATABLE_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* This can be enabled through the configure --enable-relocatable option. */
|
||||
#if ENABLE_RELOCATABLE
|
||||
|
||||
/* When building a DLL, we must export some functions. Note that because
|
||||
this is a private .h file, we don't need to use __declspec(dllimport)
|
||||
in any case. */
|
||||
#if HAVE_VISIBILITY && BUILDING_DLL
|
||||
# define RELOCATABLE_DLL_EXPORTED __attribute__((__visibility__("default")))
|
||||
#elif defined _MSC_VER && BUILDING_DLL
|
||||
# define RELOCATABLE_DLL_EXPORTED __declspec(dllexport)
|
||||
#else
|
||||
# define RELOCATABLE_DLL_EXPORTED
|
||||
#endif
|
||||
|
||||
/* Sets the original and the current installation prefix of the package.
|
||||
Relocation simply replaces a pathname starting with the original prefix
|
||||
by the corresponding pathname with the current prefix instead. Both
|
||||
prefixes should be directory names without trailing slash (i.e. use ""
|
||||
instead of "/"). */
|
||||
extern RELOCATABLE_DLL_EXPORTED void
|
||||
set_relocation_prefix (const char *orig_prefix,
|
||||
const char *curr_prefix);
|
||||
|
||||
/* Returns the pathname, relocated according to the current installation
|
||||
directory.
|
||||
The returned string is either PATHNAME unmodified or a freshly allocated
|
||||
string that you can free with free() after casting it to 'char *'. */
|
||||
extern const char * relocate (const char *pathname);
|
||||
|
||||
/* Returns the pathname, relocated according to the current installation
|
||||
directory.
|
||||
This function sets *ALLOCATEDP to the allocated memory, or to NULL if
|
||||
no memory allocation occurs. So that, after you're done with the return
|
||||
value, to reclaim allocated memory, you can do: free (*ALLOCATEDP). */
|
||||
extern const char * relocate2 (const char *pathname, char **allocatedp);
|
||||
|
||||
/* Memory management: relocate() potentially allocates memory, because it has
|
||||
to construct a fresh pathname. If this is a problem because your program
|
||||
calls relocate() frequently or because you want to fix all potential memory
|
||||
leaks anyway, you have three options:
|
||||
1) Use this idiom:
|
||||
const char *pathname = ...;
|
||||
const char *rel_pathname = relocate (pathname);
|
||||
...
|
||||
if (rel_pathname != pathname)
|
||||
free ((char *) rel_pathname);
|
||||
2) Use this idiom:
|
||||
char *allocated;
|
||||
const char *rel_pathname = relocate2 (..., &allocated);
|
||||
...
|
||||
free (allocated);
|
||||
3) Think about caching the result. */
|
||||
|
||||
/* Convenience function:
|
||||
Computes the current installation prefix, based on the original
|
||||
installation prefix, the original installation directory of a particular
|
||||
file, and the current pathname of this file.
|
||||
Returns it, freshly allocated. Returns NULL upon failure. */
|
||||
extern char * compute_curr_prefix (const char *orig_installprefix,
|
||||
const char *orig_installdir,
|
||||
const char *curr_pathname)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
|
||||
#else
|
||||
|
||||
/* By default, we use the hardwired pathnames. */
|
||||
#define relocate(pathname) (pathname)
|
||||
#define relocate2(pathname,allocatedp) (*(allocatedp) = NULL, (pathname))
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _RELOCATABLE_H */
|
||||
@@ -1,224 +0,0 @@
|
||||
/* Relocating wrapper program.
|
||||
Copyright (C) 2003, 2005-2007, 2009-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Dependencies:
|
||||
relocwrapper
|
||||
-> progname
|
||||
-> progreloc
|
||||
-> stat
|
||||
-> filename
|
||||
-> pathmax
|
||||
-> verify
|
||||
-> areadlink
|
||||
-> careadlinkat
|
||||
-> allocator
|
||||
-> readlink
|
||||
-> stat
|
||||
-> canonicalize-lgpl
|
||||
-> libc-config
|
||||
-> errno
|
||||
-> fcntl-h
|
||||
-> stdbool
|
||||
-> sys_stat
|
||||
-> unistd
|
||||
-> eloop-threshold
|
||||
-> filename
|
||||
-> idx
|
||||
-> intprops
|
||||
-> scratch_buffer
|
||||
-> malloc-posix
|
||||
-> realloc-posix
|
||||
-> free-posix
|
||||
-> pathmax
|
||||
-> mempcpy
|
||||
-> rawmemchr
|
||||
-> readlink
|
||||
-> stat
|
||||
-> double-slash-root
|
||||
-> relocatable
|
||||
-> setenv
|
||||
-> malloca
|
||||
-> fprintf-posix [ignore, cut dependency tree here]
|
||||
-> strerror [ignore, cut dependency tree here]
|
||||
-> c-ctype
|
||||
|
||||
Macros that need to be set while compiling this file:
|
||||
- ENABLE_RELOCATABLE 1
|
||||
- INSTALLPREFIX the base installation directory
|
||||
- INSTALLDIR the directory into which this program is installed
|
||||
- LIBPATHVAR the platform dependent runtime library path variable
|
||||
- LIBDIRS a comma-terminated list of strings representing the list of
|
||||
directories that contain the libraries at installation time
|
||||
|
||||
We don't want to internationalize this wrapper because then it would
|
||||
depend on libintl and therefore need relocation itself. So use only
|
||||
libc functions, no gettext(), no error(), no xmalloc(), no xsetenv().
|
||||
*/
|
||||
|
||||
#define _GL_USE_STDLIB_ALLOC 1
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "progname.h"
|
||||
#include "relocatable.h"
|
||||
#include "c-ctype.h"
|
||||
#include "verify.h"
|
||||
|
||||
/* Use the system functions, not the gnulib overrides in this file. */
|
||||
#undef fprintf
|
||||
#undef strerror
|
||||
|
||||
/* Return a copy of the filename, with an extra ".bin" at the end.
|
||||
More generally, it replaces "${EXEEXT}" at the end with ".bin${EXEEXT}". */
|
||||
static char *
|
||||
add_dotbin (const char *filename)
|
||||
{
|
||||
size_t filename_len = strlen (filename);
|
||||
char *result = (char *) malloc (filename_len + 4 + 1);
|
||||
|
||||
if (result != NULL)
|
||||
{
|
||||
if (sizeof (EXEEXT) > sizeof (""))
|
||||
{
|
||||
/* EXEEXT handling. */
|
||||
const size_t exeext_len = sizeof (EXEEXT) - sizeof ("");
|
||||
static const char exeext[] = EXEEXT;
|
||||
if (filename_len > exeext_len)
|
||||
{
|
||||
/* Compare using an inlined copy of c_strncasecmp(), because
|
||||
the filenames may have undergone a case conversion since
|
||||
they were packaged. In other words, EXEEXT may be ".exe"
|
||||
on one system and ".EXE" on another. */
|
||||
const char *s1 = filename + filename_len - exeext_len;
|
||||
const char *s2 = exeext;
|
||||
for (; *s1 != '\0'; s1++, s2++)
|
||||
{
|
||||
unsigned char c1 = *s1;
|
||||
unsigned char c2 = *s2;
|
||||
if (c_tolower (c1) != c_tolower (c2))
|
||||
goto simple_append;
|
||||
}
|
||||
/* Insert ".bin" before EXEEXT or its equivalent. */
|
||||
memcpy (result, filename, filename_len - exeext_len);
|
||||
memcpy (result + filename_len - exeext_len, ".bin", 4);
|
||||
memcpy (result + filename_len - exeext_len + 4,
|
||||
filename + filename_len - exeext_len,
|
||||
exeext_len + 1);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
simple_append:
|
||||
/* Simply append ".bin". */
|
||||
memcpy (result, filename, filename_len);
|
||||
memcpy (result + filename_len, ".bin", 4 + 1);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "%s: %s\n", program_name, "memory exhausted");
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* List of directories that contain the libraries. */
|
||||
static const char *libdirs[] = { LIBDIRS NULL };
|
||||
/* Verify that at least one directory is given. */
|
||||
verify (sizeof (libdirs) / sizeof (libdirs[0]) > 1);
|
||||
|
||||
/* Relocate the list of directories that contain the libraries. */
|
||||
static void
|
||||
relocate_libdirs ()
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
|
||||
libdirs[i] = relocate (libdirs[i]);
|
||||
}
|
||||
|
||||
/* Activate the list of directories in the LIBPATHVAR. */
|
||||
static void
|
||||
activate_libdirs ()
|
||||
{
|
||||
const char *old_value;
|
||||
size_t total;
|
||||
size_t i;
|
||||
char *value;
|
||||
char *p;
|
||||
|
||||
old_value = getenv (LIBPATHVAR);
|
||||
if (old_value == NULL)
|
||||
old_value = "";
|
||||
|
||||
total = 0;
|
||||
for (i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
|
||||
total += strlen (libdirs[i]) + 1;
|
||||
total += strlen (old_value) + 1;
|
||||
|
||||
value = (char *) malloc (total);
|
||||
if (value == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: %s\n", program_name, "memory exhausted");
|
||||
exit (1);
|
||||
}
|
||||
p = value;
|
||||
for (i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
|
||||
{
|
||||
size_t len = strlen (libdirs[i]);
|
||||
memcpy (p, libdirs[i], len);
|
||||
p += len;
|
||||
*p++ = ':';
|
||||
}
|
||||
if (old_value[0] != '\0')
|
||||
strcpy (p, old_value);
|
||||
else
|
||||
p[-1] = '\0';
|
||||
|
||||
if (setenv (LIBPATHVAR, value, 1) < 0)
|
||||
{
|
||||
fprintf (stderr, "%s: %s\n", program_name, "memory exhausted");
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char *full_program_name;
|
||||
|
||||
/* Set the program name and perform preparations for
|
||||
get_full_program_name() and relocate(). */
|
||||
set_program_name_and_installdir (argv[0], INSTALLPREFIX, INSTALLDIR);
|
||||
|
||||
/* Get the full program path. (Important if accessed through a symlink.) */
|
||||
full_program_name = get_full_program_name ();
|
||||
if (full_program_name == NULL)
|
||||
full_program_name = argv[0];
|
||||
|
||||
/* Invoke the real program, with suffix ".bin". */
|
||||
argv[0] = add_dotbin (full_program_name);
|
||||
relocate_libdirs ();
|
||||
activate_libdirs ();
|
||||
execv (argv[0], argv);
|
||||
fprintf (stderr, "%s: could not execute %s: %s\n",
|
||||
program_name, argv[0], strerror (errno));
|
||||
exit (127);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/* An interface to read() that retries after interrupts.
|
||||
Copyright (C) 2002, 2006, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Some system calls may be interrupted and fail with errno = EINTR in the
|
||||
following situations:
|
||||
- The process is stopped and restarted (signal SIGSTOP and SIGCONT, user
|
||||
types Ctrl-Z) on some platforms: Mac OS X.
|
||||
- The process receives a signal for which a signal handler was installed
|
||||
with sigaction() with an sa_flags field that does not contain
|
||||
SA_RESTART.
|
||||
- The process receives a signal for which a signal handler was installed
|
||||
with signal() and for which no call to siginterrupt(sig,0) was done,
|
||||
on some platforms: AIX, HP-UX, IRIX, OSF/1, Solaris.
|
||||
|
||||
This module provides a wrapper around read() that handles EINTR. */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define SAFE_READ_ERROR ((size_t) -1)
|
||||
|
||||
/* Read up to COUNT bytes at BUF from descriptor FD, retrying if interrupted.
|
||||
Return the actual number of bytes read, zero for EOF, or SAFE_READ_ERROR
|
||||
upon error. */
|
||||
extern size_t safe_read (int fd, void *buf, size_t count);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,127 +0,0 @@
|
||||
/* Variable-sized buffer with on-stack default allocation.
|
||||
Copyright (C) 2017-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Paul Eggert, 2017. */
|
||||
|
||||
#ifndef _GL_SCRATCH_BUFFER_H
|
||||
#define _GL_SCRATCH_BUFFER_H
|
||||
|
||||
/* Scratch buffers with a default stack allocation and fallback to
|
||||
heap allocation. It is expected that this function is used in this
|
||||
way:
|
||||
|
||||
struct scratch_buffer tmpbuf;
|
||||
scratch_buffer_init (&tmpbuf);
|
||||
|
||||
while (!function_that_uses_buffer (tmpbuf.data, tmpbuf.length))
|
||||
if (!scratch_buffer_grow (&tmpbuf))
|
||||
return -1;
|
||||
|
||||
scratch_buffer_free (&tmpbuf);
|
||||
return 0;
|
||||
|
||||
The allocation functions (scratch_buffer_grow,
|
||||
scratch_buffer_grow_preserve, scratch_buffer_set_array_size) make
|
||||
sure that the heap allocation, if any, is freed, so that the code
|
||||
above does not have a memory leak. The buffer still remains in a
|
||||
state that can be deallocated using scratch_buffer_free, so a loop
|
||||
like this is valid as well:
|
||||
|
||||
struct scratch_buffer tmpbuf;
|
||||
scratch_buffer_init (&tmpbuf);
|
||||
|
||||
while (!function_that_uses_buffer (tmpbuf.data, tmpbuf.length))
|
||||
if (!scratch_buffer_grow (&tmpbuf))
|
||||
break;
|
||||
|
||||
scratch_buffer_free (&tmpbuf);
|
||||
|
||||
scratch_buffer_grow and scratch_buffer_grow_preserve are guaranteed
|
||||
to grow the buffer by at least 512 bytes. This means that when
|
||||
using the scratch buffer as a backing store for a non-character
|
||||
array whose element size, in bytes, is 512 or smaller, the scratch
|
||||
buffer only has to grow once to make room for at least one more
|
||||
element.
|
||||
*/
|
||||
|
||||
/* Scratch buffer. Must be initialized with scratch_buffer_init
|
||||
before its use. */
|
||||
struct scratch_buffer;
|
||||
|
||||
/* Initializes *BUFFER so that BUFFER->data points to BUFFER->__space
|
||||
and BUFFER->length reflects the available space. */
|
||||
#if 0
|
||||
extern void scratch_buffer_init (struct scratch_buffer *buffer);
|
||||
#endif
|
||||
|
||||
/* Deallocates *BUFFER (if it was heap-allocated). */
|
||||
#if 0
|
||||
extern void scratch_buffer_free (struct scratch_buffer *buffer);
|
||||
#endif
|
||||
|
||||
/* Grow *BUFFER by some arbitrary amount. The buffer contents is NOT
|
||||
preserved. Return true on success, false on allocation failure (in
|
||||
which case the old buffer is freed). On success, the new buffer is
|
||||
larger than the previous size. On failure, *BUFFER is deallocated,
|
||||
but remains in a free-able state, and errno is set. */
|
||||
#if 0
|
||||
extern bool scratch_buffer_grow (struct scratch_buffer *buffer);
|
||||
#endif
|
||||
|
||||
/* Like scratch_buffer_grow, but preserve the old buffer
|
||||
contents on success, as a prefix of the new buffer. */
|
||||
#if 0
|
||||
extern bool scratch_buffer_grow_preserve (struct scratch_buffer *buffer);
|
||||
#endif
|
||||
|
||||
/* Grow *BUFFER so that it can store at least NELEM elements of SIZE
|
||||
bytes. The buffer contents are NOT preserved. Both NELEM and SIZE
|
||||
can be zero. Return true on success, false on allocation failure
|
||||
(in which case the old buffer is freed, but *BUFFER remains in a
|
||||
free-able state, and errno is set). It is unspecified whether this
|
||||
function can reduce the array size. */
|
||||
#if 0
|
||||
extern bool scratch_buffer_set_array_size (struct scratch_buffer *buffer,
|
||||
size_t nelem, size_t size);
|
||||
#endif
|
||||
|
||||
/* Return a copy of *BUFFER's first SIZE bytes as a heap-allocated block,
|
||||
deallocating *BUFFER if it was heap-allocated. SIZE must be at
|
||||
most *BUFFER's size. Return NULL (setting errno) on memory
|
||||
exhaustion. */
|
||||
#if 0
|
||||
extern void *scratch_buffer_dupfree (struct scratch_buffer *buffer,
|
||||
size_t size);
|
||||
#endif
|
||||
|
||||
|
||||
/* The implementation is imported from glibc. */
|
||||
|
||||
/* Avoid possible conflicts with symbols exported by the GNU libc. */
|
||||
#define __libc_scratch_buffer_dupfree gl_scratch_buffer_dupfree
|
||||
#define __libc_scratch_buffer_grow gl_scratch_buffer_grow
|
||||
#define __libc_scratch_buffer_grow_preserve gl_scratch_buffer_grow_preserve
|
||||
#define __libc_scratch_buffer_set_array_size gl_scratch_buffer_set_array_size
|
||||
|
||||
#ifndef _GL_LIKELY
|
||||
/* Rely on __builtin_expect, as provided by the module 'builtin-expect'. */
|
||||
# define _GL_LIKELY(cond) __builtin_expect ((cond), 1)
|
||||
# define _GL_UNLIKELY(cond) __builtin_expect ((cond), 0)
|
||||
#endif
|
||||
|
||||
#include <malloc/scratch_buffer.gl.h>
|
||||
|
||||
#endif /* _GL_SCRATCH_BUFFER_H */
|
||||
@@ -1,390 +0,0 @@
|
||||
/* Copyright (C) 1992, 1995-2003, 2005-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#if !_LIBC
|
||||
/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
|
||||
optimizes away the name == NULL test below. */
|
||||
# define _GL_ARG_NONNULL(params)
|
||||
|
||||
# define _GL_USE_STDLIB_ALLOC 1
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <alloca.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <errno.h>
|
||||
#ifndef __set_errno
|
||||
# define __set_errno(ev) ((errno) = (ev))
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#if _LIBC || HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if !_LIBC
|
||||
# include "malloca.h"
|
||||
#endif
|
||||
|
||||
#if _LIBC || !HAVE_SETENV
|
||||
|
||||
#if !_LIBC
|
||||
# define __environ environ
|
||||
#endif
|
||||
|
||||
#if _LIBC
|
||||
/* This lock protects against simultaneous modifications of 'environ'. */
|
||||
# include <bits/libc-lock.h>
|
||||
__libc_lock_define_initialized (static, envlock)
|
||||
# define LOCK __libc_lock_lock (envlock)
|
||||
# define UNLOCK __libc_lock_unlock (envlock)
|
||||
#else
|
||||
# define LOCK
|
||||
# define UNLOCK
|
||||
#endif
|
||||
|
||||
/* In the GNU C library we must keep the namespace clean. */
|
||||
#ifdef _LIBC
|
||||
# define setenv __setenv
|
||||
# define clearenv __clearenv
|
||||
# define tfind __tfind
|
||||
# define tsearch __tsearch
|
||||
#endif
|
||||
|
||||
/* In the GNU C library implementation we try to be more clever and
|
||||
allow arbitrarily many changes of the environment given that the used
|
||||
values are from a small set. Outside glibc this will eat up all
|
||||
memory after a while. */
|
||||
#if defined _LIBC || (defined HAVE_SEARCH_H && defined HAVE_TSEARCH \
|
||||
&& (defined __GNUC__ || defined __clang__))
|
||||
# define USE_TSEARCH 1
|
||||
# include <search.h>
|
||||
typedef int (*compar_fn_t) (const void *, const void *);
|
||||
|
||||
/* This is a pointer to the root of the search tree with the known
|
||||
values. */
|
||||
static void *known_values;
|
||||
|
||||
# define KNOWN_VALUE(Str) \
|
||||
({ \
|
||||
void *value = tfind (Str, &known_values, (compar_fn_t) strcmp); \
|
||||
value != NULL ? *(char **) value : NULL; \
|
||||
})
|
||||
# define STORE_VALUE(Str) \
|
||||
tsearch (Str, &known_values, (compar_fn_t) strcmp)
|
||||
|
||||
#else
|
||||
# undef USE_TSEARCH
|
||||
|
||||
# define KNOWN_VALUE(Str) NULL
|
||||
# define STORE_VALUE(Str) do { } while (0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* If this variable is not a null pointer we allocated the current
|
||||
environment. */
|
||||
static char **last_environ;
|
||||
|
||||
|
||||
/* This function is used by 'setenv' and 'putenv'. The difference between
|
||||
the two functions is that for the former must create a new string which
|
||||
is then placed in the environment, while the argument of 'putenv'
|
||||
must be used directly. This is all complicated by the fact that we try
|
||||
to reuse values once generated for a 'setenv' call since we can never
|
||||
free the strings. */
|
||||
int
|
||||
__add_to_environ (const char *name, const char *value, const char *combined,
|
||||
int replace)
|
||||
{
|
||||
char **ep;
|
||||
size_t size;
|
||||
const size_t namelen = strlen (name);
|
||||
const size_t vallen = value != NULL ? strlen (value) + 1 : 0;
|
||||
|
||||
LOCK;
|
||||
|
||||
/* We have to get the pointer now that we have the lock and not earlier
|
||||
since another thread might have created a new environment. */
|
||||
ep = __environ;
|
||||
|
||||
size = 0;
|
||||
if (ep != NULL)
|
||||
{
|
||||
for (; *ep != NULL; ++ep)
|
||||
if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=')
|
||||
break;
|
||||
else
|
||||
++size;
|
||||
}
|
||||
|
||||
if (ep == NULL || *ep == NULL)
|
||||
{
|
||||
char **new_environ;
|
||||
#ifdef USE_TSEARCH
|
||||
char *new_value;
|
||||
#endif
|
||||
|
||||
/* We allocated this space; we can extend it. */
|
||||
new_environ =
|
||||
(char **) (last_environ == NULL
|
||||
? malloc ((size + 2) * sizeof (char *))
|
||||
: realloc (last_environ, (size + 2) * sizeof (char *)));
|
||||
if (new_environ == NULL)
|
||||
{
|
||||
/* It's easier to set errno to ENOMEM than to rely on the
|
||||
'malloc-posix' and 'realloc-posix' gnulib modules. */
|
||||
__set_errno (ENOMEM);
|
||||
UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If the whole entry is given add it. */
|
||||
if (combined != NULL)
|
||||
/* We must not add the string to the search tree since it belongs
|
||||
to the user. */
|
||||
new_environ[size] = (char *) combined;
|
||||
else
|
||||
{
|
||||
/* See whether the value is already known. */
|
||||
#ifdef USE_TSEARCH
|
||||
# ifdef _LIBC
|
||||
new_value = (char *) alloca (namelen + 1 + vallen);
|
||||
__mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1),
|
||||
value, vallen);
|
||||
# else
|
||||
new_value = (char *) malloca (namelen + 1 + vallen);
|
||||
if (new_value == NULL)
|
||||
{
|
||||
__set_errno (ENOMEM);
|
||||
UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
memcpy (new_value, name, namelen);
|
||||
new_value[namelen] = '=';
|
||||
memcpy (&new_value[namelen + 1], value, vallen);
|
||||
# endif
|
||||
|
||||
new_environ[size] = KNOWN_VALUE (new_value);
|
||||
if (new_environ[size] == NULL)
|
||||
#endif
|
||||
{
|
||||
new_environ[size] = (char *) malloc (namelen + 1 + vallen);
|
||||
if (new_environ[size] == NULL)
|
||||
{
|
||||
#if defined USE_TSEARCH && !defined _LIBC
|
||||
freea (new_value);
|
||||
#endif
|
||||
__set_errno (ENOMEM);
|
||||
UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef USE_TSEARCH
|
||||
memcpy (new_environ[size], new_value, namelen + 1 + vallen);
|
||||
#else
|
||||
memcpy (new_environ[size], name, namelen);
|
||||
new_environ[size][namelen] = '=';
|
||||
memcpy (&new_environ[size][namelen + 1], value, vallen);
|
||||
#endif
|
||||
/* And save the value now. We cannot do this when we remove
|
||||
the string since then we cannot decide whether it is a
|
||||
user string or not. */
|
||||
STORE_VALUE (new_environ[size]);
|
||||
}
|
||||
#if defined USE_TSEARCH && !defined _LIBC
|
||||
freea (new_value);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (__environ != last_environ)
|
||||
memcpy ((char *) new_environ, (char *) __environ,
|
||||
size * sizeof (char *));
|
||||
|
||||
new_environ[size + 1] = NULL;
|
||||
|
||||
last_environ = __environ = new_environ;
|
||||
}
|
||||
else if (replace)
|
||||
{
|
||||
char *np;
|
||||
|
||||
/* Use the user string if given. */
|
||||
if (combined != NULL)
|
||||
np = (char *) combined;
|
||||
else
|
||||
{
|
||||
#ifdef USE_TSEARCH
|
||||
char *new_value;
|
||||
# ifdef _LIBC
|
||||
new_value = alloca (namelen + 1 + vallen);
|
||||
__mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1),
|
||||
value, vallen);
|
||||
# else
|
||||
new_value = malloca (namelen + 1 + vallen);
|
||||
if (new_value == NULL)
|
||||
{
|
||||
__set_errno (ENOMEM);
|
||||
UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
memcpy (new_value, name, namelen);
|
||||
new_value[namelen] = '=';
|
||||
memcpy (&new_value[namelen + 1], value, vallen);
|
||||
# endif
|
||||
|
||||
np = KNOWN_VALUE (new_value);
|
||||
if (np == NULL)
|
||||
#endif
|
||||
{
|
||||
np = (char *) malloc (namelen + 1 + vallen);
|
||||
if (np == NULL)
|
||||
{
|
||||
#if defined USE_TSEARCH && !defined _LIBC
|
||||
freea (new_value);
|
||||
#endif
|
||||
__set_errno (ENOMEM);
|
||||
UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef USE_TSEARCH
|
||||
memcpy (np, new_value, namelen + 1 + vallen);
|
||||
#else
|
||||
memcpy (np, name, namelen);
|
||||
np[namelen] = '=';
|
||||
memcpy (&np[namelen + 1], value, vallen);
|
||||
#endif
|
||||
/* And remember the value. */
|
||||
STORE_VALUE (np);
|
||||
}
|
||||
#if defined USE_TSEARCH && !defined _LIBC
|
||||
freea (new_value);
|
||||
#endif
|
||||
}
|
||||
|
||||
*ep = np;
|
||||
}
|
||||
|
||||
UNLOCK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
setenv (const char *name, const char *value, int replace)
|
||||
{
|
||||
if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
|
||||
{
|
||||
__set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return __add_to_environ (name, value, NULL, replace);
|
||||
}
|
||||
|
||||
/* The 'clearenv' was planned to be added to POSIX.1 but probably
|
||||
never made it. Nevertheless the POSIX.9 standard (POSIX bindings
|
||||
for Fortran 77) requires this function. */
|
||||
int
|
||||
clearenv (void)
|
||||
{
|
||||
LOCK;
|
||||
|
||||
if (__environ == last_environ && __environ != NULL)
|
||||
{
|
||||
/* We allocated this environment so we can free it. */
|
||||
free (__environ);
|
||||
last_environ = NULL;
|
||||
}
|
||||
|
||||
/* Clear the environment pointer removes the whole environment. */
|
||||
__environ = NULL;
|
||||
|
||||
UNLOCK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _LIBC
|
||||
static void
|
||||
free_mem (void)
|
||||
{
|
||||
/* Remove all traces. */
|
||||
clearenv ();
|
||||
|
||||
/* Now remove the search tree. */
|
||||
__tdestroy (known_values, free);
|
||||
known_values = NULL;
|
||||
}
|
||||
text_set_element (__libc_subfreeres, free_mem);
|
||||
|
||||
|
||||
# undef setenv
|
||||
# undef clearenv
|
||||
weak_alias (__setenv, setenv)
|
||||
weak_alias (__clearenv, clearenv)
|
||||
#endif
|
||||
|
||||
#endif /* _LIBC || !HAVE_SETENV */
|
||||
|
||||
/* The rest of this file is called into use when replacing an existing
|
||||
but buggy setenv. Known bugs include failure to diagnose invalid
|
||||
name, and consuming a leading '=' from value. */
|
||||
#if HAVE_SETENV
|
||||
|
||||
# undef setenv
|
||||
# if !HAVE_DECL_SETENV
|
||||
extern int setenv (const char *, const char *, int);
|
||||
# endif
|
||||
# define STREQ(a, b) (strcmp (a, b) == 0)
|
||||
|
||||
int
|
||||
rpl_setenv (const char *name, const char *value, int replace)
|
||||
{
|
||||
int result;
|
||||
if (!name || !*name || strchr (name, '='))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
/* Call the real setenv even if replace is 0, in case implementation
|
||||
has underlying data to update, such as when environ changes. */
|
||||
result = setenv (name, value, replace);
|
||||
if (result == 0 && replace && *value == '=')
|
||||
{
|
||||
char *tmp = getenv (name);
|
||||
if (!STREQ (tmp, value))
|
||||
{
|
||||
int saved_errno;
|
||||
size_t len = strlen (value);
|
||||
tmp = malloca (len + 2);
|
||||
/* Since leading '=' is eaten, double it up. */
|
||||
*tmp = '=';
|
||||
memcpy (tmp + 1, value, len + 1);
|
||||
result = setenv (name, tmp, replace);
|
||||
saved_errno = errno;
|
||||
freea (tmp);
|
||||
errno = saved_errno;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* HAVE_SETENV */
|
||||
@@ -1,994 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* A GNU-like <signal.h>.
|
||||
|
||||
Copyright (C) 2006-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
|
||||
#if defined __need_sig_atomic_t || defined __need_sigset_t || defined _GL_ALREADY_INCLUDING_SIGNAL_H || (defined _SIGNAL_H && !defined __SIZEOF_PTHREAD_MUTEX_T)
|
||||
/* Special invocation convention:
|
||||
- Inside glibc header files.
|
||||
- On glibc systems we have a sequence of nested includes
|
||||
<signal.h> -> <ucontext.h> -> <signal.h>.
|
||||
In this situation, the functions are not yet declared, therefore we cannot
|
||||
provide the C++ aliases.
|
||||
- On glibc systems with GCC 4.3 we have a sequence of nested includes
|
||||
<csignal> -> </usr/include/signal.h> -> <sys/ucontext.h> -> <signal.h>.
|
||||
In this situation, some of the functions are not yet declared, therefore
|
||||
we cannot provide the C++ aliases. */
|
||||
|
||||
# include_next <signal.h>
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
#ifndef _GL_SIGNAL_H
|
||||
|
||||
#define _GL_ALREADY_INCLUDING_SIGNAL_H
|
||||
|
||||
/* Define pid_t, uid_t.
|
||||
Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.
|
||||
On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes
|
||||
us; so include <sys/types.h> now, before the second inclusion guard. */
|
||||
#include <sys/types.h>
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
#include_next <signal.h>
|
||||
|
||||
#undef _GL_ALREADY_INCLUDING_SIGNAL_H
|
||||
|
||||
#ifndef _GL_SIGNAL_H
|
||||
#define _GL_SIGNAL_H
|
||||
|
||||
/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6, Android,
|
||||
OS/2 kLIBC declare pthread_sigmask in <pthread.h>, not in <signal.h>.
|
||||
But avoid namespace pollution on glibc systems.*/
|
||||
#if (0 || defined GNULIB_POSIXCHECK) \
|
||||
&& ((defined __APPLE__ && defined __MACH__) \
|
||||
|| defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ \
|
||||
|| defined __sun || defined __ANDROID__ || defined __KLIBC__) \
|
||||
&& ! defined __GLIBC__
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
/* C++ compatible function declaration macros.
|
||||
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GL_CXXDEFS_H
|
||||
#define _GL_CXXDEFS_H
|
||||
|
||||
/* Begin/end the GNULIB_NAMESPACE namespace. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
|
||||
# define _GL_END_NAMESPACE }
|
||||
#else
|
||||
# define _GL_BEGIN_NAMESPACE
|
||||
# define _GL_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
/* The three most frequent use cases of these macros are:
|
||||
|
||||
* For providing a substitute for a function that is missing on some
|
||||
platforms, but is declared and works fine on the platforms on which
|
||||
it exists:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if !@HAVE_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on all platforms,
|
||||
but is broken/insufficient and needs to be replaced on some platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on some platforms
|
||||
but is broken/insufficient and needs to be replaced on some of them and
|
||||
is additionally either missing or undeclared on some other platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
# if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
*/
|
||||
|
||||
/* _GL_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#if defined __cplusplus
|
||||
# define _GL_EXTERN_C extern "C"
|
||||
#else
|
||||
# define _GL_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
|
||||
declares a replacement function, named rpl_func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
|
||||
_GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
|
||||
#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype rpl_func parameters_and_attributes
|
||||
|
||||
/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
|
||||
declares the system function, named func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype func parameters_and_attributes
|
||||
|
||||
/* _GL_CXXALIAS_RPL (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
|
||||
|
||||
Wrapping rpl_func in an object with an inline conversion operator
|
||||
avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
|
||||
actually used in the program. */
|
||||
#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return ::rpl_func; \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||
is to be used when func is a Microsoft deprecated alias, on native Windows.
|
||||
It declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to _func, if GNULIB_NAMESPACE is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
|
||||
*/
|
||||
#define _GL_CXXALIAS_MDA(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_1 (func, _##func, rettype, parameters)
|
||||
|
||||
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
|
||||
except that the C function rpl_func may have a slightly different
|
||||
declaration. A cast is used to silence the "invalid conversion" error
|
||||
that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>(::rpl_func); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_MDA_CAST (func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||
except that the C function func may have a slightly different declaration.
|
||||
A cast is used to silence the "invalid conversion" error that would
|
||||
otherwise occur. */
|
||||
#define _GL_CXXALIAS_MDA_CAST(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_CAST_1 (func, _##func, rettype, parameters)
|
||||
|
||||
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to the system provided function func, if GNULIB_NAMESPACE
|
||||
is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
|
||||
|
||||
Wrapping func in an object with an inline conversion operator
|
||||
avoids a reference to func unless GNULIB_NAMESPACE::func is
|
||||
actually used in the program. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return ::func; \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function func may have a slightly different declaration.
|
||||
A cast is used to silence the "invalid conversion" error that would
|
||||
otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>(::func); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function is picked among a set of overloaded functions,
|
||||
namely the one with rettype2 and parameters2. Two consecutive casts
|
||||
are used to silence the "cannot find a match" and "invalid conversion"
|
||||
errors that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
/* The outer cast must be a reinterpret_cast.
|
||||
The inner cast: When the function is defined as a set of overloaded
|
||||
functions, it works as a static_cast<>, choosing the designated variant.
|
||||
When the function is defined as a single variant, it works as a
|
||||
reinterpret_cast<>. The parenthesized cast syntax works both ways. */
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN (func);
|
||||
causes a warning to be emitted when ::func is used but not when
|
||||
GNULIB_NAMESPACE::func is used. func must be defined without overloaded
|
||||
variants. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN_1(func,namespace) \
|
||||
_GL_CXXALIASWARN_2 (func, namespace)
|
||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_WARN_ON_USE (func, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
extern __typeof__ (func) func
|
||||
# else
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
|
||||
causes a warning to be emitted when the given overloaded variant of ::func
|
||||
is used but not when GNULIB_NAMESPACE::func is used. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
|
||||
GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
|
||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_WARN_ON_USE_CXX (func, rettype, rettype, parameters_and_attributes, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# else
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
#endif /* _GL_CXXDEFS_H */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
/* A C macro for declaring that specific arguments must not be NULL.
|
||||
Copyright (C) 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
|
||||
that the values passed as arguments n, ..., m must be non-NULL pointers.
|
||||
n = 1 stands for the first argument, n = 2 for the second argument etc. */
|
||||
#ifndef _GL_ARG_NONNULL
|
||||
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__
|
||||
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
|
||||
# else
|
||||
# define _GL_ARG_NONNULL(params)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
/* A C macro for emitting warnings if a function is used.
|
||||
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
|
||||
for FUNCTION which will then trigger a compiler warning containing
|
||||
the text of "literal string" anywhere that function is called, if
|
||||
supported by the compiler. If the compiler does not support this
|
||||
feature, the macro expands to an unused extern declaration.
|
||||
|
||||
_GL_WARN_ON_USE_ATTRIBUTE ("literal string") expands to the
|
||||
attribute used in _GL_WARN_ON_USE. If the compiler does not support
|
||||
this feature, it expands to empty.
|
||||
|
||||
These macros are useful for marking a function as a potential
|
||||
portability trap, with the intent that "literal string" include
|
||||
instructions on the replacement function that should be used
|
||||
instead.
|
||||
_GL_WARN_ON_USE is for functions with 'extern' linkage.
|
||||
_GL_WARN_ON_USE_ATTRIBUTE is for functions with 'static' or 'inline'
|
||||
linkage.
|
||||
|
||||
However, one of the reasons that a function is a portability trap is
|
||||
if it has the wrong signature. Declaring FUNCTION with a different
|
||||
signature in C is a compilation error, so this macro must use the
|
||||
same type as any existing declaration so that programs that avoid
|
||||
the problematic FUNCTION do not fail to compile merely because they
|
||||
included a header that poisoned the function. But this implies that
|
||||
_GL_WARN_ON_USE is only safe to use if FUNCTION is known to already
|
||||
have a declaration. Use of this macro implies that there must not
|
||||
be any other macro hiding the declaration of FUNCTION; but
|
||||
undefining FUNCTION first is part of the poisoning process anyway
|
||||
(although for symbols that are provided only via a macro, the result
|
||||
is a compilation error rather than a warning containing
|
||||
"literal string"). Also note that in C++, it is only safe to use if
|
||||
FUNCTION has no overloads.
|
||||
|
||||
For an example, it is possible to poison 'getline' by:
|
||||
- adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
|
||||
[getline]) in configure.ac, which potentially defines
|
||||
HAVE_RAW_DECL_GETLINE
|
||||
- adding this code to a header that wraps the system <stdio.h>:
|
||||
#undef getline
|
||||
#if HAVE_RAW_DECL_GETLINE
|
||||
_GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
|
||||
"not universally present; use the gnulib module getline");
|
||||
#endif
|
||||
|
||||
It is not possible to directly poison global variables. But it is
|
||||
possible to write a wrapper accessor function, and poison that
|
||||
(less common usage, like &environ, will cause a compilation error
|
||||
rather than issue the nice warning, but the end result of informing
|
||||
the developer about their portability problem is still achieved):
|
||||
#if HAVE_RAW_DECL_ENVIRON
|
||||
static char ***
|
||||
rpl_environ (void) { return &environ; }
|
||||
_GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
|
||||
# undef environ
|
||||
# define environ (*rpl_environ ())
|
||||
#endif
|
||||
or better (avoiding contradictory use of 'static' and 'extern'):
|
||||
#if HAVE_RAW_DECL_ENVIRON
|
||||
static char ***
|
||||
_GL_WARN_ON_USE_ATTRIBUTE ("environ is not always properly declared")
|
||||
rpl_environ (void) { return &environ; }
|
||||
# undef environ
|
||||
# define environ (*rpl_environ ())
|
||||
#endif
|
||||
*/
|
||||
#ifndef _GL_WARN_ON_USE
|
||||
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function __attribute__ ((__warning__ (message)))
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
||||
__attribute__ ((__warning__ (message)))
|
||||
# elif __clang_major__ >= 4
|
||||
/* Another compiler attribute is available in clang. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function \
|
||||
__attribute__ ((__diagnose_if__ (1, message, "warning")))
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
||||
__attribute__ ((__diagnose_if__ (1, message, "warning")))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message)
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_ON_USE_CXX (function, rettype_gcc, rettype_clang, parameters_and_attributes, "message")
|
||||
is like _GL_WARN_ON_USE (function, "message"), except that in C++ mode the
|
||||
function is declared with the given prototype, consisting of return type,
|
||||
parameters, and attributes.
|
||||
This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
|
||||
not work in this case. */
|
||||
#ifndef _GL_WARN_ON_USE_CXX
|
||||
# if !defined __cplusplus
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
_GL_WARN_ON_USE (function, msg)
|
||||
# else
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_gcc function parameters_and_attributes \
|
||||
__attribute__ ((__warning__ (msg)))
|
||||
# elif __clang_major__ >= 4
|
||||
/* Another compiler attribute is available in clang. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_clang function parameters_and_attributes \
|
||||
__attribute__ ((__diagnose_if__ (1, msg, "warning")))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_gcc function parameters_and_attributes
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#ifndef _GL_WARN_EXTERN_C
|
||||
# if defined __cplusplus
|
||||
# define _GL_WARN_EXTERN_C extern "C"
|
||||
# else
|
||||
# define _GL_WARN_EXTERN_C extern
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* On AIX, sig_atomic_t already includes volatile. C99 requires that
|
||||
'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
|
||||
Hence, redefine this to a non-volatile type as needed. */
|
||||
#if ! 1
|
||||
# if !GNULIB_defined_sig_atomic_t
|
||||
typedef int rpl_sig_atomic_t;
|
||||
# undef sig_atomic_t
|
||||
# define sig_atomic_t rpl_sig_atomic_t
|
||||
# define GNULIB_defined_sig_atomic_t 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* A set or mask of signals. */
|
||||
#if !1
|
||||
# if !GNULIB_defined_sigset_t
|
||||
typedef unsigned int sigset_t;
|
||||
# define GNULIB_defined_sigset_t 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Define sighandler_t, the type of signal handlers. A GNU extension. */
|
||||
#if !1
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
# if !GNULIB_defined_sighandler_t
|
||||
typedef void (*sighandler_t) (int);
|
||||
# define GNULIB_defined_sighandler_t 1
|
||||
# endif
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
# ifndef SIGPIPE
|
||||
/* Define SIGPIPE to a value that does not overlap with other signals. */
|
||||
# define SIGPIPE 13
|
||||
# define GNULIB_defined_SIGPIPE 1
|
||||
/* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
|
||||
'write', 'stdio'. */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Maximum signal number + 1. */
|
||||
#ifndef NSIG
|
||||
# if defined __TANDEM
|
||||
# define NSIG 32
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
# if 0
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef pthread_sigmask
|
||||
# define pthread_sigmask rpl_pthread_sigmask
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (pthread_sigmask, int,
|
||||
(int how,
|
||||
const sigset_t *restrict new_mask,
|
||||
sigset_t *restrict old_mask));
|
||||
_GL_CXXALIAS_RPL (pthread_sigmask, int,
|
||||
(int how,
|
||||
const sigset_t *restrict new_mask,
|
||||
sigset_t *restrict old_mask));
|
||||
# else
|
||||
# if !(1 || defined pthread_sigmask)
|
||||
_GL_FUNCDECL_SYS (pthread_sigmask, int,
|
||||
(int how,
|
||||
const sigset_t *restrict new_mask,
|
||||
sigset_t *restrict old_mask));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (pthread_sigmask, int,
|
||||
(int how,
|
||||
const sigset_t *restrict new_mask,
|
||||
sigset_t *restrict old_mask));
|
||||
# endif
|
||||
# if __GLIBC__ >= 2
|
||||
_GL_CXXALIASWARN (pthread_sigmask);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef pthread_sigmask
|
||||
# if HAVE_RAW_DECL_PTHREAD_SIGMASK
|
||||
_GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
|
||||
"use gnulib module pthread_sigmask for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
# if 0
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef raise
|
||||
# define raise rpl_raise
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (raise, int, (int sig));
|
||||
_GL_CXXALIAS_RPL (raise, int, (int sig));
|
||||
# else
|
||||
# if !1
|
||||
_GL_FUNCDECL_SYS (raise, int, (int sig));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (raise, int, (int sig));
|
||||
# endif
|
||||
# if __GLIBC__ >= 2
|
||||
_GL_CXXALIASWARN (raise);
|
||||
# endif
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef raise
|
||||
/* Assume raise is always declared. */
|
||||
_GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
|
||||
"use gnulib module raise for portability");
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
# if !1
|
||||
|
||||
# ifndef GNULIB_defined_signal_blocking
|
||||
# define GNULIB_defined_signal_blocking 1
|
||||
# endif
|
||||
|
||||
/* Maximum signal number + 1. */
|
||||
# ifndef NSIG
|
||||
# define NSIG 32
|
||||
# endif
|
||||
|
||||
/* This code supports only 32 signals. */
|
||||
# if !GNULIB_defined_verify_NSIG_constraint
|
||||
typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
|
||||
# define GNULIB_defined_verify_NSIG_constraint 1
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
/* When also using extern inline, suppress the use of static inline in
|
||||
standard headers of problematic Apple configurations, as Libc at
|
||||
least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
|
||||
<https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html>.
|
||||
Perhaps Apple will fix this some day. */
|
||||
#if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
|
||||
&& (defined __i386__ || defined __x86_64__))
|
||||
# undef sigaddset
|
||||
# undef sigdelset
|
||||
# undef sigemptyset
|
||||
# undef sigfillset
|
||||
# undef sigismember
|
||||
#endif
|
||||
|
||||
/* Test whether a given signal is contained in a signal set. */
|
||||
# if 1
|
||||
/* This function is defined as a macro on Mac OS X. */
|
||||
# if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# undef sigismember
|
||||
# endif
|
||||
# else
|
||||
_GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
|
||||
_GL_CXXALIASWARN (sigismember);
|
||||
|
||||
/* Initialize a signal set to the empty set. */
|
||||
# if 1
|
||||
/* This function is defined as a macro on Mac OS X. */
|
||||
# if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# undef sigemptyset
|
||||
# endif
|
||||
# else
|
||||
_GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
|
||||
_GL_CXXALIASWARN (sigemptyset);
|
||||
|
||||
/* Add a signal to a signal set. */
|
||||
# if 1
|
||||
/* This function is defined as a macro on Mac OS X. */
|
||||
# if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# undef sigaddset
|
||||
# endif
|
||||
# else
|
||||
_GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
|
||||
_GL_CXXALIASWARN (sigaddset);
|
||||
|
||||
/* Remove a signal from a signal set. */
|
||||
# if 1
|
||||
/* This function is defined as a macro on Mac OS X. */
|
||||
# if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# undef sigdelset
|
||||
# endif
|
||||
# else
|
||||
_GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
|
||||
_GL_CXXALIASWARN (sigdelset);
|
||||
|
||||
/* Fill a signal set with all possible signals. */
|
||||
# if 1
|
||||
/* This function is defined as a macro on Mac OS X. */
|
||||
# if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# undef sigfillset
|
||||
# endif
|
||||
# else
|
||||
_GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
|
||||
_GL_CXXALIASWARN (sigfillset);
|
||||
|
||||
/* Return the set of those blocked signals that are pending. */
|
||||
# if !1
|
||||
_GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
|
||||
_GL_CXXALIASWARN (sigpending);
|
||||
|
||||
/* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
|
||||
Then, if SET is not NULL, affect the current set of blocked signals by
|
||||
combining it with *SET as indicated in OPERATION.
|
||||
In this implementation, you are not allowed to change a signal handler
|
||||
while the signal is blocked. */
|
||||
# if !1
|
||||
# define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
|
||||
# define SIG_SETMASK 1 /* blocked_set = *set; */
|
||||
# define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
|
||||
_GL_FUNCDECL_SYS (sigprocmask, int,
|
||||
(int operation,
|
||||
const sigset_t *restrict set,
|
||||
sigset_t *restrict old_set));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (sigprocmask, int,
|
||||
(int operation,
|
||||
const sigset_t *restrict set,
|
||||
sigset_t *restrict old_set));
|
||||
_GL_CXXALIASWARN (sigprocmask);
|
||||
|
||||
/* Install the handler FUNC for signal SIG, and return the previous
|
||||
handler. */
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
# if !GNULIB_defined_function_taking_int_returning_void_t
|
||||
typedef void (*_gl_function_taking_int_returning_void_t) (int);
|
||||
# define GNULIB_defined_function_taking_int_returning_void_t 1
|
||||
# endif
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
# if !1
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define signal rpl_signal
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
|
||||
(int sig, _gl_function_taking_int_returning_void_t func));
|
||||
_GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
|
||||
(int sig, _gl_function_taking_int_returning_void_t func));
|
||||
# else
|
||||
/* On OpenBSD, the declaration of 'signal' may not be present at this point,
|
||||
because it occurs in <sys/signal.h>, not <signal.h> directly. */
|
||||
# if defined __OpenBSD__
|
||||
_GL_FUNCDECL_SYS (signal, _gl_function_taking_int_returning_void_t,
|
||||
(int sig, _gl_function_taking_int_returning_void_t func));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
|
||||
(int sig, _gl_function_taking_int_returning_void_t func));
|
||||
# endif
|
||||
# if __GLIBC__ >= 2
|
||||
_GL_CXXALIASWARN (signal);
|
||||
# endif
|
||||
|
||||
# if !1 && GNULIB_defined_SIGPIPE
|
||||
/* Raise signal SIGPIPE. */
|
||||
_GL_EXTERN_C int _gl_raise_SIGPIPE (void);
|
||||
# endif
|
||||
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef sigaddset
|
||||
# if HAVE_RAW_DECL_SIGADDSET
|
||||
_GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
|
||||
"use the gnulib module sigprocmask for portability");
|
||||
# endif
|
||||
# undef sigdelset
|
||||
# if HAVE_RAW_DECL_SIGDELSET
|
||||
_GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
|
||||
"use the gnulib module sigprocmask for portability");
|
||||
# endif
|
||||
# undef sigemptyset
|
||||
# if HAVE_RAW_DECL_SIGEMPTYSET
|
||||
_GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
|
||||
"use the gnulib module sigprocmask for portability");
|
||||
# endif
|
||||
# undef sigfillset
|
||||
# if HAVE_RAW_DECL_SIGFILLSET
|
||||
_GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
|
||||
"use the gnulib module sigprocmask for portability");
|
||||
# endif
|
||||
# undef sigismember
|
||||
# if HAVE_RAW_DECL_SIGISMEMBER
|
||||
_GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
|
||||
"use the gnulib module sigprocmask for portability");
|
||||
# endif
|
||||
# undef sigpending
|
||||
# if HAVE_RAW_DECL_SIGPENDING
|
||||
_GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
|
||||
"use the gnulib module sigprocmask for portability");
|
||||
# endif
|
||||
# undef sigprocmask
|
||||
# if HAVE_RAW_DECL_SIGPROCMASK
|
||||
_GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
|
||||
"use the gnulib module sigprocmask for portability");
|
||||
# endif
|
||||
#endif /* 1 */
|
||||
|
||||
|
||||
#if 0
|
||||
# if !1
|
||||
|
||||
# if !1
|
||||
|
||||
# if !GNULIB_defined_siginfo_types
|
||||
|
||||
/* Present to allow compilation, but unsupported by gnulib. */
|
||||
union sigval
|
||||
{
|
||||
int sival_int;
|
||||
void *sival_ptr;
|
||||
};
|
||||
|
||||
/* Present to allow compilation, but unsupported by gnulib. */
|
||||
struct siginfo_t
|
||||
{
|
||||
int si_signo;
|
||||
int si_code;
|
||||
int si_errno;
|
||||
pid_t si_pid;
|
||||
uid_t si_uid;
|
||||
void *si_addr;
|
||||
int si_status;
|
||||
long si_band;
|
||||
union sigval si_value;
|
||||
};
|
||||
typedef struct siginfo_t siginfo_t;
|
||||
|
||||
# define GNULIB_defined_siginfo_types 1
|
||||
# endif
|
||||
|
||||
# endif /* !1 */
|
||||
|
||||
/* We assume that platforms which lack the sigaction() function also lack
|
||||
the 'struct sigaction' type, and vice versa. */
|
||||
|
||||
# if !GNULIB_defined_struct_sigaction
|
||||
|
||||
struct sigaction
|
||||
{
|
||||
union
|
||||
{
|
||||
void (*_sa_handler) (int);
|
||||
/* Present to allow compilation, but unsupported by gnulib. POSIX
|
||||
says that implementations may, but not must, make sa_sigaction
|
||||
overlap with sa_handler, but we know of no implementation where
|
||||
they do not overlap. */
|
||||
void (*_sa_sigaction) (int, siginfo_t *, void *);
|
||||
} _sa_func;
|
||||
sigset_t sa_mask;
|
||||
/* Not all POSIX flags are supported. */
|
||||
int sa_flags;
|
||||
};
|
||||
# define sa_handler _sa_func._sa_handler
|
||||
# define sa_sigaction _sa_func._sa_sigaction
|
||||
/* Unsupported flags are not present. */
|
||||
# define SA_RESETHAND 1
|
||||
# define SA_NODEFER 2
|
||||
# define SA_RESTART 4
|
||||
|
||||
# define GNULIB_defined_struct_sigaction 1
|
||||
# endif
|
||||
|
||||
_GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
|
||||
struct sigaction *restrict));
|
||||
|
||||
# elif !1
|
||||
|
||||
# define sa_sigaction sa_handler
|
||||
|
||||
# endif /* !1, !1 */
|
||||
|
||||
_GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
|
||||
struct sigaction *restrict));
|
||||
_GL_CXXALIASWARN (sigaction);
|
||||
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
# undef sigaction
|
||||
# if HAVE_RAW_DECL_SIGACTION
|
||||
_GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
|
||||
"use the gnulib module sigaction for portability");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some systems don't have SA_NODEFER. */
|
||||
#ifndef SA_NODEFER
|
||||
# define SA_NODEFER 0
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _GL_SIGNAL_H */
|
||||
#endif /* _GL_SIGNAL_H */
|
||||
#endif
|
||||
@@ -1,349 +0,0 @@
|
||||
/* POSIX compatible signal blocking.
|
||||
Copyright (C) 2006-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2006.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <signal.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
# include "msvc-inval.h"
|
||||
#endif
|
||||
|
||||
/* We assume that a platform without POSIX signal blocking functions
|
||||
also does not have the POSIX sigaction() function, only the
|
||||
signal() function. We also assume signal() has SysV semantics,
|
||||
where any handler is uninstalled prior to being invoked. This is
|
||||
true for native Windows platforms. */
|
||||
|
||||
/* We use raw signal(), but also provide a wrapper rpl_signal() so
|
||||
that applications can query or change a blocked signal. */
|
||||
#undef signal
|
||||
|
||||
/* Provide invalid signal numbers as fallbacks if the uncatchable
|
||||
signals are not defined. */
|
||||
#ifndef SIGKILL
|
||||
# define SIGKILL (-1)
|
||||
#endif
|
||||
#ifndef SIGSTOP
|
||||
# define SIGSTOP (-1)
|
||||
#endif
|
||||
|
||||
/* On native Windows, as of 2008, the signal SIGABRT_COMPAT is an alias
|
||||
for the signal SIGABRT. Only one signal handler is stored for both
|
||||
SIGABRT and SIGABRT_COMPAT. SIGABRT_COMPAT is not a signal of its own. */
|
||||
#if defined _WIN32 && ! defined __CYGWIN__
|
||||
# undef SIGABRT_COMPAT
|
||||
# define SIGABRT_COMPAT 6
|
||||
#endif
|
||||
#ifdef SIGABRT_COMPAT
|
||||
# define SIGABRT_COMPAT_MASK (1U << SIGABRT_COMPAT)
|
||||
#else
|
||||
# define SIGABRT_COMPAT_MASK 0
|
||||
#endif
|
||||
|
||||
typedef void (*handler_t) (int);
|
||||
|
||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||
static handler_t
|
||||
signal_nothrow (int sig, handler_t handler)
|
||||
{
|
||||
handler_t result;
|
||||
|
||||
TRY_MSVC_INVAL
|
||||
{
|
||||
result = signal (sig, handler);
|
||||
}
|
||||
CATCH_MSVC_INVAL
|
||||
{
|
||||
result = SIG_ERR;
|
||||
errno = EINVAL;
|
||||
}
|
||||
DONE_MSVC_INVAL;
|
||||
|
||||
return result;
|
||||
}
|
||||
# define signal signal_nothrow
|
||||
#endif
|
||||
|
||||
/* Handling of gnulib defined signals. */
|
||||
|
||||
#if GNULIB_defined_SIGPIPE
|
||||
static handler_t SIGPIPE_handler = SIG_DFL;
|
||||
#endif
|
||||
|
||||
#if GNULIB_defined_SIGPIPE
|
||||
static handler_t
|
||||
ext_signal (int sig, handler_t handler)
|
||||
{
|
||||
switch (sig)
|
||||
{
|
||||
case SIGPIPE:
|
||||
{
|
||||
handler_t old_handler = SIGPIPE_handler;
|
||||
SIGPIPE_handler = handler;
|
||||
return old_handler;
|
||||
}
|
||||
default: /* System defined signal */
|
||||
return signal (sig, handler);
|
||||
}
|
||||
}
|
||||
# undef signal
|
||||
# define signal ext_signal
|
||||
#endif
|
||||
|
||||
int
|
||||
sigismember (const sigset_t *set, int sig)
|
||||
{
|
||||
if (sig >= 0 && sig < NSIG)
|
||||
{
|
||||
#ifdef SIGABRT_COMPAT
|
||||
if (sig == SIGABRT_COMPAT)
|
||||
sig = SIGABRT;
|
||||
#endif
|
||||
|
||||
return (*set >> sig) & 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sigemptyset (sigset_t *set)
|
||||
{
|
||||
*set = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sigaddset (sigset_t *set, int sig)
|
||||
{
|
||||
if (sig >= 0 && sig < NSIG)
|
||||
{
|
||||
#ifdef SIGABRT_COMPAT
|
||||
if (sig == SIGABRT_COMPAT)
|
||||
sig = SIGABRT;
|
||||
#endif
|
||||
|
||||
*set |= 1U << sig;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
sigdelset (sigset_t *set, int sig)
|
||||
{
|
||||
if (sig >= 0 && sig < NSIG)
|
||||
{
|
||||
#ifdef SIGABRT_COMPAT
|
||||
if (sig == SIGABRT_COMPAT)
|
||||
sig = SIGABRT;
|
||||
#endif
|
||||
|
||||
*set &= ~(1U << sig);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
sigfillset (sigset_t *set)
|
||||
{
|
||||
*set = ((2U << (NSIG - 1)) - 1) & ~ SIGABRT_COMPAT_MASK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set of currently blocked signals. */
|
||||
static volatile sigset_t blocked_set /* = 0 */;
|
||||
|
||||
/* Set of currently blocked and pending signals. */
|
||||
static volatile sig_atomic_t pending_array[NSIG] /* = { 0 } */;
|
||||
|
||||
/* Signal handler that is installed for blocked signals. */
|
||||
static void
|
||||
blocked_handler (int sig)
|
||||
{
|
||||
/* Reinstall the handler, in case the signal occurs multiple times
|
||||
while blocked. There is an inherent race where an asynchronous
|
||||
signal in between when the kernel uninstalled the handler and
|
||||
when we reinstall it will trigger the default handler; oh
|
||||
well. */
|
||||
signal (sig, blocked_handler);
|
||||
if (sig >= 0 && sig < NSIG)
|
||||
pending_array[sig] = 1;
|
||||
}
|
||||
|
||||
int
|
||||
sigpending (sigset_t *set)
|
||||
{
|
||||
sigset_t pending = 0;
|
||||
int sig;
|
||||
|
||||
for (sig = 0; sig < NSIG; sig++)
|
||||
if (pending_array[sig])
|
||||
pending |= 1U << sig;
|
||||
*set = pending;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The previous signal handlers.
|
||||
Only the array elements corresponding to blocked signals are relevant. */
|
||||
static volatile handler_t old_handlers[NSIG];
|
||||
|
||||
int
|
||||
sigprocmask (int operation, const sigset_t *set, sigset_t *old_set)
|
||||
{
|
||||
if (old_set != NULL)
|
||||
*old_set = blocked_set;
|
||||
|
||||
if (set != NULL)
|
||||
{
|
||||
sigset_t new_blocked_set;
|
||||
sigset_t to_unblock;
|
||||
sigset_t to_block;
|
||||
|
||||
switch (operation)
|
||||
{
|
||||
case SIG_BLOCK:
|
||||
new_blocked_set = blocked_set | *set;
|
||||
break;
|
||||
case SIG_SETMASK:
|
||||
new_blocked_set = *set;
|
||||
break;
|
||||
case SIG_UNBLOCK:
|
||||
new_blocked_set = blocked_set & ~*set;
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
to_unblock = blocked_set & ~new_blocked_set;
|
||||
to_block = new_blocked_set & ~blocked_set;
|
||||
|
||||
if (to_block != 0)
|
||||
{
|
||||
int sig;
|
||||
|
||||
for (sig = 0; sig < NSIG; sig++)
|
||||
if ((to_block >> sig) & 1)
|
||||
{
|
||||
pending_array[sig] = 0;
|
||||
if ((old_handlers[sig] = signal (sig, blocked_handler)) != SIG_ERR)
|
||||
blocked_set |= 1U << sig;
|
||||
}
|
||||
}
|
||||
|
||||
if (to_unblock != 0)
|
||||
{
|
||||
sig_atomic_t received[NSIG];
|
||||
int sig;
|
||||
|
||||
for (sig = 0; sig < NSIG; sig++)
|
||||
if ((to_unblock >> sig) & 1)
|
||||
{
|
||||
if (signal (sig, old_handlers[sig]) != blocked_handler)
|
||||
/* The application changed a signal handler while the signal
|
||||
was blocked, bypassing our rpl_signal replacement.
|
||||
We don't support this. */
|
||||
abort ();
|
||||
received[sig] = pending_array[sig];
|
||||
blocked_set &= ~(1U << sig);
|
||||
pending_array[sig] = 0;
|
||||
}
|
||||
else
|
||||
received[sig] = 0;
|
||||
|
||||
for (sig = 0; sig < NSIG; sig++)
|
||||
if (received[sig])
|
||||
raise (sig);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Install the handler FUNC for signal SIG, and return the previous
|
||||
handler. */
|
||||
handler_t
|
||||
rpl_signal (int sig, handler_t handler)
|
||||
{
|
||||
/* We must provide a wrapper, so that a user can query what handler
|
||||
they installed even if that signal is currently blocked. */
|
||||
if (sig >= 0 && sig < NSIG && sig != SIGKILL && sig != SIGSTOP
|
||||
&& handler != SIG_ERR)
|
||||
{
|
||||
#ifdef SIGABRT_COMPAT
|
||||
if (sig == SIGABRT_COMPAT)
|
||||
sig = SIGABRT;
|
||||
#endif
|
||||
|
||||
if (blocked_set & (1U << sig))
|
||||
{
|
||||
/* POSIX states that sigprocmask and signal are both
|
||||
async-signal-safe. This is not true of our
|
||||
implementation - there is a slight data race where an
|
||||
asynchronous interrupt on signal A can occur after we
|
||||
install blocked_handler but before we have updated
|
||||
old_handlers for signal B, such that handler A can see
|
||||
stale information if it calls signal(B). Oh well -
|
||||
signal handlers really shouldn't try to manipulate the
|
||||
installed handlers of unrelated signals. */
|
||||
handler_t result = old_handlers[sig];
|
||||
old_handlers[sig] = handler;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return signal (sig, handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = EINVAL;
|
||||
return SIG_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
#if GNULIB_defined_SIGPIPE
|
||||
/* Raise the signal SIGPIPE. */
|
||||
int
|
||||
_gl_raise_SIGPIPE (void)
|
||||
{
|
||||
if (blocked_set & (1U << SIGPIPE))
|
||||
pending_array[SIGPIPE] = 1;
|
||||
else
|
||||
{
|
||||
handler_t handler = SIGPIPE_handler;
|
||||
if (handler == SIG_DFL)
|
||||
exit (128 + SIGPIPE);
|
||||
else if (handler != SIG_IGN)
|
||||
(*handler) (SIGPIPE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,252 +0,0 @@
|
||||
/* stat-related time functions.
|
||||
|
||||
Copyright (C) 2005, 2007, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#ifndef STAT_TIME_H
|
||||
#define STAT_TIME_H 1
|
||||
|
||||
#include "intprops.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef _GL_INLINE_HEADER_BEGIN
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef _GL_STAT_TIME_INLINE
|
||||
# define _GL_STAT_TIME_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* STAT_TIMESPEC (ST, ST_XTIM) is the ST_XTIM member for *ST of type
|
||||
struct timespec, if available. If not, then STAT_TIMESPEC_NS (ST,
|
||||
ST_XTIM) is the nanosecond component of the ST_XTIM member for *ST,
|
||||
if available. ST_XTIM can be st_atim, st_ctim, st_mtim, or st_birthtim
|
||||
for access, status change, data modification, or birth (creation)
|
||||
time respectively.
|
||||
|
||||
These macros are private to stat-time.h. */
|
||||
#if _GL_WINDOWS_STAT_TIMESPEC || defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
|
||||
# if _GL_WINDOWS_STAT_TIMESPEC || defined TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC
|
||||
# define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim)
|
||||
# else
|
||||
# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.tv_nsec)
|
||||
# endif
|
||||
#elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC
|
||||
# define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim##espec)
|
||||
#elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC
|
||||
# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim##ensec)
|
||||
#elif defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC
|
||||
# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.st__tim.tv_nsec)
|
||||
#endif
|
||||
|
||||
/* Return the nanosecond component of *ST's access time. */
|
||||
_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
|
||||
get_stat_atime_ns (struct stat const *st)
|
||||
{
|
||||
# if defined STAT_TIMESPEC
|
||||
return STAT_TIMESPEC (st, st_atim).tv_nsec;
|
||||
# elif defined STAT_TIMESPEC_NS
|
||||
return STAT_TIMESPEC_NS (st, st_atim);
|
||||
# else
|
||||
return 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
/* Return the nanosecond component of *ST's status change time. */
|
||||
_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
|
||||
get_stat_ctime_ns (struct stat const *st)
|
||||
{
|
||||
# if defined STAT_TIMESPEC
|
||||
return STAT_TIMESPEC (st, st_ctim).tv_nsec;
|
||||
# elif defined STAT_TIMESPEC_NS
|
||||
return STAT_TIMESPEC_NS (st, st_ctim);
|
||||
# else
|
||||
return 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
/* Return the nanosecond component of *ST's data modification time. */
|
||||
_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
|
||||
get_stat_mtime_ns (struct stat const *st)
|
||||
{
|
||||
# if defined STAT_TIMESPEC
|
||||
return STAT_TIMESPEC (st, st_mtim).tv_nsec;
|
||||
# elif defined STAT_TIMESPEC_NS
|
||||
return STAT_TIMESPEC_NS (st, st_mtim);
|
||||
# else
|
||||
return 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
/* Return the nanosecond component of *ST's birth time. */
|
||||
_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
|
||||
get_stat_birthtime_ns (_GL_UNUSED struct stat const *st)
|
||||
{
|
||||
# if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
|
||||
return STAT_TIMESPEC (st, st_birthtim).tv_nsec;
|
||||
# elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
|
||||
return STAT_TIMESPEC_NS (st, st_birthtim);
|
||||
# else
|
||||
return 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
/* Return *ST's access time. */
|
||||
_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
|
||||
get_stat_atime (struct stat const *st)
|
||||
{
|
||||
#ifdef STAT_TIMESPEC
|
||||
return STAT_TIMESPEC (st, st_atim);
|
||||
#else
|
||||
struct timespec t;
|
||||
t.tv_sec = st->st_atime;
|
||||
t.tv_nsec = get_stat_atime_ns (st);
|
||||
return t;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Return *ST's status change time. */
|
||||
_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
|
||||
get_stat_ctime (struct stat const *st)
|
||||
{
|
||||
#ifdef STAT_TIMESPEC
|
||||
return STAT_TIMESPEC (st, st_ctim);
|
||||
#else
|
||||
struct timespec t;
|
||||
t.tv_sec = st->st_ctime;
|
||||
t.tv_nsec = get_stat_ctime_ns (st);
|
||||
return t;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Return *ST's data modification time. */
|
||||
_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
|
||||
get_stat_mtime (struct stat const *st)
|
||||
{
|
||||
#ifdef STAT_TIMESPEC
|
||||
return STAT_TIMESPEC (st, st_mtim);
|
||||
#else
|
||||
struct timespec t;
|
||||
t.tv_sec = st->st_mtime;
|
||||
t.tv_nsec = get_stat_mtime_ns (st);
|
||||
return t;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Return *ST's birth time, if available; otherwise return a value
|
||||
with tv_sec and tv_nsec both equal to -1. */
|
||||
_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
|
||||
get_stat_birthtime (_GL_UNUSED struct stat const *st)
|
||||
{
|
||||
struct timespec t;
|
||||
|
||||
#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
|
||||
|| defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
|
||||
t = STAT_TIMESPEC (st, st_birthtim);
|
||||
#elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
|
||||
t.tv_sec = st->st_birthtime;
|
||||
t.tv_nsec = st->st_birthtimensec;
|
||||
#elif defined _WIN32 && ! defined __CYGWIN__
|
||||
/* Native Windows platforms (but not Cygwin) put the "file creation
|
||||
time" in st_ctime (!). See
|
||||
<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions>. */
|
||||
# if _GL_WINDOWS_STAT_TIMESPEC
|
||||
t = st->st_ctim;
|
||||
# else
|
||||
t.tv_sec = st->st_ctime;
|
||||
t.tv_nsec = 0;
|
||||
# endif
|
||||
#else
|
||||
/* Birth time is not supported. */
|
||||
t.tv_sec = -1;
|
||||
t.tv_nsec = -1;
|
||||
#endif
|
||||
|
||||
#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
|
||||
|| defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC \
|
||||
|| defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
|
||||
/* FreeBSD and NetBSD sometimes signal the absence of knowledge by
|
||||
using zero. Attempt to work around this problem. Alas, this can
|
||||
report failure even for valid timestamps. Also, NetBSD
|
||||
sometimes returns junk in the birth time fields; work around this
|
||||
bug if it is detected. */
|
||||
if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000))
|
||||
{
|
||||
t.tv_sec = -1;
|
||||
t.tv_nsec = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/* If a stat-like function returned RESULT, normalize the timestamps
|
||||
in *ST, in case this platform suffers from the Solaris 11 bug where
|
||||
tv_nsec might be negative. Return the adjusted RESULT, setting
|
||||
errno to EOVERFLOW if normalization overflowed. This function
|
||||
is intended to be private to this .h file. */
|
||||
_GL_STAT_TIME_INLINE int
|
||||
stat_time_normalize (int result, _GL_UNUSED struct stat *st)
|
||||
{
|
||||
#if defined __sun && defined STAT_TIMESPEC
|
||||
if (result == 0)
|
||||
{
|
||||
long int timespec_hz = 1000000000;
|
||||
short int const ts_off[] = { offsetof (struct stat, st_atim),
|
||||
offsetof (struct stat, st_mtim),
|
||||
offsetof (struct stat, st_ctim) };
|
||||
int i;
|
||||
for (i = 0; i < sizeof ts_off / sizeof *ts_off; i++)
|
||||
{
|
||||
struct timespec *ts = (struct timespec *) ((char *) st + ts_off[i]);
|
||||
long int q = ts->tv_nsec / timespec_hz;
|
||||
long int r = ts->tv_nsec % timespec_hz;
|
||||
if (r < 0)
|
||||
{
|
||||
r += timespec_hz;
|
||||
q--;
|
||||
}
|
||||
ts->tv_nsec = r;
|
||||
/* Overflow is possible, as Solaris 11 stat can yield
|
||||
tv_sec == TYPE_MINIMUM (time_t) && tv_nsec == -1000000000.
|
||||
INT_ADD_WRAPV is OK, since time_t is signed on Solaris. */
|
||||
if (INT_ADD_WRAPV (q, ts->tv_sec, &ts->tv_sec))
|
||||
{
|
||||
errno = EOVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif
|
||||
@@ -1,461 +0,0 @@
|
||||
/* Core of implementation of fstat and stat for native Windows.
|
||||
Copyright (C) 2017-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Bruno Haible. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined _WIN32 && ! defined __CYGWIN__
|
||||
|
||||
/* Attempt to make <windows.h> define FILE_ID_INFO.
|
||||
But ensure that the redefinition of _WIN32_WINNT does not make us assume
|
||||
Windows Vista or newer when building for an older version of Windows. */
|
||||
#if HAVE_SDKDDKVER_H
|
||||
# include <sdkddkver.h>
|
||||
# if _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
||||
# define WIN32_ASSUME_VISTA 1
|
||||
# else
|
||||
# define WIN32_ASSUME_VISTA 0
|
||||
# endif
|
||||
# if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN8)
|
||||
# undef _WIN32_WINNT
|
||||
# define _WIN32_WINNT _WIN32_WINNT_WIN8
|
||||
# endif
|
||||
#else
|
||||
# define WIN32_ASSUME_VISTA (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <windows.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "stat-w32.h"
|
||||
|
||||
#include "pathmax.h"
|
||||
#include "verify.h"
|
||||
|
||||
/* Don't assume that UNICODE is not defined. */
|
||||
#undef LoadLibrary
|
||||
#define LoadLibrary LoadLibraryA
|
||||
#undef GetFinalPathNameByHandle
|
||||
#define GetFinalPathNameByHandle GetFinalPathNameByHandleA
|
||||
|
||||
/* Older mingw headers do not define VOLUME_NAME_NONE. */
|
||||
#ifndef VOLUME_NAME_NONE
|
||||
# define VOLUME_NAME_NONE 4
|
||||
#endif
|
||||
|
||||
#if !WIN32_ASSUME_VISTA
|
||||
|
||||
/* Avoid warnings from gcc -Wcast-function-type. */
|
||||
# define GetProcAddress \
|
||||
(void *) GetProcAddress
|
||||
|
||||
# if _GL_WINDOWS_STAT_INODES == 2
|
||||
/* GetFileInformationByHandleEx was introduced only in Windows Vista. */
|
||||
typedef DWORD (WINAPI * GetFileInformationByHandleExFuncType) (HANDLE hFile,
|
||||
FILE_INFO_BY_HANDLE_CLASS fiClass,
|
||||
LPVOID lpBuffer,
|
||||
DWORD dwBufferSize);
|
||||
static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = NULL;
|
||||
# endif
|
||||
/* GetFinalPathNameByHandle was introduced only in Windows Vista. */
|
||||
typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile,
|
||||
LPSTR lpFilePath,
|
||||
DWORD lenFilePath,
|
||||
DWORD dwFlags);
|
||||
static GetFinalPathNameByHandleFuncType GetFinalPathNameByHandleFunc = NULL;
|
||||
static BOOL initialized = FALSE;
|
||||
|
||||
static void
|
||||
initialize (void)
|
||||
{
|
||||
HMODULE kernel32 = LoadLibrary ("kernel32.dll");
|
||||
if (kernel32 != NULL)
|
||||
{
|
||||
# if _GL_WINDOWS_STAT_INODES == 2
|
||||
GetFileInformationByHandleExFunc =
|
||||
(GetFileInformationByHandleExFuncType) GetProcAddress (kernel32, "GetFileInformationByHandleEx");
|
||||
# endif
|
||||
GetFinalPathNameByHandleFunc =
|
||||
(GetFinalPathNameByHandleFuncType) GetProcAddress (kernel32, "GetFinalPathNameByHandleA");
|
||||
}
|
||||
initialized = TRUE;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
# define GetFileInformationByHandleExFunc GetFileInformationByHandleEx
|
||||
# define GetFinalPathNameByHandleFunc GetFinalPathNameByHandle
|
||||
|
||||
#endif
|
||||
|
||||
/* Converts a FILETIME to GMT time since 1970-01-01 00:00:00. */
|
||||
#if _GL_WINDOWS_STAT_TIMESPEC
|
||||
struct timespec
|
||||
_gl_convert_FILETIME_to_timespec (const FILETIME *ft)
|
||||
{
|
||||
struct timespec result;
|
||||
/* FILETIME: <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime> */
|
||||
unsigned long long since_1601 =
|
||||
((unsigned long long) ft->dwHighDateTime << 32)
|
||||
| (unsigned long long) ft->dwLowDateTime;
|
||||
if (since_1601 == 0)
|
||||
{
|
||||
result.tv_sec = 0;
|
||||
result.tv_nsec = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89
|
||||
leap years, in total 134774 days. */
|
||||
unsigned long long since_1970 =
|
||||
since_1601 - (unsigned long long) 134774 * (unsigned long long) 86400 * (unsigned long long) 10000000;
|
||||
result.tv_sec = since_1970 / (unsigned long long) 10000000;
|
||||
result.tv_nsec = (unsigned long) (since_1970 % (unsigned long long) 10000000) * 100;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
time_t
|
||||
_gl_convert_FILETIME_to_POSIX (const FILETIME *ft)
|
||||
{
|
||||
/* FILETIME: <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime> */
|
||||
unsigned long long since_1601 =
|
||||
((unsigned long long) ft->dwHighDateTime << 32)
|
||||
| (unsigned long long) ft->dwLowDateTime;
|
||||
if (since_1601 == 0)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
/* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89
|
||||
leap years, in total 134774 days. */
|
||||
unsigned long long since_1970 =
|
||||
since_1601 - (unsigned long long) 134774 * (unsigned long long) 86400 * (unsigned long long) 10000000;
|
||||
return since_1970 / (unsigned long long) 10000000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Fill *BUF with information about the file designated by H.
|
||||
PATH is the file name, if known, otherwise NULL.
|
||||
Return 0 if successful, or -1 with errno set upon failure. */
|
||||
int
|
||||
_gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf)
|
||||
{
|
||||
/* GetFileType
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfiletype> */
|
||||
DWORD type = GetFileType (h);
|
||||
if (type == FILE_TYPE_DISK)
|
||||
{
|
||||
#if !WIN32_ASSUME_VISTA
|
||||
if (!initialized)
|
||||
initialize ();
|
||||
#endif
|
||||
|
||||
/* st_mode can be determined through
|
||||
GetFileAttributesEx
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data>
|
||||
or through
|
||||
GetFileInformationByHandle
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
|
||||
or through
|
||||
GetFileInformationByHandleEx with argument FileBasicInfo
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_basic_info>
|
||||
The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
|
||||
BY_HANDLE_FILE_INFORMATION info;
|
||||
if (! GetFileInformationByHandle (h, &info))
|
||||
goto failed;
|
||||
|
||||
/* Test for error conditions before starting to fill *buf. */
|
||||
if (sizeof (buf->st_size) <= 4 && info.nFileSizeHigh > 0)
|
||||
{
|
||||
errno = EOVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if _GL_WINDOWS_STAT_INODES
|
||||
/* st_ino can be determined through
|
||||
GetFileInformationByHandle
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
|
||||
as 64 bits, or through
|
||||
GetFileInformationByHandleEx with argument FileIdInfo
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_id_info>
|
||||
as 128 bits.
|
||||
The latter requires -D_WIN32_WINNT=_WIN32_WINNT_WIN8 or higher. */
|
||||
/* Experiments show that GetFileInformationByHandleEx does not provide
|
||||
much more information than GetFileInformationByHandle:
|
||||
* The dwVolumeSerialNumber from GetFileInformationByHandle is equal
|
||||
to the low 32 bits of the 64-bit VolumeSerialNumber from
|
||||
GetFileInformationByHandleEx, and is apparently sufficient for
|
||||
identifying the device.
|
||||
* The nFileIndex from GetFileInformationByHandle is equal to the low
|
||||
64 bits of the 128-bit FileId from GetFileInformationByHandleEx,
|
||||
and the high 64 bits of this 128-bit FileId are zero.
|
||||
* On a FAT file system, GetFileInformationByHandleEx fails with error
|
||||
ERROR_INVALID_PARAMETER, whereas GetFileInformationByHandle
|
||||
succeeds.
|
||||
* On a CIFS/SMB file system, GetFileInformationByHandleEx fails with
|
||||
error ERROR_INVALID_LEVEL, whereas GetFileInformationByHandle
|
||||
succeeds. */
|
||||
# if _GL_WINDOWS_STAT_INODES == 2
|
||||
if (GetFileInformationByHandleExFunc != NULL)
|
||||
{
|
||||
FILE_ID_INFO id;
|
||||
if (GetFileInformationByHandleExFunc (h, FileIdInfo, &id, sizeof (id)))
|
||||
{
|
||||
buf->st_dev = id.VolumeSerialNumber;
|
||||
verify (sizeof (ino_t) == sizeof (id.FileId));
|
||||
memcpy (&buf->st_ino, &id.FileId, sizeof (ino_t));
|
||||
goto ino_done;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (GetLastError ())
|
||||
{
|
||||
case ERROR_INVALID_PARAMETER: /* older Windows version, or FAT */
|
||||
case ERROR_INVALID_LEVEL: /* CIFS/SMB file system */
|
||||
goto fallback;
|
||||
default:
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
fallback: ;
|
||||
/* Fallback for older Windows versions. */
|
||||
buf->st_dev = info.dwVolumeSerialNumber;
|
||||
buf->st_ino._gl_ino[0] = ((ULONGLONG) info.nFileIndexHigh << 32) | (ULONGLONG) info.nFileIndexLow;
|
||||
buf->st_ino._gl_ino[1] = 0;
|
||||
ino_done: ;
|
||||
# else /* _GL_WINDOWS_STAT_INODES == 1 */
|
||||
buf->st_dev = info.dwVolumeSerialNumber;
|
||||
buf->st_ino = ((ULONGLONG) info.nFileIndexHigh << 32) | (ULONGLONG) info.nFileIndexLow;
|
||||
# endif
|
||||
#else
|
||||
/* st_ino is not wide enough for identifying a file on a device.
|
||||
Without st_ino, st_dev is pointless. */
|
||||
buf->st_dev = 0;
|
||||
buf->st_ino = 0;
|
||||
#endif
|
||||
|
||||
/* st_mode. */
|
||||
unsigned int mode =
|
||||
/* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ? */
|
||||
((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR | S_IEXEC_UGO : _S_IFREG)
|
||||
| S_IREAD_UGO
|
||||
| ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWRITE_UGO);
|
||||
if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
/* Determine whether the file is executable by looking at the file
|
||||
name suffix.
|
||||
If the file name is already known, use it. Otherwise, for
|
||||
non-empty files, it can be determined through
|
||||
GetFinalPathNameByHandle
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea>
|
||||
or through
|
||||
GetFileInformationByHandleEx with argument FileNameInfo
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_name_info>
|
||||
Both require -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
|
||||
if (info.nFileSizeHigh > 0 || info.nFileSizeLow > 0)
|
||||
{
|
||||
char fpath[PATH_MAX];
|
||||
if (path != NULL
|
||||
|| (GetFinalPathNameByHandleFunc != NULL
|
||||
&& GetFinalPathNameByHandleFunc (h, fpath, sizeof (fpath), VOLUME_NAME_NONE)
|
||||
< sizeof (fpath)
|
||||
&& (path = fpath, 1)))
|
||||
{
|
||||
const char *last_dot = NULL;
|
||||
const char *p;
|
||||
for (p = path; *p != '\0'; p++)
|
||||
if (*p == '.')
|
||||
last_dot = p;
|
||||
if (last_dot != NULL)
|
||||
{
|
||||
const char *suffix = last_dot + 1;
|
||||
if (_stricmp (suffix, "exe") == 0
|
||||
|| _stricmp (suffix, "bat") == 0
|
||||
|| _stricmp (suffix, "cmd") == 0
|
||||
|| _stricmp (suffix, "com") == 0)
|
||||
mode |= S_IEXEC_UGO;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* Cannot determine file name. Pretend that it is executable. */
|
||||
mode |= S_IEXEC_UGO;
|
||||
}
|
||||
}
|
||||
buf->st_mode = mode;
|
||||
|
||||
/* st_nlink can be determined through
|
||||
GetFileInformationByHandle
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
|
||||
or through
|
||||
GetFileInformationByHandleEx with argument FileStandardInfo
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_standard_info>
|
||||
The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
|
||||
buf->st_nlink = (info.nNumberOfLinks > SHRT_MAX ? SHRT_MAX : info.nNumberOfLinks);
|
||||
|
||||
/* There's no easy way to map the Windows SID concept to an integer. */
|
||||
buf->st_uid = 0;
|
||||
buf->st_gid = 0;
|
||||
|
||||
/* st_rdev is irrelevant for normal files and directories. */
|
||||
buf->st_rdev = 0;
|
||||
|
||||
/* st_size can be determined through
|
||||
GetFileSizeEx
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfilesizeex>
|
||||
or through
|
||||
GetFileAttributesEx
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data>
|
||||
or through
|
||||
GetFileInformationByHandle
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
|
||||
or through
|
||||
GetFileInformationByHandleEx with argument FileStandardInfo
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_standard_info>
|
||||
The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
|
||||
if (sizeof (buf->st_size) <= 4)
|
||||
/* Range check already done above. */
|
||||
buf->st_size = info.nFileSizeLow;
|
||||
else
|
||||
buf->st_size = ((long long) info.nFileSizeHigh << 32) | (long long) info.nFileSizeLow;
|
||||
|
||||
/* st_atime, st_mtime, st_ctime can be determined through
|
||||
GetFileTime
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfiletime>
|
||||
or through
|
||||
GetFileAttributesEx
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data>
|
||||
or through
|
||||
GetFileInformationByHandle
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
|
||||
or through
|
||||
GetFileInformationByHandleEx with argument FileBasicInfo
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_basic_info>
|
||||
The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
|
||||
#if _GL_WINDOWS_STAT_TIMESPEC
|
||||
buf->st_atim = _gl_convert_FILETIME_to_timespec (&info.ftLastAccessTime);
|
||||
buf->st_mtim = _gl_convert_FILETIME_to_timespec (&info.ftLastWriteTime);
|
||||
buf->st_ctim = _gl_convert_FILETIME_to_timespec (&info.ftCreationTime);
|
||||
#else
|
||||
buf->st_atime = _gl_convert_FILETIME_to_POSIX (&info.ftLastAccessTime);
|
||||
buf->st_mtime = _gl_convert_FILETIME_to_POSIX (&info.ftLastWriteTime);
|
||||
buf->st_ctime = _gl_convert_FILETIME_to_POSIX (&info.ftCreationTime);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (type == FILE_TYPE_CHAR || type == FILE_TYPE_PIPE)
|
||||
{
|
||||
buf->st_dev = 0;
|
||||
#if _GL_WINDOWS_STAT_INODES == 2
|
||||
buf->st_ino._gl_ino[0] = buf->st_ino._gl_ino[1] = 0;
|
||||
#else
|
||||
buf->st_ino = 0;
|
||||
#endif
|
||||
buf->st_mode = (type == FILE_TYPE_PIPE ? _S_IFIFO : _S_IFCHR);
|
||||
buf->st_nlink = 1;
|
||||
buf->st_uid = 0;
|
||||
buf->st_gid = 0;
|
||||
buf->st_rdev = 0;
|
||||
if (type == FILE_TYPE_PIPE)
|
||||
{
|
||||
/* PeekNamedPipe
|
||||
<https://msdn.microsoft.com/en-us/library/aa365779.aspx> */
|
||||
DWORD bytes_available;
|
||||
if (PeekNamedPipe (h, NULL, 0, NULL, &bytes_available, NULL))
|
||||
buf->st_size = bytes_available;
|
||||
else
|
||||
buf->st_size = 0;
|
||||
}
|
||||
else
|
||||
buf->st_size = 0;
|
||||
#if _GL_WINDOWS_STAT_TIMESPEC
|
||||
buf->st_atim.tv_sec = 0; buf->st_atim.tv_nsec = 0;
|
||||
buf->st_mtim.tv_sec = 0; buf->st_mtim.tv_nsec = 0;
|
||||
buf->st_ctim.tv_sec = 0; buf->st_ctim.tv_nsec = 0;
|
||||
#else
|
||||
buf->st_atime = 0;
|
||||
buf->st_mtime = 0;
|
||||
buf->st_ctime = 0;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
failed:
|
||||
{
|
||||
DWORD error = GetLastError ();
|
||||
#if 0
|
||||
fprintf (stderr, "_gl_fstat_by_handle error 0x%x\n", (unsigned int) error);
|
||||
#endif
|
||||
switch (error)
|
||||
{
|
||||
case ERROR_ACCESS_DENIED:
|
||||
case ERROR_SHARING_VIOLATION:
|
||||
errno = EACCES;
|
||||
break;
|
||||
|
||||
case ERROR_OUTOFMEMORY:
|
||||
errno = ENOMEM;
|
||||
break;
|
||||
|
||||
case ERROR_WRITE_FAULT:
|
||||
case ERROR_READ_FAULT:
|
||||
case ERROR_GEN_FAILURE:
|
||||
errno = EIO;
|
||||
break;
|
||||
|
||||
default:
|
||||
errno = EINVAL;
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* This declaration is solely to ensure that after preprocessing
|
||||
this file is never empty. */
|
||||
typedef int dummy;
|
||||
|
||||
#endif
|
||||
@@ -1,37 +0,0 @@
|
||||
/* Core of implementation of fstat and stat for native Windows.
|
||||
Copyright (C) 2017-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _STAT_W32_H
|
||||
#define _STAT_W32_H 1
|
||||
|
||||
/* Converts a FILETIME to GMT time since 1970-01-01 00:00:00. */
|
||||
#if _GL_WINDOWS_STAT_TIMESPEC
|
||||
extern struct timespec _gl_convert_FILETIME_to_timespec (const FILETIME *ft);
|
||||
#else
|
||||
extern time_t _gl_convert_FILETIME_to_POSIX (const FILETIME *ft);
|
||||
#endif
|
||||
|
||||
/* Fill *BUF with information about the file designated by H.
|
||||
PATH is the file name, if known, otherwise NULL.
|
||||
Return 0 if successful, or -1 with errno set upon failure. */
|
||||
extern int _gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf);
|
||||
|
||||
/* Bitmasks for st_mode. */
|
||||
#define S_IREAD_UGO (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6))
|
||||
#define S_IWRITE_UGO (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))
|
||||
#define S_IEXEC_UGO (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6))
|
||||
|
||||
#endif /* _STAT_W32_H */
|
||||
@@ -1,440 +0,0 @@
|
||||
/* Work around platform bugs in stat.
|
||||
Copyright (C) 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Eric Blake and Bruno Haible. */
|
||||
|
||||
/* If the user's config.h happens to include <sys/stat.h>, let it include only
|
||||
the system's <sys/stat.h> here, so that orig_stat doesn't recurse to
|
||||
rpl_stat. */
|
||||
#define __need_system_sys_stat_h
|
||||
#include <config.h>
|
||||
|
||||
/* Get the original definition of stat. It might be defined as a macro. */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#undef __need_system_sys_stat_h
|
||||
|
||||
#if defined _WIN32 && ! defined __CYGWIN__
|
||||
# define WINDOWS_NATIVE
|
||||
#endif
|
||||
|
||||
#if !defined WINDOWS_NATIVE
|
||||
|
||||
static int
|
||||
orig_stat (const char *filename, struct stat *buf)
|
||||
{
|
||||
return stat (filename, buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#ifdef __osf__
|
||||
/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
|
||||
eliminates this include because of the preliminary #include <sys/stat.h>
|
||||
above. */
|
||||
# include "sys/stat.h"
|
||||
#else
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include "stat-time.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "filename.h"
|
||||
#include "malloca.h"
|
||||
#include "verify.h"
|
||||
|
||||
#ifdef WINDOWS_NATIVE
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# include "stat-w32.h"
|
||||
/* Don't assume that UNICODE is not defined. */
|
||||
# undef WIN32_FIND_DATA
|
||||
# define WIN32_FIND_DATA WIN32_FIND_DATAA
|
||||
# undef CreateFile
|
||||
# define CreateFile CreateFileA
|
||||
# undef FindFirstFile
|
||||
# define FindFirstFile FindFirstFileA
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_NATIVE
|
||||
/* Return TRUE if the given file name denotes an UNC root. */
|
||||
static BOOL
|
||||
is_unc_root (const char *rname)
|
||||
{
|
||||
/* Test whether it has the syntax '\\server\share'. */
|
||||
if (ISSLASH (rname[0]) && ISSLASH (rname[1]))
|
||||
{
|
||||
/* It starts with two slashes. Find the next slash. */
|
||||
const char *p = rname + 2;
|
||||
const char *q = p;
|
||||
while (*q != '\0' && !ISSLASH (*q))
|
||||
q++;
|
||||
if (q > p && *q != '\0')
|
||||
{
|
||||
/* Found the next slash at q. */
|
||||
q++;
|
||||
const char *r = q;
|
||||
while (*r != '\0' && !ISSLASH (*r))
|
||||
r++;
|
||||
if (r > q && *r == '\0')
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Store information about NAME into ST. Work around bugs with
|
||||
trailing slashes. Mingw has other bugs (such as st_ino always
|
||||
being 0 on success) which this wrapper does not work around. But
|
||||
at least this implementation provides the ability to emulate fchdir
|
||||
correctly. */
|
||||
|
||||
int
|
||||
rpl_stat (char const *name, struct stat *buf)
|
||||
{
|
||||
#ifdef WINDOWS_NATIVE
|
||||
/* Fill the fields ourselves, because the original stat function returns
|
||||
values for st_atime, st_mtime, st_ctime that depend on the current time
|
||||
zone. See
|
||||
<https://lists.gnu.org/r/bug-gnulib/2017-04/msg00134.html> */
|
||||
/* XXX Should we convert to wchar_t* and prepend '\\?\', in order to work
|
||||
around length limitations
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file> ? */
|
||||
|
||||
/* POSIX <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>
|
||||
specifies: "More than two leading <slash> characters shall be treated as
|
||||
a single <slash> character." */
|
||||
if (ISSLASH (name[0]) && ISSLASH (name[1]) && ISSLASH (name[2]))
|
||||
{
|
||||
name += 2;
|
||||
while (ISSLASH (name[1]))
|
||||
name++;
|
||||
}
|
||||
|
||||
size_t len = strlen (name);
|
||||
size_t drive_prefix_len = (HAS_DEVICE (name) ? 2 : 0);
|
||||
|
||||
/* Remove trailing slashes (except the very first one, at position
|
||||
drive_prefix_len), but remember their presence. */
|
||||
size_t rlen;
|
||||
bool check_dir = false;
|
||||
|
||||
rlen = len;
|
||||
while (rlen > drive_prefix_len && ISSLASH (name[rlen-1]))
|
||||
{
|
||||
check_dir = true;
|
||||
if (rlen == drive_prefix_len + 1)
|
||||
break;
|
||||
rlen--;
|
||||
}
|
||||
|
||||
/* Handle '' and 'C:'. */
|
||||
if (!check_dir && rlen == drive_prefix_len)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Handle '\\'. */
|
||||
if (rlen == 1 && ISSLASH (name[0]) && len >= 2)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *rname;
|
||||
char *malloca_rname;
|
||||
if (rlen == len)
|
||||
{
|
||||
rname = name;
|
||||
malloca_rname = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
malloca_rname = malloca (rlen + 1);
|
||||
if (malloca_rname == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
memcpy (malloca_rname, name, rlen);
|
||||
malloca_rname[rlen] = '\0';
|
||||
rname = malloca_rname;
|
||||
}
|
||||
|
||||
/* There are two ways to get at the requested information:
|
||||
- by scanning the parent directory and examining the relevant
|
||||
directory entry,
|
||||
- by opening the file directly.
|
||||
The first approach fails for root directories (e.g. 'C:\') and
|
||||
UNC root directories (e.g. '\\server\share').
|
||||
The second approach fails for some system files (e.g. 'C:\pagefile.sys'
|
||||
and 'C:\hiberfil.sys'): ERROR_SHARING_VIOLATION.
|
||||
The second approach gives more information (in particular, correct
|
||||
st_dev, st_ino, st_nlink fields).
|
||||
So we use the second approach and, as a fallback except for root and
|
||||
UNC root directories, also the first approach. */
|
||||
{
|
||||
int ret;
|
||||
|
||||
{
|
||||
/* Approach based on the file. */
|
||||
|
||||
/* Open a handle to the file.
|
||||
CreateFile
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-createfilea>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/FileIO/creating-and-opening-files> */
|
||||
HANDLE h =
|
||||
CreateFile (rname,
|
||||
FILE_READ_ATTRIBUTES,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
/* FILE_FLAG_POSIX_SEMANTICS (treat file names that differ only
|
||||
in case as different) makes sense only when applied to *all*
|
||||
filesystem operations. */
|
||||
FILE_FLAG_BACKUP_SEMANTICS /* | FILE_FLAG_POSIX_SEMANTICS */,
|
||||
NULL);
|
||||
if (h != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ret = _gl_fstat_by_handle (h, rname, buf);
|
||||
CloseHandle (h);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Test for root and UNC root directories. */
|
||||
if ((rlen == drive_prefix_len + 1 && ISSLASH (rname[drive_prefix_len]))
|
||||
|| is_unc_root (rname))
|
||||
goto failed;
|
||||
|
||||
/* Fallback. */
|
||||
{
|
||||
/* Approach based on the directory entry. */
|
||||
|
||||
if (strchr (rname, '?') != NULL || strchr (rname, '*') != NULL)
|
||||
{
|
||||
/* Other Windows API functions would fail with error
|
||||
ERROR_INVALID_NAME. */
|
||||
if (malloca_rname != NULL)
|
||||
freea (malloca_rname);
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Get the details about the directory entry. This can be done through
|
||||
FindFirstFile
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilea>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-_win32_find_dataa>
|
||||
or through
|
||||
FindFirstFileEx with argument FindExInfoBasic
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfileexa>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ne-minwinbase-findex_info_levels>
|
||||
<https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-_win32_find_dataa> */
|
||||
WIN32_FIND_DATA info;
|
||||
HANDLE h = FindFirstFile (rname, &info);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
goto failed;
|
||||
|
||||
/* Test for error conditions before starting to fill *buf. */
|
||||
if (sizeof (buf->st_size) <= 4 && info.nFileSizeHigh > 0)
|
||||
{
|
||||
FindClose (h);
|
||||
if (malloca_rname != NULL)
|
||||
freea (malloca_rname);
|
||||
errno = EOVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
|
||||
# if _GL_WINDOWS_STAT_INODES
|
||||
buf->st_dev = 0;
|
||||
# if _GL_WINDOWS_STAT_INODES == 2
|
||||
buf->st_ino._gl_ino[0] = buf->st_ino._gl_ino[1] = 0;
|
||||
# else /* _GL_WINDOWS_STAT_INODES == 1 */
|
||||
buf->st_ino = 0;
|
||||
# endif
|
||||
# else
|
||||
/* st_ino is not wide enough for identifying a file on a device.
|
||||
Without st_ino, st_dev is pointless. */
|
||||
buf->st_dev = 0;
|
||||
buf->st_ino = 0;
|
||||
# endif
|
||||
|
||||
/* st_mode. */
|
||||
unsigned int mode =
|
||||
/* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ? */
|
||||
((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR | S_IEXEC_UGO : _S_IFREG)
|
||||
| S_IREAD_UGO
|
||||
| ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWRITE_UGO);
|
||||
if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
/* Determine whether the file is executable by looking at the file
|
||||
name suffix. */
|
||||
if (info.nFileSizeHigh > 0 || info.nFileSizeLow > 0)
|
||||
{
|
||||
const char *last_dot = NULL;
|
||||
const char *p;
|
||||
for (p = info.cFileName; *p != '\0'; p++)
|
||||
if (*p == '.')
|
||||
last_dot = p;
|
||||
if (last_dot != NULL)
|
||||
{
|
||||
const char *suffix = last_dot + 1;
|
||||
if (_stricmp (suffix, "exe") == 0
|
||||
|| _stricmp (suffix, "bat") == 0
|
||||
|| _stricmp (suffix, "cmd") == 0
|
||||
|| _stricmp (suffix, "com") == 0)
|
||||
mode |= S_IEXEC_UGO;
|
||||
}
|
||||
}
|
||||
}
|
||||
buf->st_mode = mode;
|
||||
|
||||
/* st_nlink. Ignore hard links here. */
|
||||
buf->st_nlink = 1;
|
||||
|
||||
/* There's no easy way to map the Windows SID concept to an integer. */
|
||||
buf->st_uid = 0;
|
||||
buf->st_gid = 0;
|
||||
|
||||
/* st_rdev is irrelevant for normal files and directories. */
|
||||
buf->st_rdev = 0;
|
||||
|
||||
/* st_size. */
|
||||
if (sizeof (buf->st_size) <= 4)
|
||||
/* Range check already done above. */
|
||||
buf->st_size = info.nFileSizeLow;
|
||||
else
|
||||
buf->st_size = ((long long) info.nFileSizeHigh << 32) | (long long) info.nFileSizeLow;
|
||||
|
||||
/* st_atime, st_mtime, st_ctime. */
|
||||
# if _GL_WINDOWS_STAT_TIMESPEC
|
||||
buf->st_atim = _gl_convert_FILETIME_to_timespec (&info.ftLastAccessTime);
|
||||
buf->st_mtim = _gl_convert_FILETIME_to_timespec (&info.ftLastWriteTime);
|
||||
buf->st_ctim = _gl_convert_FILETIME_to_timespec (&info.ftCreationTime);
|
||||
# else
|
||||
buf->st_atime = _gl_convert_FILETIME_to_POSIX (&info.ftLastAccessTime);
|
||||
buf->st_mtime = _gl_convert_FILETIME_to_POSIX (&info.ftLastWriteTime);
|
||||
buf->st_ctime = _gl_convert_FILETIME_to_POSIX (&info.ftCreationTime);
|
||||
# endif
|
||||
|
||||
FindClose (h);
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
done:
|
||||
if (ret >= 0 && check_dir && !S_ISDIR (buf->st_mode))
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
ret = -1;
|
||||
}
|
||||
if (malloca_rname != NULL)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
freea (malloca_rname);
|
||||
errno = saved_errno;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
failed:
|
||||
{
|
||||
DWORD error = GetLastError ();
|
||||
#if 0
|
||||
fprintf (stderr, "rpl_stat error 0x%x\n", (unsigned int) error);
|
||||
#endif
|
||||
|
||||
if (malloca_rname != NULL)
|
||||
freea (malloca_rname);
|
||||
|
||||
switch (error)
|
||||
{
|
||||
/* Some of these errors probably cannot happen with the specific flags
|
||||
that we pass to CreateFile. But who knows... */
|
||||
case ERROR_FILE_NOT_FOUND: /* The last component of rname does not exist. */
|
||||
case ERROR_PATH_NOT_FOUND: /* Some directory component in rname does not exist. */
|
||||
case ERROR_BAD_PATHNAME: /* rname is such as '\\server'. */
|
||||
case ERROR_BAD_NET_NAME: /* rname is such as '\\server\nonexistentshare'. */
|
||||
case ERROR_INVALID_NAME: /* rname contains wildcards, misplaced colon, etc. */
|
||||
case ERROR_DIRECTORY:
|
||||
errno = ENOENT;
|
||||
break;
|
||||
|
||||
case ERROR_ACCESS_DENIED: /* rname is such as 'C:\System Volume Information\foo'. */
|
||||
case ERROR_SHARING_VIOLATION: /* rname is such as 'C:\pagefile.sys' (second approach only). */
|
||||
/* XXX map to EACCES or EPERM? */
|
||||
errno = EACCES;
|
||||
break;
|
||||
|
||||
case ERROR_OUTOFMEMORY:
|
||||
errno = ENOMEM;
|
||||
break;
|
||||
|
||||
case ERROR_WRITE_PROTECT:
|
||||
errno = EROFS;
|
||||
break;
|
||||
|
||||
case ERROR_WRITE_FAULT:
|
||||
case ERROR_READ_FAULT:
|
||||
case ERROR_GEN_FAILURE:
|
||||
errno = EIO;
|
||||
break;
|
||||
|
||||
case ERROR_BUFFER_OVERFLOW:
|
||||
case ERROR_FILENAME_EXCED_RANGE:
|
||||
errno = ENAMETOOLONG;
|
||||
break;
|
||||
|
||||
case ERROR_DELETE_PENDING: /* XXX map to EACCES or EPERM? */
|
||||
errno = EPERM;
|
||||
break;
|
||||
|
||||
default:
|
||||
errno = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
int result = orig_stat (name, buf);
|
||||
if (result == 0)
|
||||
{
|
||||
# if REPLACE_FUNC_STAT_FILE
|
||||
/* Solaris 9 mistakenly succeeds when given a non-directory with a
|
||||
trailing slash. */
|
||||
if (!S_ISDIR (buf->st_mode))
|
||||
{
|
||||
size_t len = strlen (name);
|
||||
if (ISSLASH (name[len - 1]))
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
# endif /* REPLACE_FUNC_STAT_FILE */
|
||||
result = stat_time_normalize (result, buf);
|
||||
}
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
@@ -1,741 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* Copyright (C) 2001-2002, 2004-2022 Free Software Foundation, Inc.
|
||||
Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood.
|
||||
This file is part of gnulib.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/*
|
||||
* ISO C 99 <stdint.h> for platforms that lack it.
|
||||
* <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdint.h.html>
|
||||
*/
|
||||
|
||||
#ifndef _GL_STDINT_H
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
|
||||
/* When including a system file that in turn includes <inttypes.h>,
|
||||
use the system <inttypes.h>, not our substitute. This avoids
|
||||
problems with (for example) VMS, whose <sys/bitypes.h> includes
|
||||
<inttypes.h>. */
|
||||
#define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
|
||||
|
||||
/* On Android (Bionic libc), <sys/types.h> includes this file before
|
||||
having defined 'time_t'. Therefore in this case avoid including
|
||||
other system header files; just include the system's <stdint.h>.
|
||||
Ideally we should test __BIONIC__ here, but it is only defined after
|
||||
<sys/cdefs.h> has been included; hence test __ANDROID__ instead. */
|
||||
#if defined __ANDROID__ && defined _GL_INCLUDING_SYS_TYPES_H
|
||||
# include_next <stdint.h>
|
||||
#else
|
||||
|
||||
/* Get those types that are already defined in other system include
|
||||
files, so that we can "#define int8_t signed char" below without
|
||||
worrying about a later system include file containing a "typedef
|
||||
signed char int8_t;" that will get messed up by our macro. Our
|
||||
macros should all be consistent with the system versions, except
|
||||
for the "fast" types and macros, which we recommend against using
|
||||
in public interfaces due to compiler differences. */
|
||||
|
||||
#if 1
|
||||
# if defined __sgi && ! defined __c99
|
||||
/* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users
|
||||
with "This header file is to be used only for c99 mode compilations"
|
||||
diagnostics. */
|
||||
# define __STDINT_H__
|
||||
# endif
|
||||
|
||||
/* Some pre-C++11 <stdint.h> implementations need this. */
|
||||
# ifdef __cplusplus
|
||||
# ifndef __STDC_CONSTANT_MACROS
|
||||
# define __STDC_CONSTANT_MACROS 1
|
||||
# endif
|
||||
# ifndef __STDC_LIMIT_MACROS
|
||||
# define __STDC_LIMIT_MACROS 1
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Other systems may have an incomplete or buggy <stdint.h>.
|
||||
Include it before <inttypes.h>, since any "#include <stdint.h>"
|
||||
in <inttypes.h> would reinclude us, skipping our contents because
|
||||
_GL_STDINT_H is defined.
|
||||
The include_next requires a split double-inclusion guard. */
|
||||
# include_next <stdint.h>
|
||||
#endif
|
||||
|
||||
#if ! defined _GL_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
|
||||
#define _GL_STDINT_H
|
||||
|
||||
/* Get SCHAR_MIN, SCHAR_MAX, UCHAR_MAX, INT_MIN, INT_MAX,
|
||||
LONG_MIN, LONG_MAX, ULONG_MAX, _GL_INTEGER_WIDTH. */
|
||||
#include <limits.h>
|
||||
|
||||
/* Override WINT_MIN and WINT_MAX if gnulib's <wchar.h> or <wctype.h> overrides
|
||||
wint_t. */
|
||||
#if 0
|
||||
# undef WINT_MIN
|
||||
# undef WINT_MAX
|
||||
# define WINT_MIN 0x0U
|
||||
# define WINT_MAX 0xffffffffU
|
||||
#endif
|
||||
|
||||
#if ! 0
|
||||
|
||||
/* <sys/types.h> defines some of the stdint.h types as well, on glibc,
|
||||
IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
|
||||
AIX 5.2 <sys/types.h> isn't needed and causes troubles.
|
||||
Mac OS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
|
||||
relies on the system <stdint.h> definitions, so include
|
||||
<sys/types.h> after <stdint.h>. */
|
||||
# if 1 && ! defined _AIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
|
||||
# if 1
|
||||
/* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
|
||||
int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
|
||||
<inttypes.h> also defines intptr_t and uintptr_t. */
|
||||
# include <inttypes.h>
|
||||
# elif 0
|
||||
/* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
|
||||
the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
|
||||
# include <sys/inttypes.h>
|
||||
# endif
|
||||
|
||||
# if 0 && ! defined __BIT_TYPES_DEFINED__
|
||||
/* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
|
||||
int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is
|
||||
included by <sys/types.h>. */
|
||||
# include <sys/bitypes.h>
|
||||
# endif
|
||||
|
||||
# undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
|
||||
|
||||
/* Minimum and maximum values for an integer type under the usual assumption.
|
||||
Return an unspecified value if BITS == 0, adding a check to pacify
|
||||
picky compilers. */
|
||||
|
||||
/* These are separate macros, because if you try to merge these macros into
|
||||
a single one, HP-UX cc rejects the resulting expression in constant
|
||||
expressions. */
|
||||
# define _STDINT_UNSIGNED_MIN(bits, zero) \
|
||||
(zero)
|
||||
# define _STDINT_SIGNED_MIN(bits, zero) \
|
||||
(~ _STDINT_MAX (1, bits, zero))
|
||||
|
||||
# define _STDINT_MAX(signed, bits, zero) \
|
||||
(((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
|
||||
|
||||
#if !GNULIB_defined_stdint_types
|
||||
|
||||
/* 7.18.1.1. Exact-width integer types */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. */
|
||||
|
||||
# undef int8_t
|
||||
# undef uint8_t
|
||||
typedef signed char gl_int8_t;
|
||||
typedef unsigned char gl_uint8_t;
|
||||
# define int8_t gl_int8_t
|
||||
# define uint8_t gl_uint8_t
|
||||
|
||||
# undef int16_t
|
||||
# undef uint16_t
|
||||
typedef short int gl_int16_t;
|
||||
typedef unsigned short int gl_uint16_t;
|
||||
# define int16_t gl_int16_t
|
||||
# define uint16_t gl_uint16_t
|
||||
|
||||
# undef int32_t
|
||||
# undef uint32_t
|
||||
typedef int gl_int32_t;
|
||||
typedef unsigned int gl_uint32_t;
|
||||
# define int32_t gl_int32_t
|
||||
# define uint32_t gl_uint32_t
|
||||
|
||||
/* If the system defines INT64_MAX, assume int64_t works. That way,
|
||||
if the underlying platform defines int64_t to be a 64-bit long long
|
||||
int, the code below won't mistakenly define it to be a 64-bit long
|
||||
int, which would mess up C++ name mangling. We must use #ifdef
|
||||
rather than #if, to avoid an error with HP-UX 10.20 cc. */
|
||||
|
||||
# ifdef INT64_MAX
|
||||
# define GL_INT64_T
|
||||
# else
|
||||
/* Do not undefine int64_t if gnulib is not being used with 64-bit
|
||||
types, since otherwise it breaks platforms like Tandem/NSK. */
|
||||
# if LONG_MAX >> 31 >> 31 == 1
|
||||
# undef int64_t
|
||||
typedef long int gl_int64_t;
|
||||
# define int64_t gl_int64_t
|
||||
# define GL_INT64_T
|
||||
# elif defined _MSC_VER
|
||||
# undef int64_t
|
||||
typedef __int64 gl_int64_t;
|
||||
# define int64_t gl_int64_t
|
||||
# define GL_INT64_T
|
||||
# else
|
||||
# undef int64_t
|
||||
typedef long long int gl_int64_t;
|
||||
# define int64_t gl_int64_t
|
||||
# define GL_INT64_T
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifdef UINT64_MAX
|
||||
# define GL_UINT64_T
|
||||
# else
|
||||
# if ULONG_MAX >> 31 >> 31 >> 1 == 1
|
||||
# undef uint64_t
|
||||
typedef unsigned long int gl_uint64_t;
|
||||
# define uint64_t gl_uint64_t
|
||||
# define GL_UINT64_T
|
||||
# elif defined _MSC_VER
|
||||
# undef uint64_t
|
||||
typedef unsigned __int64 gl_uint64_t;
|
||||
# define uint64_t gl_uint64_t
|
||||
# define GL_UINT64_T
|
||||
# else
|
||||
# undef uint64_t
|
||||
typedef unsigned long long int gl_uint64_t;
|
||||
# define uint64_t gl_uint64_t
|
||||
# define GL_UINT64_T
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */
|
||||
# define _UINT8_T
|
||||
# define _UINT32_T
|
||||
# define _UINT64_T
|
||||
|
||||
|
||||
/* 7.18.1.2. Minimum-width integer types */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
|
||||
are the same as the corresponding N_t types. */
|
||||
|
||||
# undef int_least8_t
|
||||
# undef uint_least8_t
|
||||
# undef int_least16_t
|
||||
# undef uint_least16_t
|
||||
# undef int_least32_t
|
||||
# undef uint_least32_t
|
||||
# undef int_least64_t
|
||||
# undef uint_least64_t
|
||||
# define int_least8_t int8_t
|
||||
# define uint_least8_t uint8_t
|
||||
# define int_least16_t int16_t
|
||||
# define uint_least16_t uint16_t
|
||||
# define int_least32_t int32_t
|
||||
# define uint_least32_t uint32_t
|
||||
# ifdef GL_INT64_T
|
||||
# define int_least64_t int64_t
|
||||
# endif
|
||||
# ifdef GL_UINT64_T
|
||||
# define uint_least64_t uint64_t
|
||||
# endif
|
||||
|
||||
/* 7.18.1.3. Fastest minimum-width integer types */
|
||||
|
||||
/* Note: Other <stdint.h> substitutes may define these types differently.
|
||||
It is not recommended to use these types in public header files. */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
|
||||
are taken from the same list of types. The following code normally
|
||||
uses types consistent with glibc, as that lessens the chance of
|
||||
incompatibility with older GNU hosts. */
|
||||
|
||||
# undef int_fast8_t
|
||||
# undef uint_fast8_t
|
||||
# undef int_fast16_t
|
||||
# undef uint_fast16_t
|
||||
# undef int_fast32_t
|
||||
# undef uint_fast32_t
|
||||
# undef int_fast64_t
|
||||
# undef uint_fast64_t
|
||||
typedef signed char gl_int_fast8_t;
|
||||
typedef unsigned char gl_uint_fast8_t;
|
||||
|
||||
# ifdef __sun
|
||||
/* Define types compatible with SunOS 5.10, so that code compiled under
|
||||
earlier SunOS versions works with code compiled under SunOS 5.10. */
|
||||
typedef int gl_int_fast32_t;
|
||||
typedef unsigned int gl_uint_fast32_t;
|
||||
# else
|
||||
typedef long int gl_int_fast32_t;
|
||||
typedef unsigned long int gl_uint_fast32_t;
|
||||
# endif
|
||||
typedef gl_int_fast32_t gl_int_fast16_t;
|
||||
typedef gl_uint_fast32_t gl_uint_fast16_t;
|
||||
|
||||
# define int_fast8_t gl_int_fast8_t
|
||||
# define uint_fast8_t gl_uint_fast8_t
|
||||
# define int_fast16_t gl_int_fast16_t
|
||||
# define uint_fast16_t gl_uint_fast16_t
|
||||
# define int_fast32_t gl_int_fast32_t
|
||||
# define uint_fast32_t gl_uint_fast32_t
|
||||
# ifdef GL_INT64_T
|
||||
# define int_fast64_t int64_t
|
||||
# endif
|
||||
# ifdef GL_UINT64_T
|
||||
# define uint_fast64_t uint64_t
|
||||
# endif
|
||||
|
||||
/* 7.18.1.4. Integer types capable of holding object pointers */
|
||||
|
||||
/* kLIBC's <stdint.h> defines _INTPTR_T_DECLARED and needs its own
|
||||
definitions of intptr_t and uintptr_t (which use int and unsigned)
|
||||
to avoid clashes with declarations of system functions like sbrk.
|
||||
Similarly, MinGW WSL-5.4.1 <stdint.h> needs its own intptr_t and
|
||||
uintptr_t to avoid conflicting declarations of system functions like
|
||||
_findclose in <io.h>. */
|
||||
# if !((defined __KLIBC__ && defined _INTPTR_T_DECLARED) \
|
||||
|| defined __MINGW32__)
|
||||
# undef intptr_t
|
||||
# undef uintptr_t
|
||||
# ifdef _WIN64
|
||||
typedef long long int gl_intptr_t;
|
||||
typedef unsigned long long int gl_uintptr_t;
|
||||
# else
|
||||
typedef long int gl_intptr_t;
|
||||
typedef unsigned long int gl_uintptr_t;
|
||||
# endif
|
||||
# define intptr_t gl_intptr_t
|
||||
# define uintptr_t gl_uintptr_t
|
||||
# endif
|
||||
|
||||
/* 7.18.1.5. Greatest-width integer types */
|
||||
|
||||
/* Note: These types are compiler dependent. It may be unwise to use them in
|
||||
public header files. */
|
||||
|
||||
/* If the system defines INTMAX_MAX, assume that intmax_t works, and
|
||||
similarly for UINTMAX_MAX and uintmax_t. This avoids problems with
|
||||
assuming one type where another is used by the system. */
|
||||
|
||||
# ifndef INTMAX_MAX
|
||||
# undef INTMAX_C
|
||||
# undef intmax_t
|
||||
# if LONG_MAX >> 30 == 1
|
||||
typedef long long int gl_intmax_t;
|
||||
# define intmax_t gl_intmax_t
|
||||
# elif defined GL_INT64_T
|
||||
# define intmax_t int64_t
|
||||
# else
|
||||
typedef long int gl_intmax_t;
|
||||
# define intmax_t gl_intmax_t
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef UINTMAX_MAX
|
||||
# undef UINTMAX_C
|
||||
# undef uintmax_t
|
||||
# if ULONG_MAX >> 31 == 1
|
||||
typedef unsigned long long int gl_uintmax_t;
|
||||
# define uintmax_t gl_uintmax_t
|
||||
# elif defined GL_UINT64_T
|
||||
# define uintmax_t uint64_t
|
||||
# else
|
||||
typedef unsigned long int gl_uintmax_t;
|
||||
# define uintmax_t gl_uintmax_t
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Verify that intmax_t and uintmax_t have the same size. Too much code
|
||||
breaks if this is not the case. If this check fails, the reason is likely
|
||||
to be found in the autoconf macros. */
|
||||
typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
|
||||
? 1 : -1];
|
||||
|
||||
# define GNULIB_defined_stdint_types 1
|
||||
# endif /* !GNULIB_defined_stdint_types */
|
||||
|
||||
/* 7.18.2. Limits of specified-width integer types */
|
||||
|
||||
/* 7.18.2.1. Limits of exact-width integer types */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. */
|
||||
|
||||
# undef INT8_MIN
|
||||
# undef INT8_MAX
|
||||
# undef UINT8_MAX
|
||||
# define INT8_MIN (~ INT8_MAX)
|
||||
# define INT8_MAX 127
|
||||
# define UINT8_MAX 255
|
||||
|
||||
# undef INT16_MIN
|
||||
# undef INT16_MAX
|
||||
# undef UINT16_MAX
|
||||
# define INT16_MIN (~ INT16_MAX)
|
||||
# define INT16_MAX 32767
|
||||
# define UINT16_MAX 65535
|
||||
|
||||
# undef INT32_MIN
|
||||
# undef INT32_MAX
|
||||
# undef UINT32_MAX
|
||||
# define INT32_MIN (~ INT32_MAX)
|
||||
# define INT32_MAX 2147483647
|
||||
# define UINT32_MAX 4294967295U
|
||||
|
||||
# if defined GL_INT64_T && ! defined INT64_MAX
|
||||
/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0
|
||||
evaluates the latter incorrectly in preprocessor expressions. */
|
||||
# define INT64_MIN (- INTMAX_C (1) << 63)
|
||||
# define INT64_MAX INTMAX_C (9223372036854775807)
|
||||
# endif
|
||||
|
||||
# if defined GL_UINT64_T && ! defined UINT64_MAX
|
||||
# define UINT64_MAX UINTMAX_C (18446744073709551615)
|
||||
# endif
|
||||
|
||||
/* 7.18.2.2. Limits of minimum-width integer types */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
|
||||
are the same as the corresponding N_t types. */
|
||||
|
||||
# undef INT_LEAST8_MIN
|
||||
# undef INT_LEAST8_MAX
|
||||
# undef UINT_LEAST8_MAX
|
||||
# define INT_LEAST8_MIN INT8_MIN
|
||||
# define INT_LEAST8_MAX INT8_MAX
|
||||
# define UINT_LEAST8_MAX UINT8_MAX
|
||||
|
||||
# undef INT_LEAST16_MIN
|
||||
# undef INT_LEAST16_MAX
|
||||
# undef UINT_LEAST16_MAX
|
||||
# define INT_LEAST16_MIN INT16_MIN
|
||||
# define INT_LEAST16_MAX INT16_MAX
|
||||
# define UINT_LEAST16_MAX UINT16_MAX
|
||||
|
||||
# undef INT_LEAST32_MIN
|
||||
# undef INT_LEAST32_MAX
|
||||
# undef UINT_LEAST32_MAX
|
||||
# define INT_LEAST32_MIN INT32_MIN
|
||||
# define INT_LEAST32_MAX INT32_MAX
|
||||
# define UINT_LEAST32_MAX UINT32_MAX
|
||||
|
||||
# undef INT_LEAST64_MIN
|
||||
# undef INT_LEAST64_MAX
|
||||
# ifdef GL_INT64_T
|
||||
# define INT_LEAST64_MIN INT64_MIN
|
||||
# define INT_LEAST64_MAX INT64_MAX
|
||||
# endif
|
||||
|
||||
# undef UINT_LEAST64_MAX
|
||||
# ifdef GL_UINT64_T
|
||||
# define UINT_LEAST64_MAX UINT64_MAX
|
||||
# endif
|
||||
|
||||
/* 7.18.2.3. Limits of fastest minimum-width integer types */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
|
||||
are taken from the same list of types. */
|
||||
|
||||
# undef INT_FAST8_MIN
|
||||
# undef INT_FAST8_MAX
|
||||
# undef UINT_FAST8_MAX
|
||||
# define INT_FAST8_MIN SCHAR_MIN
|
||||
# define INT_FAST8_MAX SCHAR_MAX
|
||||
# define UINT_FAST8_MAX UCHAR_MAX
|
||||
|
||||
# undef INT_FAST16_MIN
|
||||
# undef INT_FAST16_MAX
|
||||
# undef UINT_FAST16_MAX
|
||||
# define INT_FAST16_MIN INT_FAST32_MIN
|
||||
# define INT_FAST16_MAX INT_FAST32_MAX
|
||||
# define UINT_FAST16_MAX UINT_FAST32_MAX
|
||||
|
||||
# undef INT_FAST32_MIN
|
||||
# undef INT_FAST32_MAX
|
||||
# undef UINT_FAST32_MAX
|
||||
# ifdef __sun
|
||||
# define INT_FAST32_MIN INT_MIN
|
||||
# define INT_FAST32_MAX INT_MAX
|
||||
# define UINT_FAST32_MAX UINT_MAX
|
||||
# else
|
||||
# define INT_FAST32_MIN LONG_MIN
|
||||
# define INT_FAST32_MAX LONG_MAX
|
||||
# define UINT_FAST32_MAX ULONG_MAX
|
||||
# endif
|
||||
|
||||
# undef INT_FAST64_MIN
|
||||
# undef INT_FAST64_MAX
|
||||
# ifdef GL_INT64_T
|
||||
# define INT_FAST64_MIN INT64_MIN
|
||||
# define INT_FAST64_MAX INT64_MAX
|
||||
# endif
|
||||
|
||||
# undef UINT_FAST64_MAX
|
||||
# ifdef GL_UINT64_T
|
||||
# define UINT_FAST64_MAX UINT64_MAX
|
||||
# endif
|
||||
|
||||
/* 7.18.2.4. Limits of integer types capable of holding object pointers */
|
||||
|
||||
# undef INTPTR_MIN
|
||||
# undef INTPTR_MAX
|
||||
# undef UINTPTR_MAX
|
||||
# ifdef _WIN64
|
||||
# define INTPTR_MIN LLONG_MIN
|
||||
# define INTPTR_MAX LLONG_MAX
|
||||
# define UINTPTR_MAX ULLONG_MAX
|
||||
# else
|
||||
# define INTPTR_MIN LONG_MIN
|
||||
# define INTPTR_MAX LONG_MAX
|
||||
# define UINTPTR_MAX ULONG_MAX
|
||||
# endif
|
||||
|
||||
/* 7.18.2.5. Limits of greatest-width integer types */
|
||||
|
||||
# ifndef INTMAX_MAX
|
||||
# undef INTMAX_MIN
|
||||
# ifdef INT64_MAX
|
||||
# define INTMAX_MIN INT64_MIN
|
||||
# define INTMAX_MAX INT64_MAX
|
||||
# else
|
||||
# define INTMAX_MIN INT32_MIN
|
||||
# define INTMAX_MAX INT32_MAX
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef UINTMAX_MAX
|
||||
# ifdef UINT64_MAX
|
||||
# define UINTMAX_MAX UINT64_MAX
|
||||
# else
|
||||
# define UINTMAX_MAX UINT32_MAX
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* 7.18.3. Limits of other integer types */
|
||||
|
||||
/* ptrdiff_t limits */
|
||||
# undef PTRDIFF_MIN
|
||||
# undef PTRDIFF_MAX
|
||||
# if 0
|
||||
# ifdef _LP64
|
||||
# define PTRDIFF_MIN _STDINT_SIGNED_MIN (64, 0l)
|
||||
# define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l)
|
||||
# else
|
||||
# define PTRDIFF_MIN _STDINT_SIGNED_MIN (32, 0)
|
||||
# define PTRDIFF_MAX _STDINT_MAX (1, 32, 0)
|
||||
# endif
|
||||
# else
|
||||
# define PTRDIFF_MIN \
|
||||
_STDINT_SIGNED_MIN (64, 0l)
|
||||
# define PTRDIFF_MAX \
|
||||
_STDINT_MAX (1, 64, 0l)
|
||||
# endif
|
||||
|
||||
/* sig_atomic_t limits */
|
||||
# undef SIG_ATOMIC_MIN
|
||||
# undef SIG_ATOMIC_MAX
|
||||
# if 1
|
||||
# define SIG_ATOMIC_MIN \
|
||||
_STDINT_SIGNED_MIN (32, 0)
|
||||
# else
|
||||
# define SIG_ATOMIC_MIN \
|
||||
_STDINT_UNSIGNED_MIN (32, 0)
|
||||
# endif
|
||||
# define SIG_ATOMIC_MAX \
|
||||
_STDINT_MAX (1, 32, \
|
||||
0)
|
||||
|
||||
|
||||
/* size_t limit */
|
||||
# undef SIZE_MAX
|
||||
# if 0
|
||||
# ifdef _LP64
|
||||
# define SIZE_MAX _STDINT_MAX (0, 64, 0ul)
|
||||
# else
|
||||
# define SIZE_MAX _STDINT_MAX (0, 32, 0ul)
|
||||
# endif
|
||||
# else
|
||||
# define SIZE_MAX _STDINT_MAX (0, 64, 0ul)
|
||||
# endif
|
||||
|
||||
/* wchar_t limits */
|
||||
/* Get WCHAR_MIN, WCHAR_MAX.
|
||||
This include is not on the top, above, because on OSF/1 4.0 we have a
|
||||
sequence of nested includes
|
||||
<wchar.h> -> <stdio.h> -> <getopt.h> -> <stdlib.h>, and the latter includes
|
||||
<stdint.h> and assumes its types are already defined. */
|
||||
# if 1 && ! (defined WCHAR_MIN && defined WCHAR_MAX)
|
||||
# define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
|
||||
# include <wchar.h>
|
||||
# undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
|
||||
# endif
|
||||
# undef WCHAR_MIN
|
||||
# undef WCHAR_MAX
|
||||
# if 0
|
||||
# define WCHAR_MIN \
|
||||
_STDINT_SIGNED_MIN (32, 0u)
|
||||
# else
|
||||
# define WCHAR_MIN \
|
||||
_STDINT_UNSIGNED_MIN (32, 0u)
|
||||
# endif
|
||||
# define WCHAR_MAX \
|
||||
_STDINT_MAX (0, 32, 0u)
|
||||
|
||||
/* wint_t limits */
|
||||
/* If gnulib's <wchar.h> or <wctype.h> overrides wint_t, u is not
|
||||
accurate, therefore use the definitions from above. */
|
||||
# if !0
|
||||
# undef WINT_MIN
|
||||
# undef WINT_MAX
|
||||
# if 0
|
||||
# define WINT_MIN \
|
||||
_STDINT_SIGNED_MIN (32, 0u)
|
||||
# else
|
||||
# define WINT_MIN \
|
||||
_STDINT_UNSIGNED_MIN (32, 0u)
|
||||
# endif
|
||||
# define WINT_MAX \
|
||||
_STDINT_MAX (0, 32, 0u)
|
||||
# endif
|
||||
|
||||
/* 7.18.4. Macros for integer constants */
|
||||
|
||||
/* 7.18.4.1. Macros for minimum-width integer constants */
|
||||
/* According to ISO C 99 Technical Corrigendum 1 */
|
||||
|
||||
/* Here we assume a standard architecture where the hardware integer
|
||||
types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */
|
||||
|
||||
# undef INT8_C
|
||||
# undef UINT8_C
|
||||
# define INT8_C(x) x
|
||||
# define UINT8_C(x) x
|
||||
|
||||
# undef INT16_C
|
||||
# undef UINT16_C
|
||||
# define INT16_C(x) x
|
||||
# define UINT16_C(x) x
|
||||
|
||||
# undef INT32_C
|
||||
# undef UINT32_C
|
||||
# define INT32_C(x) x
|
||||
# define UINT32_C(x) x ## U
|
||||
|
||||
# undef INT64_C
|
||||
# undef UINT64_C
|
||||
# if LONG_MAX >> 31 >> 31 == 1
|
||||
# define INT64_C(x) x##L
|
||||
# elif defined _MSC_VER
|
||||
# define INT64_C(x) x##i64
|
||||
# else
|
||||
# define INT64_C(x) x##LL
|
||||
# endif
|
||||
# if ULONG_MAX >> 31 >> 31 >> 1 == 1
|
||||
# define UINT64_C(x) x##UL
|
||||
# elif defined _MSC_VER
|
||||
# define UINT64_C(x) x##ui64
|
||||
# else
|
||||
# define UINT64_C(x) x##ULL
|
||||
# endif
|
||||
|
||||
/* 7.18.4.2. Macros for greatest-width integer constants */
|
||||
|
||||
# ifndef INTMAX_C
|
||||
# if LONG_MAX >> 30 == 1
|
||||
# define INTMAX_C(x) x##LL
|
||||
# elif defined GL_INT64_T
|
||||
# define INTMAX_C(x) INT64_C(x)
|
||||
# else
|
||||
# define INTMAX_C(x) x##L
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef UINTMAX_C
|
||||
# if ULONG_MAX >> 31 == 1
|
||||
# define UINTMAX_C(x) x##ULL
|
||||
# elif defined GL_UINT64_T
|
||||
# define UINTMAX_C(x) UINT64_C(x)
|
||||
# else
|
||||
# define UINTMAX_C(x) x##UL
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif /* !0 */
|
||||
|
||||
/* Macros specified by ISO/IEC TS 18661-1:2014. */
|
||||
|
||||
#if (!defined UINTMAX_WIDTH \
|
||||
&& (defined _GNU_SOURCE || defined __STDC_WANT_IEC_60559_BFP_EXT__))
|
||||
# ifdef INT8_MAX
|
||||
# define INT8_WIDTH _GL_INTEGER_WIDTH (INT8_MIN, INT8_MAX)
|
||||
# endif
|
||||
# ifdef UINT8_MAX
|
||||
# define UINT8_WIDTH _GL_INTEGER_WIDTH (0, UINT8_MAX)
|
||||
# endif
|
||||
# ifdef INT16_MAX
|
||||
# define INT16_WIDTH _GL_INTEGER_WIDTH (INT16_MIN, INT16_MAX)
|
||||
# endif
|
||||
# ifdef UINT16_MAX
|
||||
# define UINT16_WIDTH _GL_INTEGER_WIDTH (0, UINT16_MAX)
|
||||
# endif
|
||||
# ifdef INT32_MAX
|
||||
# define INT32_WIDTH _GL_INTEGER_WIDTH (INT32_MIN, INT32_MAX)
|
||||
# endif
|
||||
# ifdef UINT32_MAX
|
||||
# define UINT32_WIDTH _GL_INTEGER_WIDTH (0, UINT32_MAX)
|
||||
# endif
|
||||
# ifdef INT64_MAX
|
||||
# define INT64_WIDTH _GL_INTEGER_WIDTH (INT64_MIN, INT64_MAX)
|
||||
# endif
|
||||
# ifdef UINT64_MAX
|
||||
# define UINT64_WIDTH _GL_INTEGER_WIDTH (0, UINT64_MAX)
|
||||
# endif
|
||||
# define INT_LEAST8_WIDTH _GL_INTEGER_WIDTH (INT_LEAST8_MIN, INT_LEAST8_MAX)
|
||||
# define UINT_LEAST8_WIDTH _GL_INTEGER_WIDTH (0, UINT_LEAST8_MAX)
|
||||
# define INT_LEAST16_WIDTH _GL_INTEGER_WIDTH (INT_LEAST16_MIN, INT_LEAST16_MAX)
|
||||
# define UINT_LEAST16_WIDTH _GL_INTEGER_WIDTH (0, UINT_LEAST16_MAX)
|
||||
# define INT_LEAST32_WIDTH _GL_INTEGER_WIDTH (INT_LEAST32_MIN, INT_LEAST32_MAX)
|
||||
# define UINT_LEAST32_WIDTH _GL_INTEGER_WIDTH (0, UINT_LEAST32_MAX)
|
||||
# define INT_LEAST64_WIDTH _GL_INTEGER_WIDTH (INT_LEAST64_MIN, INT_LEAST64_MAX)
|
||||
# define UINT_LEAST64_WIDTH _GL_INTEGER_WIDTH (0, UINT_LEAST64_MAX)
|
||||
# define INT_FAST8_WIDTH _GL_INTEGER_WIDTH (INT_FAST8_MIN, INT_FAST8_MAX)
|
||||
# define UINT_FAST8_WIDTH _GL_INTEGER_WIDTH (0, UINT_FAST8_MAX)
|
||||
# define INT_FAST16_WIDTH _GL_INTEGER_WIDTH (INT_FAST16_MIN, INT_FAST16_MAX)
|
||||
# define UINT_FAST16_WIDTH _GL_INTEGER_WIDTH (0, UINT_FAST16_MAX)
|
||||
# define INT_FAST32_WIDTH _GL_INTEGER_WIDTH (INT_FAST32_MIN, INT_FAST32_MAX)
|
||||
# define UINT_FAST32_WIDTH _GL_INTEGER_WIDTH (0, UINT_FAST32_MAX)
|
||||
# define INT_FAST64_WIDTH _GL_INTEGER_WIDTH (INT_FAST64_MIN, INT_FAST64_MAX)
|
||||
# define UINT_FAST64_WIDTH _GL_INTEGER_WIDTH (0, UINT_FAST64_MAX)
|
||||
# define INTPTR_WIDTH _GL_INTEGER_WIDTH (INTPTR_MIN, INTPTR_MAX)
|
||||
# define UINTPTR_WIDTH _GL_INTEGER_WIDTH (0, UINTPTR_MAX)
|
||||
# define INTMAX_WIDTH _GL_INTEGER_WIDTH (INTMAX_MIN, INTMAX_MAX)
|
||||
# define UINTMAX_WIDTH _GL_INTEGER_WIDTH (0, UINTMAX_MAX)
|
||||
# define PTRDIFF_WIDTH _GL_INTEGER_WIDTH (PTRDIFF_MIN, PTRDIFF_MAX)
|
||||
# define SIZE_WIDTH _GL_INTEGER_WIDTH (0, SIZE_MAX)
|
||||
# define WCHAR_WIDTH _GL_INTEGER_WIDTH (WCHAR_MIN, WCHAR_MAX)
|
||||
# ifdef WINT_MAX
|
||||
# define WINT_WIDTH _GL_INTEGER_WIDTH (WINT_MIN, WINT_MAX)
|
||||
# endif
|
||||
# ifdef SIG_ATOMIC_MAX
|
||||
# define SIG_ATOMIC_WIDTH _GL_INTEGER_WIDTH (SIG_ATOMIC_MIN, SIG_ATOMIC_MAX)
|
||||
# endif
|
||||
#endif /* !WINT_WIDTH && (_GNU_SOURCE || __STDC_WANT_IEC_60559_BFP_EXT__) */
|
||||
|
||||
#endif /* _GL_STDINT_H */
|
||||
#endif /* !(defined __ANDROID__ && ...) */
|
||||
#endif /* !defined _GL_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */
|
||||
@@ -1,168 +0,0 @@
|
||||
/* POSIX compatible FILE stream read function.
|
||||
Copyright (C) 2008-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2011.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <stdio.h>
|
||||
|
||||
/* Replace these functions only if module 'nonblocking' is requested. */
|
||||
#if GNULIB_NONBLOCKING
|
||||
|
||||
/* On native Windows platforms, when read() is called on a non-blocking pipe
|
||||
with an empty buffer, ReadFile() fails with error GetLastError() =
|
||||
ERROR_NO_DATA, and read() in consequence fails with error EINVAL. This
|
||||
read() function is at the basis of the function which fills the buffer of
|
||||
a FILE stream. */
|
||||
|
||||
# if defined _WIN32 && ! defined __CYGWIN__
|
||||
|
||||
# include <errno.h>
|
||||
# include <io.h>
|
||||
|
||||
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
|
||||
# include <windows.h>
|
||||
|
||||
# if GNULIB_MSVC_NOTHROW
|
||||
# include "msvc-nothrow.h"
|
||||
# else
|
||||
# include <io.h>
|
||||
# endif
|
||||
|
||||
/* Don't assume that UNICODE is not defined. */
|
||||
# undef GetNamedPipeHandleState
|
||||
# define GetNamedPipeHandleState GetNamedPipeHandleStateA
|
||||
|
||||
# define CALL_WITH_ERRNO_FIX(RETTYPE, EXPRESSION, FAILED) \
|
||||
if (ferror (stream)) \
|
||||
return (EXPRESSION); \
|
||||
else \
|
||||
{ \
|
||||
RETTYPE ret; \
|
||||
SetLastError (0); \
|
||||
ret = (EXPRESSION); \
|
||||
if (FAILED) \
|
||||
{ \
|
||||
if (GetLastError () == ERROR_NO_DATA && ferror (stream)) \
|
||||
{ \
|
||||
int fd = fileno (stream); \
|
||||
if (fd >= 0) \
|
||||
{ \
|
||||
HANDLE h = (HANDLE) _get_osfhandle (fd); \
|
||||
if (GetFileType (h) == FILE_TYPE_PIPE) \
|
||||
{ \
|
||||
/* h is a pipe or socket. */ \
|
||||
DWORD state; \
|
||||
if (GetNamedPipeHandleState (h, &state, NULL, NULL, \
|
||||
NULL, NULL, 0) \
|
||||
&& (state & PIPE_NOWAIT) != 0) \
|
||||
/* h is a pipe in non-blocking mode. \
|
||||
Change errno from EINVAL to EAGAIN. */ \
|
||||
errno = EAGAIN; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
|
||||
Otherwise we get a function definition conflict with mingw64's <stdio.h>. */
|
||||
# if GNULIB_SCANF
|
||||
int
|
||||
scanf (const char *format, ...)
|
||||
{
|
||||
int retval;
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
retval = vfscanf (stdin, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
|
||||
Otherwise we get a function definition conflict with mingw64's <stdio.h>. */
|
||||
# if GNULIB_FSCANF
|
||||
int
|
||||
fscanf (FILE *stream, const char *format, ...)
|
||||
{
|
||||
int retval;
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
retval = vfscanf (stream, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
|
||||
Otherwise we get a function definition conflict with mingw64's <stdio.h>. */
|
||||
# if GNULIB_VSCANF
|
||||
int
|
||||
vscanf (const char *format, va_list args)
|
||||
{
|
||||
return vfscanf (stdin, format, args);
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
|
||||
Otherwise we get a function definition conflict with mingw64's <stdio.h>. */
|
||||
# if GNULIB_VFSCANF
|
||||
int
|
||||
vfscanf (FILE *stream, const char *format, va_list args)
|
||||
#undef vfscanf
|
||||
{
|
||||
CALL_WITH_ERRNO_FIX (int, vfscanf (stream, format, args), ret == EOF)
|
||||
}
|
||||
# endif
|
||||
|
||||
int
|
||||
getchar (void)
|
||||
{
|
||||
return fgetc (stdin);
|
||||
}
|
||||
|
||||
int
|
||||
fgetc (FILE *stream)
|
||||
#undef fgetc
|
||||
{
|
||||
CALL_WITH_ERRNO_FIX (int, fgetc (stream), ret == EOF)
|
||||
}
|
||||
|
||||
char *
|
||||
fgets (char *s, int n, FILE *stream)
|
||||
#undef fgets
|
||||
{
|
||||
CALL_WITH_ERRNO_FIX (char *, fgets (s, n, stream), ret == NULL)
|
||||
}
|
||||
|
||||
/* We intentionally don't bother to fix gets. */
|
||||
|
||||
size_t
|
||||
fread (void *ptr, size_t s, size_t n, FILE *stream)
|
||||
#undef fread
|
||||
{
|
||||
CALL_WITH_ERRNO_FIX (size_t, fread (ptr, s, n, stream), ret < n)
|
||||
}
|
||||
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,206 +0,0 @@
|
||||
/* POSIX compatible FILE stream write function.
|
||||
Copyright (C) 2008-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2008.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <stdio.h>
|
||||
|
||||
/* Replace these functions only if module 'nonblocking' or module 'sigpipe' is
|
||||
requested. */
|
||||
#if GNULIB_NONBLOCKING || GNULIB_SIGPIPE
|
||||
|
||||
/* On native Windows platforms, SIGPIPE does not exist. When write() is
|
||||
called on a pipe with no readers, WriteFile() fails with error
|
||||
GetLastError() = ERROR_NO_DATA, and write() in consequence fails with
|
||||
error EINVAL. This write() function is at the basis of the function
|
||||
which flushes the buffer of a FILE stream. */
|
||||
|
||||
# if defined _WIN32 && ! defined __CYGWIN__
|
||||
|
||||
# include <errno.h>
|
||||
# include <signal.h>
|
||||
# include <io.h>
|
||||
|
||||
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
|
||||
# include <windows.h>
|
||||
|
||||
# if GNULIB_MSVC_NOTHROW
|
||||
# include "msvc-nothrow.h"
|
||||
# else
|
||||
# include <io.h>
|
||||
# endif
|
||||
|
||||
/* Don't assume that UNICODE is not defined. */
|
||||
# undef GetNamedPipeHandleState
|
||||
# define GetNamedPipeHandleState GetNamedPipeHandleStateA
|
||||
|
||||
# if GNULIB_NONBLOCKING
|
||||
# define CLEAR_ERRNO \
|
||||
errno = 0;
|
||||
# define HANDLE_ENOSPC \
|
||||
if (errno == ENOSPC && ferror (stream)) \
|
||||
{ \
|
||||
int fd = fileno (stream); \
|
||||
if (fd >= 0) \
|
||||
{ \
|
||||
HANDLE h = (HANDLE) _get_osfhandle (fd); \
|
||||
if (GetFileType (h) == FILE_TYPE_PIPE) \
|
||||
{ \
|
||||
/* h is a pipe or socket. */ \
|
||||
DWORD state; \
|
||||
if (GetNamedPipeHandleState (h, &state, NULL, NULL, \
|
||||
NULL, NULL, 0) \
|
||||
&& (state & PIPE_NOWAIT) != 0) \
|
||||
/* h is a pipe in non-blocking mode. \
|
||||
Change errno from ENOSPC to EAGAIN. */ \
|
||||
errno = EAGAIN; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
else
|
||||
# else
|
||||
# define CLEAR_ERRNO
|
||||
# define HANDLE_ENOSPC
|
||||
# endif
|
||||
|
||||
# if GNULIB_SIGPIPE
|
||||
# define CLEAR_LastError \
|
||||
SetLastError (0);
|
||||
# define HANDLE_ERROR_NO_DATA \
|
||||
if (GetLastError () == ERROR_NO_DATA && ferror (stream)) \
|
||||
{ \
|
||||
int fd = fileno (stream); \
|
||||
if (fd >= 0 \
|
||||
&& GetFileType ((HANDLE) _get_osfhandle (fd)) \
|
||||
== FILE_TYPE_PIPE) \
|
||||
{ \
|
||||
/* Try to raise signal SIGPIPE. */ \
|
||||
raise (SIGPIPE); \
|
||||
/* If it is currently blocked or ignored, change errno from \
|
||||
EINVAL to EPIPE. */ \
|
||||
errno = EPIPE; \
|
||||
} \
|
||||
} \
|
||||
else
|
||||
# else
|
||||
# define CLEAR_LastError
|
||||
# define HANDLE_ERROR_NO_DATA
|
||||
# endif
|
||||
|
||||
# define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
|
||||
if (ferror (stream)) \
|
||||
return (EXPRESSION); \
|
||||
else \
|
||||
{ \
|
||||
RETTYPE ret; \
|
||||
CLEAR_ERRNO \
|
||||
CLEAR_LastError \
|
||||
ret = (EXPRESSION); \
|
||||
if (FAILED) \
|
||||
{ \
|
||||
HANDLE_ENOSPC \
|
||||
HANDLE_ERROR_NO_DATA \
|
||||
; \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
# if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
|
||||
int
|
||||
printf (const char *format, ...)
|
||||
{
|
||||
int retval;
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
retval = vfprintf (stdout, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
# endif
|
||||
|
||||
# if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
|
||||
int
|
||||
fprintf (FILE *stream, const char *format, ...)
|
||||
{
|
||||
int retval;
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
retval = vfprintf (stream, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
# endif
|
||||
|
||||
# if !REPLACE_VPRINTF_POSIX /* avoid collision with vprintf.c */
|
||||
int
|
||||
vprintf (const char *format, va_list args)
|
||||
{
|
||||
return vfprintf (stdout, format, args);
|
||||
}
|
||||
# endif
|
||||
|
||||
# if !REPLACE_VFPRINTF_POSIX /* avoid collision with vfprintf.c */
|
||||
int
|
||||
vfprintf (FILE *stream, const char *format, va_list args)
|
||||
#undef vfprintf
|
||||
{
|
||||
CALL_WITH_SIGPIPE_EMULATION (int, vfprintf (stream, format, args), ret == EOF)
|
||||
}
|
||||
# endif
|
||||
|
||||
int
|
||||
putchar (int c)
|
||||
{
|
||||
return fputc (c, stdout);
|
||||
}
|
||||
|
||||
int
|
||||
fputc (int c, FILE *stream)
|
||||
#undef fputc
|
||||
{
|
||||
CALL_WITH_SIGPIPE_EMULATION (int, fputc (c, stream), ret == EOF)
|
||||
}
|
||||
|
||||
int
|
||||
fputs (const char *string, FILE *stream)
|
||||
#undef fputs
|
||||
{
|
||||
CALL_WITH_SIGPIPE_EMULATION (int, fputs (string, stream), ret == EOF)
|
||||
}
|
||||
|
||||
int
|
||||
puts (const char *string)
|
||||
#undef puts
|
||||
{
|
||||
FILE *stream = stdout;
|
||||
CALL_WITH_SIGPIPE_EMULATION (int, puts (string), ret == EOF)
|
||||
}
|
||||
|
||||
size_t
|
||||
fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
|
||||
#undef fwrite
|
||||
{
|
||||
CALL_WITH_SIGPIPE_EMULATION (size_t, fwrite (ptr, s, n, stream), ret < n)
|
||||
}
|
||||
|
||||
# endif
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,176 +0,0 @@
|
||||
/* Optimized string comparison.
|
||||
Copyright (C) 2001-2002, 2007, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Bruno Haible <bruno@clisp.org>. */
|
||||
|
||||
#ifndef _GL_STREQ_H
|
||||
#define _GL_STREQ_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* STREQ_OPT allows to optimize string comparison with a small literal string.
|
||||
STREQ_OPT (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
|
||||
is semantically equivalent to
|
||||
strcmp (s, "EUC-KR") == 0
|
||||
just faster. */
|
||||
|
||||
/* Help GCC to generate good code for string comparisons with
|
||||
immediate strings. */
|
||||
#if (defined __GNUC__ || defined __clang__) && defined __OPTIMIZE__
|
||||
|
||||
static inline int
|
||||
streq9 (const char *s1, const char *s2)
|
||||
{
|
||||
return strcmp (s1 + 9, s2 + 9) == 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
streq8 (const char *s1, const char *s2, char s28)
|
||||
{
|
||||
if (s1[8] == s28)
|
||||
{
|
||||
if (s28 == 0)
|
||||
return 1;
|
||||
else
|
||||
return streq9 (s1, s2);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
streq7 (const char *s1, const char *s2, char s27, char s28)
|
||||
{
|
||||
if (s1[7] == s27)
|
||||
{
|
||||
if (s27 == 0)
|
||||
return 1;
|
||||
else
|
||||
return streq8 (s1, s2, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
streq6 (const char *s1, const char *s2, char s26, char s27, char s28)
|
||||
{
|
||||
if (s1[6] == s26)
|
||||
{
|
||||
if (s26 == 0)
|
||||
return 1;
|
||||
else
|
||||
return streq7 (s1, s2, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
streq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (s1[5] == s25)
|
||||
{
|
||||
if (s25 == 0)
|
||||
return 1;
|
||||
else
|
||||
return streq6 (s1, s2, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
streq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (s1[4] == s24)
|
||||
{
|
||||
if (s24 == 0)
|
||||
return 1;
|
||||
else
|
||||
return streq5 (s1, s2, s25, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
streq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (s1[3] == s23)
|
||||
{
|
||||
if (s23 == 0)
|
||||
return 1;
|
||||
else
|
||||
return streq4 (s1, s2, s24, s25, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
streq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (s1[2] == s22)
|
||||
{
|
||||
if (s22 == 0)
|
||||
return 1;
|
||||
else
|
||||
return streq3 (s1, s2, s23, s24, s25, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
streq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (s1[1] == s21)
|
||||
{
|
||||
if (s21 == 0)
|
||||
return 1;
|
||||
else
|
||||
return streq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
streq0 (const char *s1, const char *s2, char s20, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (s1[0] == s20)
|
||||
{
|
||||
if (s20 == 0)
|
||||
return 1;
|
||||
else
|
||||
return streq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
|
||||
streq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
|
||||
|
||||
#else
|
||||
|
||||
#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
|
||||
(strcmp (s1, s2) == 0)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _GL_STREQ_H */
|
||||
@@ -1,306 +0,0 @@
|
||||
/* strerror-override.c --- POSIX compatible system error routine
|
||||
|
||||
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Bruno Haible <bruno@clisp.org>, 2010. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "strerror-override.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#if GNULIB_defined_EWINSOCK /* native Windows platforms */
|
||||
# if HAVE_WINSOCK2_H
|
||||
# include <winsock2.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !GNULIB_defined_strerror_override_macro
|
||||
|
||||
/* If ERRNUM maps to an errno value defined by gnulib, return a string
|
||||
describing the error. Otherwise return NULL. */
|
||||
const char *
|
||||
strerror_override (int errnum)
|
||||
{
|
||||
/* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */
|
||||
switch (errnum)
|
||||
{
|
||||
# if REPLACE_STRERROR_0
|
||||
case 0:
|
||||
return "Success";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_ESOCK /* native Windows platforms with older <errno.h> */
|
||||
case EINPROGRESS:
|
||||
return "Operation now in progress";
|
||||
case EALREADY:
|
||||
return "Operation already in progress";
|
||||
case ENOTSOCK:
|
||||
return "Socket operation on non-socket";
|
||||
case EDESTADDRREQ:
|
||||
return "Destination address required";
|
||||
case EMSGSIZE:
|
||||
return "Message too long";
|
||||
case EPROTOTYPE:
|
||||
return "Protocol wrong type for socket";
|
||||
case ENOPROTOOPT:
|
||||
return "Protocol not available";
|
||||
case EPROTONOSUPPORT:
|
||||
return "Protocol not supported";
|
||||
case EOPNOTSUPP:
|
||||
return "Operation not supported";
|
||||
case EAFNOSUPPORT:
|
||||
return "Address family not supported by protocol";
|
||||
case EADDRINUSE:
|
||||
return "Address already in use";
|
||||
case EADDRNOTAVAIL:
|
||||
return "Cannot assign requested address";
|
||||
case ENETDOWN:
|
||||
return "Network is down";
|
||||
case ENETUNREACH:
|
||||
return "Network is unreachable";
|
||||
case ECONNRESET:
|
||||
return "Connection reset by peer";
|
||||
case ENOBUFS:
|
||||
return "No buffer space available";
|
||||
case EISCONN:
|
||||
return "Transport endpoint is already connected";
|
||||
case ENOTCONN:
|
||||
return "Transport endpoint is not connected";
|
||||
case ETIMEDOUT:
|
||||
return "Connection timed out";
|
||||
case ECONNREFUSED:
|
||||
return "Connection refused";
|
||||
case ELOOP:
|
||||
return "Too many levels of symbolic links";
|
||||
case EHOSTUNREACH:
|
||||
return "No route to host";
|
||||
case EWOULDBLOCK:
|
||||
return "Operation would block";
|
||||
# endif
|
||||
# if GNULIB_defined_ESTREAMS /* native Windows platforms with older <errno.h> */
|
||||
case ETXTBSY:
|
||||
return "Text file busy";
|
||||
case ENODATA:
|
||||
return "No data available";
|
||||
case ENOSR:
|
||||
return "Out of streams resources";
|
||||
case ENOSTR:
|
||||
return "Device not a stream";
|
||||
case ETIME:
|
||||
return "Timer expired";
|
||||
case EOTHER:
|
||||
return "Other error";
|
||||
# endif
|
||||
# if GNULIB_defined_EWINSOCK /* native Windows platforms */
|
||||
case ESOCKTNOSUPPORT:
|
||||
return "Socket type not supported";
|
||||
case EPFNOSUPPORT:
|
||||
return "Protocol family not supported";
|
||||
case ESHUTDOWN:
|
||||
return "Cannot send after transport endpoint shutdown";
|
||||
case ETOOMANYREFS:
|
||||
return "Too many references: cannot splice";
|
||||
case EHOSTDOWN:
|
||||
return "Host is down";
|
||||
case EPROCLIM:
|
||||
return "Too many processes";
|
||||
case EUSERS:
|
||||
return "Too many users";
|
||||
case EDQUOT:
|
||||
return "Disk quota exceeded";
|
||||
case ESTALE:
|
||||
return "Stale NFS file handle";
|
||||
case EREMOTE:
|
||||
return "Object is remote";
|
||||
# if HAVE_WINSOCK2_H
|
||||
/* WSA_INVALID_HANDLE maps to EBADF */
|
||||
/* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
|
||||
/* WSA_INVALID_PARAMETER maps to EINVAL */
|
||||
case WSA_OPERATION_ABORTED:
|
||||
return "Overlapped operation aborted";
|
||||
case WSA_IO_INCOMPLETE:
|
||||
return "Overlapped I/O event object not in signaled state";
|
||||
case WSA_IO_PENDING:
|
||||
return "Overlapped operations will complete later";
|
||||
/* WSAEINTR maps to EINTR */
|
||||
/* WSAEBADF maps to EBADF */
|
||||
/* WSAEACCES maps to EACCES */
|
||||
/* WSAEFAULT maps to EFAULT */
|
||||
/* WSAEINVAL maps to EINVAL */
|
||||
/* WSAEMFILE maps to EMFILE */
|
||||
/* WSAEWOULDBLOCK maps to EWOULDBLOCK */
|
||||
/* WSAEINPROGRESS maps to EINPROGRESS */
|
||||
/* WSAEALREADY maps to EALREADY */
|
||||
/* WSAENOTSOCK maps to ENOTSOCK */
|
||||
/* WSAEDESTADDRREQ maps to EDESTADDRREQ */
|
||||
/* WSAEMSGSIZE maps to EMSGSIZE */
|
||||
/* WSAEPROTOTYPE maps to EPROTOTYPE */
|
||||
/* WSAENOPROTOOPT maps to ENOPROTOOPT */
|
||||
/* WSAEPROTONOSUPPORT maps to EPROTONOSUPPORT */
|
||||
/* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
|
||||
/* WSAEOPNOTSUPP maps to EOPNOTSUPP */
|
||||
/* WSAEPFNOSUPPORT is EPFNOSUPPORT */
|
||||
/* WSAEAFNOSUPPORT maps to EAFNOSUPPORT */
|
||||
/* WSAEADDRINUSE maps to EADDRINUSE */
|
||||
/* WSAEADDRNOTAVAIL maps to EADDRNOTAVAIL */
|
||||
/* WSAENETDOWN maps to ENETDOWN */
|
||||
/* WSAENETUNREACH maps to ENETUNREACH */
|
||||
/* WSAENETRESET maps to ENETRESET */
|
||||
/* WSAECONNABORTED maps to ECONNABORTED */
|
||||
/* WSAECONNRESET maps to ECONNRESET */
|
||||
/* WSAENOBUFS maps to ENOBUFS */
|
||||
/* WSAEISCONN maps to EISCONN */
|
||||
/* WSAENOTCONN maps to ENOTCONN */
|
||||
/* WSAESHUTDOWN is ESHUTDOWN */
|
||||
/* WSAETOOMANYREFS is ETOOMANYREFS */
|
||||
/* WSAETIMEDOUT maps to ETIMEDOUT */
|
||||
/* WSAECONNREFUSED maps to ECONNREFUSED */
|
||||
/* WSAELOOP maps to ELOOP */
|
||||
/* WSAENAMETOOLONG maps to ENAMETOOLONG */
|
||||
/* WSAEHOSTDOWN is EHOSTDOWN */
|
||||
/* WSAEHOSTUNREACH maps to EHOSTUNREACH */
|
||||
/* WSAENOTEMPTY maps to ENOTEMPTY */
|
||||
/* WSAEPROCLIM is EPROCLIM */
|
||||
/* WSAEUSERS is EUSERS */
|
||||
/* WSAEDQUOT is EDQUOT */
|
||||
/* WSAESTALE is ESTALE */
|
||||
/* WSAEREMOTE is EREMOTE */
|
||||
case WSASYSNOTREADY:
|
||||
return "Network subsystem is unavailable";
|
||||
case WSAVERNOTSUPPORTED:
|
||||
return "Winsock.dll version out of range";
|
||||
case WSANOTINITIALISED:
|
||||
return "Successful WSAStartup not yet performed";
|
||||
case WSAEDISCON:
|
||||
return "Graceful shutdown in progress";
|
||||
case WSAENOMORE: case WSA_E_NO_MORE:
|
||||
return "No more results";
|
||||
case WSAECANCELLED: case WSA_E_CANCELLED:
|
||||
return "Call was canceled";
|
||||
case WSAEINVALIDPROCTABLE:
|
||||
return "Procedure call table is invalid";
|
||||
case WSAEINVALIDPROVIDER:
|
||||
return "Service provider is invalid";
|
||||
case WSAEPROVIDERFAILEDINIT:
|
||||
return "Service provider failed to initialize";
|
||||
case WSASYSCALLFAILURE:
|
||||
return "System call failure";
|
||||
case WSASERVICE_NOT_FOUND:
|
||||
return "Service not found";
|
||||
case WSATYPE_NOT_FOUND:
|
||||
return "Class type not found";
|
||||
case WSAEREFUSED:
|
||||
return "Database query was refused";
|
||||
case WSAHOST_NOT_FOUND:
|
||||
return "Host not found";
|
||||
case WSATRY_AGAIN:
|
||||
return "Nonauthoritative host not found";
|
||||
case WSANO_RECOVERY:
|
||||
return "Nonrecoverable error";
|
||||
case WSANO_DATA:
|
||||
return "Valid name, no data record of requested type";
|
||||
/* WSA_QOS_* omitted */
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_ENOMSG
|
||||
case ENOMSG:
|
||||
return "No message of desired type";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_EIDRM
|
||||
case EIDRM:
|
||||
return "Identifier removed";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_ENOLINK
|
||||
case ENOLINK:
|
||||
return "Link has been severed";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_EPROTO
|
||||
case EPROTO:
|
||||
return "Protocol error";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_EMULTIHOP
|
||||
case EMULTIHOP:
|
||||
return "Multihop attempted";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_EBADMSG
|
||||
case EBADMSG:
|
||||
return "Bad message";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_EOVERFLOW
|
||||
case EOVERFLOW:
|
||||
return "Value too large for defined data type";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_ENOTSUP
|
||||
case ENOTSUP:
|
||||
return "Not supported";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_ENETRESET
|
||||
case ENETRESET:
|
||||
return "Network dropped connection on reset";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_ECONNABORTED
|
||||
case ECONNABORTED:
|
||||
return "Software caused connection abort";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_ESTALE
|
||||
case ESTALE:
|
||||
return "Stale NFS file handle";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_EDQUOT
|
||||
case EDQUOT:
|
||||
return "Disk quota exceeded";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_ECANCELED
|
||||
case ECANCELED:
|
||||
return "Operation canceled";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_EOWNERDEAD
|
||||
case EOWNERDEAD:
|
||||
return "Owner died";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_ENOTRECOVERABLE
|
||||
case ENOTRECOVERABLE:
|
||||
return "State not recoverable";
|
||||
# endif
|
||||
|
||||
# if GNULIB_defined_EILSEQ
|
||||
case EILSEQ:
|
||||
return "Invalid or incomplete multibyte or wide character";
|
||||
# endif
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,57 +0,0 @@
|
||||
/* strerror-override.h --- POSIX compatible system error routine
|
||||
|
||||
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GL_STRERROR_OVERRIDE_H
|
||||
# define _GL_STRERROR_OVERRIDE_H
|
||||
|
||||
# include <errno.h>
|
||||
# include <stddef.h>
|
||||
|
||||
/* Reasonable buffer size that should never trigger ERANGE; if this
|
||||
proves too small, we intentionally abort(), to remind us to fix
|
||||
this value. */
|
||||
# define STACKBUF_LEN 256
|
||||
|
||||
/* If ERRNUM maps to an errno value defined by gnulib, return a string
|
||||
describing the error. Otherwise return NULL. */
|
||||
# if REPLACE_STRERROR_0 \
|
||||
|| GNULIB_defined_ESOCK \
|
||||
|| GNULIB_defined_ESTREAMS \
|
||||
|| GNULIB_defined_EWINSOCK \
|
||||
|| GNULIB_defined_ENOMSG \
|
||||
|| GNULIB_defined_EIDRM \
|
||||
|| GNULIB_defined_ENOLINK \
|
||||
|| GNULIB_defined_EPROTO \
|
||||
|| GNULIB_defined_EMULTIHOP \
|
||||
|| GNULIB_defined_EBADMSG \
|
||||
|| GNULIB_defined_EOVERFLOW \
|
||||
|| GNULIB_defined_ENOTSUP \
|
||||
|| GNULIB_defined_ENETRESET \
|
||||
|| GNULIB_defined_ECONNABORTED \
|
||||
|| GNULIB_defined_ESTALE \
|
||||
|| GNULIB_defined_EDQUOT \
|
||||
|| GNULIB_defined_ECANCELED \
|
||||
|| GNULIB_defined_EOWNERDEAD \
|
||||
|| GNULIB_defined_ENOTRECOVERABLE \
|
||||
|| GNULIB_defined_EILSEQ
|
||||
extern const char *strerror_override (int errnum) _GL_ATTRIBUTE_CONST;
|
||||
# else
|
||||
# define strerror_override(ignored) NULL
|
||||
# define GNULIB_defined_strerror_override_macro 1
|
||||
# endif
|
||||
|
||||
#endif /* _GL_STRERROR_OVERRIDE_H */
|
||||
@@ -1,71 +0,0 @@
|
||||
/* strerror.c --- POSIX compatible system error routine
|
||||
|
||||
Copyright (C) 2007-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "intprops.h"
|
||||
#include "strerror-override.h"
|
||||
#include "verify.h"
|
||||
|
||||
/* Use the system functions, not the gnulib overrides in this file. */
|
||||
#undef sprintf
|
||||
|
||||
char *
|
||||
strerror (int n)
|
||||
#undef strerror
|
||||
{
|
||||
static char buf[STACKBUF_LEN];
|
||||
size_t len;
|
||||
|
||||
/* Cast away const, due to the historical signature of strerror;
|
||||
callers should not be modifying the string. */
|
||||
const char *msg = strerror_override (n);
|
||||
if (msg)
|
||||
return (char *) msg;
|
||||
|
||||
msg = strerror (n);
|
||||
|
||||
/* Our strerror_r implementation might use the system's strerror
|
||||
buffer, so all other clients of strerror have to see the error
|
||||
copied into a buffer that we manage. This is not thread-safe,
|
||||
even if the system strerror is, but portable programs shouldn't
|
||||
be using strerror if they care about thread-safety. */
|
||||
if (!msg || !*msg)
|
||||
{
|
||||
static char const fmt[] = "Unknown error %d";
|
||||
verify (sizeof buf >= sizeof (fmt) + INT_STRLEN_BOUND (n));
|
||||
sprintf (buf, fmt, n);
|
||||
errno = EINVAL;
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Fix STACKBUF_LEN if this ever aborts. */
|
||||
len = strlen (msg);
|
||||
if (sizeof buf <= len)
|
||||
abort ();
|
||||
|
||||
memcpy (buf, msg, len + 1);
|
||||
return buf;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,42 +0,0 @@
|
||||
/* System call limits
|
||||
|
||||
Copyright 2018-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GL_SYS_LIMITS_H
|
||||
#define _GL_SYS_LIMITS_H
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
/* Maximum number of bytes to read or write in a single system call.
|
||||
This can be useful for system calls like sendfile on GNU/Linux,
|
||||
which do not handle more than MAX_RW_COUNT bytes correctly.
|
||||
The Linux kernel MAX_RW_COUNT is at least INT_MAX >> 20 << 20,
|
||||
where the 20 comes from the Hexagon port with 1 MiB pages; use that
|
||||
as an approximation, as the exact value may not be available to us.
|
||||
|
||||
Using this also works around a serious Linux bug before 2.6.16; see
|
||||
<https://bugzilla.redhat.com/show_bug.cgi?id=612839>.
|
||||
|
||||
Using this also works around a Tru64 5.1 bug, where attempting
|
||||
to read INT_MAX bytes fails with errno == EINVAL. See
|
||||
<https://lists.gnu.org/r/bug-gnu-utils/2002-04/msg00010.html>.
|
||||
|
||||
Using this is likely to work around similar bugs in other operating
|
||||
systems. */
|
||||
|
||||
enum { SYS_BUFSIZE_MAX = INT_MAX >> 20 << 20 };
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,107 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* Provide a more complete sys/types.h.
|
||||
|
||||
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
|
||||
#if defined _WIN32 && !defined __CYGWIN__ \
|
||||
&& (defined __need_off_t || defined __need___off64_t \
|
||||
|| defined __need_ssize_t || defined __need_time_t)
|
||||
|
||||
/* Special invocation convention inside mingw header files. */
|
||||
|
||||
#include_next <sys/types.h>
|
||||
|
||||
#else
|
||||
/* Normal invocation convention. */
|
||||
|
||||
#ifndef _GL_SYS_TYPES_H
|
||||
|
||||
/* The include_next requires a split double-inclusion guard. */
|
||||
# define _GL_INCLUDING_SYS_TYPES_H
|
||||
#include_next <sys/types.h>
|
||||
# undef _GL_INCLUDING_SYS_TYPES_H
|
||||
|
||||
#ifndef _GL_SYS_TYPES_H
|
||||
#define _GL_SYS_TYPES_H
|
||||
|
||||
/* Override off_t if Large File Support is requested on native Windows. */
|
||||
#if 0
|
||||
/* Same as int64_t in <stdint.h>. */
|
||||
# if defined _MSC_VER
|
||||
# define off_t __int64
|
||||
# else
|
||||
# define off_t long long int
|
||||
# endif
|
||||
/* Indicator, for gnulib internal purposes. */
|
||||
# define _GL_WINDOWS_64_BIT_OFF_T 1
|
||||
#endif
|
||||
|
||||
/* Override dev_t and ino_t if distinguishable inodes support is requested
|
||||
on native Windows. */
|
||||
#if 0
|
||||
|
||||
# if 0 == 2
|
||||
/* Experimental, not useful in Windows 10. */
|
||||
|
||||
/* Define dev_t to a 64-bit type. */
|
||||
# if !defined GNULIB_defined_dev_t
|
||||
typedef unsigned long long int rpl_dev_t;
|
||||
# undef dev_t
|
||||
# define dev_t rpl_dev_t
|
||||
# define GNULIB_defined_dev_t 1
|
||||
# endif
|
||||
|
||||
/* Define ino_t to a 128-bit type. */
|
||||
# if !defined GNULIB_defined_ino_t
|
||||
/* MSVC does not have a 128-bit integer type.
|
||||
GCC has a 128-bit integer type __int128, but only on 64-bit targets. */
|
||||
typedef struct { unsigned long long int _gl_ino[2]; } rpl_ino_t;
|
||||
# undef ino_t
|
||||
# define ino_t rpl_ino_t
|
||||
# define GNULIB_defined_ino_t 1
|
||||
# endif
|
||||
|
||||
# else /* 0 == 1 */
|
||||
|
||||
/* Define ino_t to a 64-bit type. */
|
||||
# if !defined GNULIB_defined_ino_t
|
||||
typedef unsigned long long int rpl_ino_t;
|
||||
# undef ino_t
|
||||
# define ino_t rpl_ino_t
|
||||
# define GNULIB_defined_ino_t 1
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
/* Indicator, for gnulib internal purposes. */
|
||||
# define _GL_WINDOWS_STAT_INODES 0
|
||||
|
||||
#endif
|
||||
|
||||
/* MSVC 9 defines size_t in <stddef.h>, not in <sys/types.h>. */
|
||||
/* But avoid namespace pollution on glibc systems. */
|
||||
#if (defined _WIN32 && ! defined __CYGWIN__) && ! defined __GLIBC__
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
|
||||
#endif /* _GL_SYS_TYPES_H */
|
||||
#endif /* _GL_SYS_TYPES_H */
|
||||
#endif /* __need_XXX */
|
||||
@@ -1,959 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* A more-standard <time.h>.
|
||||
|
||||
Copyright (C) 2007-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
|
||||
/* Don't get in the way of glibc when it includes time.h merely to
|
||||
declare a few standard symbols, rather than to declare all the
|
||||
symbols. (However, skip this for MinGW as it treats __need_time_t
|
||||
incompatibly.) Also, Solaris 8 <time.h> eventually includes itself
|
||||
recursively; if that is happening, just include the system <time.h>
|
||||
without adding our own declarations. */
|
||||
#if (((defined __need_time_t || defined __need_clock_t \
|
||||
|| defined __need_timespec) \
|
||||
&& !defined __MINGW32__) \
|
||||
|| defined _GL_TIME_H)
|
||||
|
||||
# include_next <time.h>
|
||||
|
||||
#else
|
||||
|
||||
# define _GL_TIME_H
|
||||
|
||||
/* mingw's <time.h> provides the functions asctime_r, ctime_r, gmtime_r,
|
||||
localtime_r only if <unistd.h> or <pthread.h> has been included before. */
|
||||
# if defined __MINGW32__
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
|
||||
# include_next <time.h>
|
||||
|
||||
/* NetBSD 5.0 mis-defines NULL. */
|
||||
# include <stddef.h>
|
||||
|
||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||
/* C++ compatible function declaration macros.
|
||||
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GL_CXXDEFS_H
|
||||
#define _GL_CXXDEFS_H
|
||||
|
||||
/* Begin/end the GNULIB_NAMESPACE namespace. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
|
||||
# define _GL_END_NAMESPACE }
|
||||
#else
|
||||
# define _GL_BEGIN_NAMESPACE
|
||||
# define _GL_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
/* The three most frequent use cases of these macros are:
|
||||
|
||||
* For providing a substitute for a function that is missing on some
|
||||
platforms, but is declared and works fine on the platforms on which
|
||||
it exists:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if !@HAVE_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on all platforms,
|
||||
but is broken/insufficient and needs to be replaced on some platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
|
||||
* For providing a replacement for a function that exists on some platforms
|
||||
but is broken/insufficient and needs to be replaced on some of them and
|
||||
is additionally either missing or undeclared on some other platforms:
|
||||
|
||||
#if @GNULIB_FOO@
|
||||
# if @REPLACE_FOO@
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef foo
|
||||
# define foo rpl_foo
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (foo, ...);
|
||||
_GL_CXXALIAS_RPL (foo, ...);
|
||||
# else
|
||||
# if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
|
||||
_GL_FUNCDECL_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (foo, ...);
|
||||
# endif
|
||||
_GL_CXXALIASWARN (foo);
|
||||
#elif defined GNULIB_POSIXCHECK
|
||||
...
|
||||
#endif
|
||||
*/
|
||||
|
||||
/* _GL_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#if defined __cplusplus
|
||||
# define _GL_EXTERN_C extern "C"
|
||||
#else
|
||||
# define _GL_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
|
||||
declares a replacement function, named rpl_func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
|
||||
_GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
|
||||
#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype rpl_func parameters_and_attributes
|
||||
|
||||
/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
|
||||
declares the system function, named func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Example:
|
||||
_GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
*/
|
||||
#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C rettype func parameters_and_attributes
|
||||
|
||||
/* _GL_CXXALIAS_RPL (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
|
||||
|
||||
Wrapping rpl_func in an object with an inline conversion operator
|
||||
avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
|
||||
actually used in the program. */
|
||||
#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return ::rpl_func; \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||
is to be used when func is a Microsoft deprecated alias, on native Windows.
|
||||
It declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to _func, if GNULIB_NAMESPACE is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
|
||||
*/
|
||||
#define _GL_CXXALIAS_MDA(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_1 (func, _##func, rettype, parameters)
|
||||
|
||||
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
|
||||
except that the C function rpl_func may have a slightly different
|
||||
declaration. A cast is used to silence the "invalid conversion" error
|
||||
that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>(::rpl_func); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_MDA_CAST (func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||
except that the C function func may have a slightly different declaration.
|
||||
A cast is used to silence the "invalid conversion" error that would
|
||||
otherwise occur. */
|
||||
#define _GL_CXXALIAS_MDA_CAST(func,rettype,parameters) \
|
||||
_GL_CXXALIAS_RPL_CAST_1 (func, _##func, rettype, parameters)
|
||||
|
||||
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||
that redirects to the system provided function func, if GNULIB_NAMESPACE
|
||||
is defined.
|
||||
Example:
|
||||
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
|
||||
|
||||
Wrapping func in an object with an inline conversion operator
|
||||
avoids a reference to func unless GNULIB_NAMESPACE::func is
|
||||
actually used in the program. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return ::func; \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function func may have a slightly different declaration.
|
||||
A cast is used to silence the "invalid conversion" error that would
|
||||
otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>(::func); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
|
||||
is like _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||
except that the C function is picked among a set of overloaded functions,
|
||||
namely the one with rettype2 and parameters2. Two consecutive casts
|
||||
are used to silence the "cannot find a match" and "invalid conversion"
|
||||
errors that would otherwise occur. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
/* The outer cast must be a reinterpret_cast.
|
||||
The inner cast: When the function is defined as a set of overloaded
|
||||
functions, it works as a static_cast<>, choosing the designated variant.
|
||||
When the function is defined as a single variant, it works as a
|
||||
reinterpret_cast<>. The parenthesized cast syntax works both ways. */
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
namespace GNULIB_NAMESPACE \
|
||||
{ \
|
||||
static const struct _gl_ ## func ## _wrapper \
|
||||
{ \
|
||||
typedef rettype (*type) parameters; \
|
||||
\
|
||||
inline operator type () const \
|
||||
{ \
|
||||
return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); \
|
||||
} \
|
||||
} func = {}; \
|
||||
} \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#else
|
||||
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN (func);
|
||||
causes a warning to be emitted when ::func is used but not when
|
||||
GNULIB_NAMESPACE::func is used. func must be defined without overloaded
|
||||
variants. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN_1(func,namespace) \
|
||||
_GL_CXXALIASWARN_2 (func, namespace)
|
||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_WARN_ON_USE (func, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
extern __typeof__ (func) func
|
||||
# else
|
||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN(func) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
|
||||
causes a warning to be emitted when the given overloaded variant of ::func
|
||||
is used but not when GNULIB_NAMESPACE::func is used. */
|
||||
#if defined __cplusplus && defined GNULIB_NAMESPACE
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
|
||||
GNULIB_NAMESPACE)
|
||||
# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
|
||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||
we enable the warning only when not optimizing. */
|
||||
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_WARN_ON_USE_CXX (func, rettype, rettype, parameters_and_attributes, \
|
||||
"The symbol ::" #func " refers to the system function. " \
|
||||
"Use " #namespace "::" #func " instead.")
|
||||
# else
|
||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
# endif
|
||||
#else
|
||||
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
|
||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||
#endif
|
||||
|
||||
#endif /* _GL_CXXDEFS_H */
|
||||
|
||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||
/* A C macro for declaring that specific arguments must not be NULL.
|
||||
Copyright (C) 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
|
||||
that the values passed as arguments n, ..., m must be non-NULL pointers.
|
||||
n = 1 stands for the first argument, n = 2 for the second argument etc. */
|
||||
#ifndef _GL_ARG_NONNULL
|
||||
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__
|
||||
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
|
||||
# else
|
||||
# define _GL_ARG_NONNULL(params)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||
/* A C macro for emitting warnings if a function is used.
|
||||
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
|
||||
for FUNCTION which will then trigger a compiler warning containing
|
||||
the text of "literal string" anywhere that function is called, if
|
||||
supported by the compiler. If the compiler does not support this
|
||||
feature, the macro expands to an unused extern declaration.
|
||||
|
||||
_GL_WARN_ON_USE_ATTRIBUTE ("literal string") expands to the
|
||||
attribute used in _GL_WARN_ON_USE. If the compiler does not support
|
||||
this feature, it expands to empty.
|
||||
|
||||
These macros are useful for marking a function as a potential
|
||||
portability trap, with the intent that "literal string" include
|
||||
instructions on the replacement function that should be used
|
||||
instead.
|
||||
_GL_WARN_ON_USE is for functions with 'extern' linkage.
|
||||
_GL_WARN_ON_USE_ATTRIBUTE is for functions with 'static' or 'inline'
|
||||
linkage.
|
||||
|
||||
However, one of the reasons that a function is a portability trap is
|
||||
if it has the wrong signature. Declaring FUNCTION with a different
|
||||
signature in C is a compilation error, so this macro must use the
|
||||
same type as any existing declaration so that programs that avoid
|
||||
the problematic FUNCTION do not fail to compile merely because they
|
||||
included a header that poisoned the function. But this implies that
|
||||
_GL_WARN_ON_USE is only safe to use if FUNCTION is known to already
|
||||
have a declaration. Use of this macro implies that there must not
|
||||
be any other macro hiding the declaration of FUNCTION; but
|
||||
undefining FUNCTION first is part of the poisoning process anyway
|
||||
(although for symbols that are provided only via a macro, the result
|
||||
is a compilation error rather than a warning containing
|
||||
"literal string"). Also note that in C++, it is only safe to use if
|
||||
FUNCTION has no overloads.
|
||||
|
||||
For an example, it is possible to poison 'getline' by:
|
||||
- adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
|
||||
[getline]) in configure.ac, which potentially defines
|
||||
HAVE_RAW_DECL_GETLINE
|
||||
- adding this code to a header that wraps the system <stdio.h>:
|
||||
#undef getline
|
||||
#if HAVE_RAW_DECL_GETLINE
|
||||
_GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
|
||||
"not universally present; use the gnulib module getline");
|
||||
#endif
|
||||
|
||||
It is not possible to directly poison global variables. But it is
|
||||
possible to write a wrapper accessor function, and poison that
|
||||
(less common usage, like &environ, will cause a compilation error
|
||||
rather than issue the nice warning, but the end result of informing
|
||||
the developer about their portability problem is still achieved):
|
||||
#if HAVE_RAW_DECL_ENVIRON
|
||||
static char ***
|
||||
rpl_environ (void) { return &environ; }
|
||||
_GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
|
||||
# undef environ
|
||||
# define environ (*rpl_environ ())
|
||||
#endif
|
||||
or better (avoiding contradictory use of 'static' and 'extern'):
|
||||
#if HAVE_RAW_DECL_ENVIRON
|
||||
static char ***
|
||||
_GL_WARN_ON_USE_ATTRIBUTE ("environ is not always properly declared")
|
||||
rpl_environ (void) { return &environ; }
|
||||
# undef environ
|
||||
# define environ (*rpl_environ ())
|
||||
#endif
|
||||
*/
|
||||
#ifndef _GL_WARN_ON_USE
|
||||
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function __attribute__ ((__warning__ (message)))
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
||||
__attribute__ ((__warning__ (message)))
|
||||
# elif __clang_major__ >= 4
|
||||
/* Another compiler attribute is available in clang. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function \
|
||||
__attribute__ ((__diagnose_if__ (1, message, "warning")))
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
||||
__attribute__ ((__diagnose_if__ (1, message, "warning")))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message)
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_ON_USE_CXX (function, rettype_gcc, rettype_clang, parameters_and_attributes, "message")
|
||||
is like _GL_WARN_ON_USE (function, "message"), except that in C++ mode the
|
||||
function is declared with the given prototype, consisting of return type,
|
||||
parameters, and attributes.
|
||||
This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
|
||||
not work in this case. */
|
||||
#ifndef _GL_WARN_ON_USE_CXX
|
||||
# if !defined __cplusplus
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
_GL_WARN_ON_USE (function, msg)
|
||||
# else
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_gcc function parameters_and_attributes \
|
||||
__attribute__ ((__warning__ (msg)))
|
||||
# elif __clang_major__ >= 4
|
||||
/* Another compiler attribute is available in clang. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_clang function parameters_and_attributes \
|
||||
__attribute__ ((__diagnose_if__ (1, msg, "warning")))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_gcc function parameters_and_attributes
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#ifndef _GL_WARN_EXTERN_C
|
||||
# if defined __cplusplus
|
||||
# define _GL_WARN_EXTERN_C extern "C"
|
||||
# else
|
||||
# define _GL_WARN_EXTERN_C extern
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some systems don't define struct timespec (e.g., AIX 4.1).
|
||||
Or they define it with the wrong member names or define it in <sys/time.h>
|
||||
(e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it,
|
||||
but the pthreads-win32 library defines it in <pthread.h>. */
|
||||
# if ! 1
|
||||
# if 0
|
||||
# include <sys/time.h>
|
||||
# elif 0
|
||||
# include <pthread.h>
|
||||
# elif 0
|
||||
# include <unistd.h>
|
||||
# else
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
# if !GNULIB_defined_struct_timespec
|
||||
# undef timespec
|
||||
# define timespec rpl_timespec
|
||||
struct timespec
|
||||
{
|
||||
time_t tv_sec;
|
||||
long int tv_nsec;
|
||||
};
|
||||
# define GNULIB_defined_struct_timespec 1
|
||||
# endif
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if !GNULIB_defined_struct_time_t_must_be_integral
|
||||
/* https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
|
||||
requires time_t to be an integer type, even though C99 permits floating
|
||||
point. We don't know of any implementation that uses floating
|
||||
point, and it is much easier to write code that doesn't have to
|
||||
worry about that corner case, so we force the issue. */
|
||||
struct __time_t_must_be_integral {
|
||||
unsigned int __floating_time_t_unsupported : (time_t) 1;
|
||||
};
|
||||
# define GNULIB_defined_struct_time_t_must_be_integral 1
|
||||
# endif
|
||||
|
||||
/* Define TIME_UTC, a positive integer constant used for timespec_get(). */
|
||||
# if ! 1
|
||||
# if !GNULIB_defined_TIME_UTC
|
||||
# define TIME_UTC 1
|
||||
# define GNULIB_defined_TIME_UTC 1
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Set *TS to the current time, and return BASE.
|
||||
Upon failure, return 0. */
|
||||
# if 0
|
||||
# if ! 1
|
||||
_GL_FUNCDECL_SYS (timespec_get, int, (struct timespec *ts, int base)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base));
|
||||
_GL_CXXALIASWARN (timespec_get);
|
||||
# endif
|
||||
|
||||
/* Set *TS to the current time resolution, and return BASE.
|
||||
Upon failure, return 0. */
|
||||
# if 0
|
||||
# if ! 1
|
||||
_GL_FUNCDECL_SYS (timespec_getres, int, (struct timespec *ts, int base)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (timespec_getres, int, (struct timespec *ts, int base));
|
||||
_GL_CXXALIASWARN (timespec_getres);
|
||||
# endif
|
||||
|
||||
/* Sleep for at least RQTP seconds unless interrupted, If interrupted,
|
||||
return -1 and store the remaining time into RMTP. See
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html>. */
|
||||
# if 0
|
||||
# if GNULIB_PORTCHECK
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define nanosleep rpl_nanosleep
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (nanosleep, int,
|
||||
(struct timespec const *__rqtp, struct timespec *__rmtp)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (nanosleep, int,
|
||||
(struct timespec const *__rqtp, struct timespec *__rmtp));
|
||||
# else
|
||||
# if ! 1
|
||||
_GL_FUNCDECL_SYS (nanosleep, int,
|
||||
(struct timespec const *__rqtp, struct timespec *__rmtp)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (nanosleep, int,
|
||||
(struct timespec const *__rqtp, struct timespec *__rmtp));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (nanosleep);
|
||||
# endif
|
||||
|
||||
/* Initialize time conversion information. */
|
||||
# if 0
|
||||
# if GNULIB_PORTCHECK
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef tzset
|
||||
# define tzset rpl_tzset
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (tzset, void, (void));
|
||||
_GL_CXXALIAS_RPL (tzset, void, (void));
|
||||
# elif defined _WIN32 && !defined __CYGWIN__
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef tzset
|
||||
# define tzset _tzset
|
||||
# endif
|
||||
_GL_CXXALIAS_MDA (tzset, void, (void));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (tzset, void, (void));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (tzset);
|
||||
# elif 1
|
||||
/* On native Windows, map 'tzset' to '_tzset', so that -loldnames is not
|
||||
required. In C++ with GNULIB_NAMESPACE, avoid differences between
|
||||
platforms by defining GNULIB_NAMESPACE::tzset always. */
|
||||
# if defined _WIN32 && !defined __CYGWIN__
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef tzset
|
||||
# define tzset _tzset
|
||||
# endif
|
||||
_GL_CXXALIAS_MDA (tzset, void, (void));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (tzset, void, (void));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (tzset);
|
||||
# endif
|
||||
|
||||
/* Return the 'time_t' representation of TP and normalize TP. */
|
||||
# if 0
|
||||
# if GNULIB_PORTCHECK
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define mktime rpl_mktime
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
|
||||
# endif
|
||||
# if __GLIBC__ >= 2
|
||||
_GL_CXXALIASWARN (mktime);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime_r.html> and
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime_r.html>. */
|
||||
# if 0
|
||||
# if GNULIB_PORTCHECK
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef localtime_r
|
||||
# define localtime_r rpl_localtime_r
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result));
|
||||
# else
|
||||
# if ! 1
|
||||
_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result));
|
||||
# endif
|
||||
# if 1
|
||||
_GL_CXXALIASWARN (localtime_r);
|
||||
# endif
|
||||
# if GNULIB_PORTCHECK
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef gmtime_r
|
||||
# define gmtime_r rpl_gmtime_r
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result));
|
||||
# else
|
||||
# if ! 1
|
||||
_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result)
|
||||
_GL_ARG_NONNULL ((1, 2)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
|
||||
struct tm *restrict __result));
|
||||
# endif
|
||||
# if 1
|
||||
_GL_CXXALIASWARN (gmtime_r);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime.html> and
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime.html>. */
|
||||
# if 0 || 0
|
||||
# if 0
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef localtime
|
||||
# define localtime rpl_localtime
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
|
||||
# endif
|
||||
# if __GLIBC__ >= 2
|
||||
_GL_CXXALIASWARN (localtime);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if 0 || 0
|
||||
# if 0
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef gmtime
|
||||
# define gmtime rpl_gmtime
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (gmtime);
|
||||
# endif
|
||||
|
||||
/* Parse BUF as a timestamp, assuming FORMAT specifies its layout, and store
|
||||
the resulting broken-down time into TM. See
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html>. */
|
||||
# if 0
|
||||
# if ! 1
|
||||
_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
|
||||
char const *restrict __format,
|
||||
struct tm *restrict __tm)
|
||||
_GL_ARG_NONNULL ((1, 2, 3)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
|
||||
char const *restrict __format,
|
||||
struct tm *restrict __tm));
|
||||
_GL_CXXALIASWARN (strptime);
|
||||
# endif
|
||||
|
||||
/* Convert *TP to a date and time string. See
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/ctime.html>. */
|
||||
# if 0
|
||||
# if GNULIB_PORTCHECK
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define ctime rpl_ctime
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp)
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (ctime, char *, (time_t const *__tp));
|
||||
# endif
|
||||
# if __GLIBC__ >= 2
|
||||
_GL_CXXALIASWARN (ctime);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Convert *TP to a date and time string. See
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html>. */
|
||||
# if 0
|
||||
# if GNULIB_PORTCHECK
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# define strftime rpl_strftime
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (strftime, size_t,
|
||||
(char *restrict __buf, size_t __bufsize,
|
||||
const char *restrict __fmt, const struct tm *restrict __tp)
|
||||
_GL_ARG_NONNULL ((1, 3, 4)));
|
||||
_GL_CXXALIAS_RPL (strftime, size_t,
|
||||
(char *restrict __buf, size_t __bufsize,
|
||||
const char *restrict __fmt, const struct tm *restrict __tp));
|
||||
# else
|
||||
_GL_CXXALIAS_SYS (strftime, size_t,
|
||||
(char *restrict __buf, size_t __bufsize,
|
||||
const char *restrict __fmt, const struct tm *restrict __tp));
|
||||
# endif
|
||||
# if __GLIBC__ >= 2
|
||||
_GL_CXXALIASWARN (strftime);
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if defined _GNU_SOURCE && 0 && ! 0
|
||||
/* Functions that use a first-class time zone data type, instead of
|
||||
relying on an implicit global time zone.
|
||||
Inspired by NetBSD. */
|
||||
|
||||
/* Represents a time zone.
|
||||
(timezone_t) NULL stands for UTC. */
|
||||
typedef struct tm_zone *timezone_t;
|
||||
|
||||
/* tzalloc (name)
|
||||
Returns a time zone object for the given time zone NAME. This object
|
||||
represents the time zone that other functions would use it the TZ
|
||||
environment variable was set to NAME.
|
||||
If NAME is NULL, the result represents the time zone that other functions
|
||||
would use it the TZ environment variable was unset.
|
||||
May return NULL if NAME is invalid (this is platform dependent) or
|
||||
upon memory allocation failure. */
|
||||
_GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name));
|
||||
_GL_CXXALIAS_SYS (tzalloc, timezone_t, (char const *__name));
|
||||
|
||||
/* tzfree (tz)
|
||||
Frees a time zone object.
|
||||
The argument must have been returned by tzalloc(). */
|
||||
_GL_FUNCDECL_SYS (tzfree, void, (timezone_t __tz));
|
||||
_GL_CXXALIAS_SYS (tzfree, void, (timezone_t __tz));
|
||||
|
||||
/* localtime_rz (tz, &t, &result)
|
||||
Converts an absolute time T to a broken-down time RESULT, assuming the
|
||||
time zone TZ.
|
||||
This function is like 'localtime_r', but relies on the argument TZ instead
|
||||
of an implicit global time zone. */
|
||||
_GL_FUNCDECL_SYS (localtime_rz, struct tm *,
|
||||
(timezone_t __tz, time_t const *restrict __timer,
|
||||
struct tm *restrict __result) _GL_ARG_NONNULL ((2, 3)));
|
||||
_GL_CXXALIAS_SYS (localtime_rz, struct tm *,
|
||||
(timezone_t __tz, time_t const *restrict __timer,
|
||||
struct tm *restrict __result));
|
||||
|
||||
/* mktime_z (tz, &tm)
|
||||
Normalizes the broken-down time TM and converts it to an absolute time,
|
||||
assuming the time zone TZ. Returns the absolute time.
|
||||
This function is like 'mktime', but relies on the argument TZ instead
|
||||
of an implicit global time zone. */
|
||||
_GL_FUNCDECL_SYS (mktime_z, time_t,
|
||||
(timezone_t __tz, struct tm *restrict __tm)
|
||||
_GL_ARG_NONNULL ((2)));
|
||||
_GL_CXXALIAS_SYS (mktime_z, time_t,
|
||||
(timezone_t __tz, struct tm *restrict __tm));
|
||||
|
||||
/* Time zone abbreviation strings (returned by 'localtime_rz' or 'mktime_z'
|
||||
in the 'tm_zone' member of 'struct tm') are valid as long as
|
||||
- the 'struct tm' argument is not destroyed or overwritten,
|
||||
and
|
||||
- the 'timezone_t' argument is not freed through tzfree(). */
|
||||
|
||||
# endif
|
||||
|
||||
/* Convert TM to a time_t value, assuming UTC. */
|
||||
# if 0
|
||||
# if GNULIB_PORTCHECK
|
||||
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
|
||||
# undef timegm
|
||||
# define timegm rpl_timegm
|
||||
# endif
|
||||
_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
|
||||
_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
|
||||
# else
|
||||
# if ! 1
|
||||
_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
|
||||
# endif
|
||||
_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
|
||||
# endif
|
||||
_GL_CXXALIASWARN (timegm);
|
||||
# endif
|
||||
|
||||
/* Encourage applications to avoid unsafe functions that can overrun
|
||||
buffers when given outlandish struct tm values. Portable
|
||||
applications should use strftime (or even sprintf) instead. */
|
||||
# if defined GNULIB_POSIXCHECK
|
||||
# undef asctime
|
||||
_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
|
||||
"better use strftime (or even sprintf) instead");
|
||||
# endif
|
||||
# if defined GNULIB_POSIXCHECK
|
||||
# undef asctime_r
|
||||
_GL_WARN_ON_USE (asctime_r, "asctime_r can overrun buffers in some cases - "
|
||||
"better use strftime (or even sprintf) instead");
|
||||
# endif
|
||||
# if defined GNULIB_POSIXCHECK
|
||||
# undef ctime
|
||||
_GL_WARN_ON_USE (ctime, "ctime can overrun buffers in some cases - "
|
||||
"better use strftime (or even sprintf) instead");
|
||||
# endif
|
||||
# if defined GNULIB_POSIXCHECK
|
||||
# undef ctime_r
|
||||
_GL_WARN_ON_USE (ctime_r, "ctime_r can overrun buffers in some cases - "
|
||||
"better use strftime (or even sprintf) instead");
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@@ -1,48 +0,0 @@
|
||||
/* Three-level bitmap lookup.
|
||||
Copyright (C) 2000-2002, 2005-2007, 2009-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2000-2002.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
static inline int bitmap_lookup (const void *table, ucs4_t uc);
|
||||
|
||||
/* These values are currently hardcoded into gen-uni-tables.c, function
|
||||
output_predicate(). */
|
||||
#define header_0 16
|
||||
#define header_2 9
|
||||
#define header_3 127
|
||||
#define header_4 15
|
||||
|
||||
static inline int
|
||||
bitmap_lookup (const void *table, ucs4_t uc)
|
||||
{
|
||||
unsigned int index1 = uc >> header_0;
|
||||
if (index1 < ((const int *) table)[0])
|
||||
{
|
||||
int lookup1 = ((const int *) table)[1 + index1];
|
||||
if (lookup1 >= 0)
|
||||
{
|
||||
unsigned int index2 = (uc >> header_2) & header_3;
|
||||
int lookup2 = ((const short *) table)[lookup1 + index2];
|
||||
if (lookup2 >= 0)
|
||||
{
|
||||
unsigned int index3 = (uc >> 5) & header_4;
|
||||
unsigned int lookup3 = ((const unsigned int *) table)[lookup2 + index3];
|
||||
|
||||
return (lookup3 >> (uc & 0x1f)) & 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,62 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* Elementary types and macros for the GNU UniString library.
|
||||
Copyright (C) 2002, 2005-2006, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _UNITYPES_H
|
||||
#define _UNITYPES_H
|
||||
|
||||
/* Get uint8_t, uint16_t, uint32_t. */
|
||||
#include <stdint.h>
|
||||
|
||||
/* Type representing a Unicode character. */
|
||||
typedef uint32_t ucs4_t;
|
||||
|
||||
/* Attribute of a function whose result depends only on the arguments
|
||||
(not pointers!) and which has no side effects. */
|
||||
#ifndef _UC_ATTRIBUTE_CONST
|
||||
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) || defined __clang__
|
||||
# define _UC_ATTRIBUTE_CONST __attribute__ ((__const__))
|
||||
# else
|
||||
# define _UC_ATTRIBUTE_CONST
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Attribute of a function whose result depends only on the arguments
|
||||
(possibly pointers) and global memory, and which has no side effects. */
|
||||
#ifndef _UC_ATTRIBUTE_PURE
|
||||
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
|
||||
# define _UC_ATTRIBUTE_PURE __attribute__ ((__pure__))
|
||||
# else
|
||||
# define _UC_ATTRIBUTE_PURE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Qualifier in a function declaration, that asserts that the caller must
|
||||
pass a pointer to a different object in the specified pointer argument
|
||||
than in the other pointer arguments. */
|
||||
#ifndef _UC_RESTRICT
|
||||
# if defined __restrict \
|
||||
|| 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
|
||||
|| __clang_major__ >= 3
|
||||
# define _UC_RESTRICT __restrict
|
||||
# elif 199901L <= __STDC_VERSION__ || defined restrict
|
||||
# define _UC_RESTRICT restrict
|
||||
# else
|
||||
# define _UC_RESTRICT
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _UNITYPES_H */
|
||||
@@ -1,73 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* Display width functions.
|
||||
Copyright (C) 2001-2002, 2005, 2007, 2009-2022 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _UNIWIDTH_H
|
||||
#define _UNIWIDTH_H
|
||||
|
||||
#include "unitypes.h"
|
||||
|
||||
/* Get size_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Get locale_charset() declaration. */
|
||||
#include "localcharset.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Display width. */
|
||||
|
||||
/* These functions are locale dependent. The encoding argument identifies
|
||||
the encoding (e.g. "ISO-8859-2" for Polish). */
|
||||
|
||||
/* Determine number of column positions required for UC. */
|
||||
extern int
|
||||
uc_width (ucs4_t uc, const char *encoding)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Determine number of column positions required for first N units
|
||||
(or fewer if S ends before this) in S. */
|
||||
extern int
|
||||
u8_width (const uint8_t *s, size_t n, const char *encoding)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_width (const uint16_t *s, size_t n, const char *encoding)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_width (const uint32_t *s, size_t n, const char *encoding)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
/* Determine number of column positions required for S. */
|
||||
extern int
|
||||
u8_strwidth (const uint8_t *s, const char *encoding)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u16_strwidth (const uint16_t *s, const char *encoding)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
extern int
|
||||
u32_strwidth (const uint32_t *s, const char *encoding)
|
||||
_UC_ATTRIBUTE_PURE;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _UNIWIDTH_H */
|
||||
@@ -1,37 +0,0 @@
|
||||
/* Test for CJK encoding.
|
||||
Copyright (C) 2001-2002, 2005-2007, 2009-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2002.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "streq.h"
|
||||
|
||||
static int
|
||||
is_cjk_encoding (const char *encoding)
|
||||
{
|
||||
if (0
|
||||
/* Legacy Japanese encodings */
|
||||
|| STREQ_OPT (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)
|
||||
/* Legacy Chinese encodings */
|
||||
|| STREQ_OPT (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
|
||||
|| STREQ_OPT (encoding, "GBK", 'G', 'B', 'K', 0, 0, 0, 0, 0, 0)
|
||||
|| STREQ_OPT (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)
|
||||
|| STREQ_OPT (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)
|
||||
/* Legacy Korean encodings */
|
||||
|| STREQ_OPT (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
|
||||
|| STREQ_OPT (encoding, "CP949", 'C', 'P', '9', '4', '9', 0, 0, 0, 0)
|
||||
|| STREQ_OPT (encoding, "JOHAB", 'J', 'O', 'H', 'A', 'B', 0, 0, 0, 0))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/* Determine display width of Unicode character.
|
||||
Copyright (C) 2001-2002, 2006-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2002.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "uniwidth.h"
|
||||
|
||||
#include "cjk.h"
|
||||
|
||||
/* The non-spacing attribute table consists of:
|
||||
* Non-spacing characters; generated from PropList.txt or
|
||||
"grep '^[^;]*;[^;]*;[^;]*;[^;]*;NSM;' UnicodeData.txt"
|
||||
* Format control characters; generated from
|
||||
"grep '^[^;]*;[^;]*;Cf;' UnicodeData.txt"
|
||||
* Zero width characters; generated from
|
||||
"grep '^[^;]*;ZERO WIDTH ' UnicodeData.txt"
|
||||
* Hangul Jamo characters that have conjoining behaviour:
|
||||
- jungseong = syllable-middle vowels
|
||||
- jongseong = syllable-final consonants
|
||||
Rationale:
|
||||
1) These characters act like combining characters. They have no
|
||||
equivalent in legacy character sets. Therefore the EastAsianWidth.txt
|
||||
file does not really matter for them; UAX #11 East Asian Width
|
||||
<https://www.unicode.org/reports/tr11/> makes it clear that it focus
|
||||
is on compatibility with traditional Japanese layout.
|
||||
By contrast, the same glyphs without conjoining behaviour are available
|
||||
in the U+3130..U+318F block, and these characters are mapped to legacy
|
||||
character sets, and traditional Japanese layout matters for them.
|
||||
2) glibc does the same thing, see
|
||||
<https://sourceware.org/bugzilla/show_bug.cgi?id=21750>
|
||||
<https://sourceware.org/bugzilla/show_bug.cgi?id=26120>
|
||||
*/
|
||||
#include "uniwidth/width0.h"
|
||||
|
||||
#include "uniwidth/width2.h"
|
||||
#include "unictype/bitmap.h"
|
||||
|
||||
#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
|
||||
/* Determine number of column positions required for UC. */
|
||||
int
|
||||
uc_width (ucs4_t uc, const char *encoding)
|
||||
{
|
||||
/* Test for non-spacing or control character. */
|
||||
if ((uc >> 9) < SIZEOF (nonspacing_table_ind))
|
||||
{
|
||||
int ind = nonspacing_table_ind[uc >> 9];
|
||||
if (ind >= 0)
|
||||
if ((nonspacing_table_data[64*ind + ((uc >> 3) & 63)] >> (uc & 7)) & 1)
|
||||
{
|
||||
if (uc > 0 && uc < 0xa0)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if ((uc >> 9) == (0xe0000 >> 9))
|
||||
{
|
||||
if (uc >= 0xe0100)
|
||||
{
|
||||
if (uc <= 0xe01ef)
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (uc >= 0xe0020 ? uc <= 0xe007f : uc == 0xe0001)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* Test for double-width character. */
|
||||
if (bitmap_lookup (&u_width2, uc))
|
||||
return 2;
|
||||
/* In ancient CJK encodings, Cyrillic and most other characters are
|
||||
double-width as well. */
|
||||
if (uc >= 0x00A1 && uc < 0xFF61 && uc != 0x20A9
|
||||
&& is_cjk_encoding (encoding))
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
@@ -1,485 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* Table of non-spacing or control characters. */
|
||||
/* Generated automatically by gen-uni-tables.c for Unicode 14.0.0. */
|
||||
|
||||
/* Copyright (C) 2000-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software.
|
||||
It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
|
||||
You can redistribute it and/or modify it under either
|
||||
- the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation, either version 3, or (at your
|
||||
option) any later version, or
|
||||
- the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option)
|
||||
any later version, or
|
||||
- the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License and the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License and of the GNU General Public License along with this
|
||||
program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
static const unsigned char nonspacing_table_data[47*64] = {
|
||||
/* 0x0000-0x01ff */
|
||||
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0x0000-0x003f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0x0040-0x007f */
|
||||
0xff, 0xff, 0xff, 0xff, 0x00, 0x20, 0x00, 0x00, /* 0x0080-0x00bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00c0-0x00ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0100-0x013f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0140-0x017f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0180-0x01bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x01c0-0x01ff */
|
||||
/* 0x0200-0x03ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0200-0x023f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0240-0x027f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0280-0x02bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02c0-0x02ff */
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x0300-0x033f */
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, /* 0x0340-0x037f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0380-0x03bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x03c0-0x03ff */
|
||||
/* 0x0400-0x05ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0400-0x043f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0440-0x047f */
|
||||
0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0480-0x04bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x04c0-0x04ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0500-0x053f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0540-0x057f */
|
||||
0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xbf, /* 0x0580-0x05bf */
|
||||
0xb6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x05c0-0x05ff */
|
||||
/* 0x0600-0x07ff */
|
||||
0x3f, 0x00, 0xff, 0x17, 0x00, 0x00, 0x00, 0x00, /* 0x0600-0x063f */
|
||||
0x00, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x01, 0x00, /* 0x0640-0x067f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0680-0x06bf */
|
||||
0x00, 0x00, 0xc0, 0xbf, 0x9f, 0x3d, 0x00, 0x00, /* 0x06c0-0x06ff */
|
||||
0x00, 0x80, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, /* 0x0700-0x073f */
|
||||
0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0740-0x077f */
|
||||
0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x01, 0x00, /* 0x0780-0x07bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x20, /* 0x07c0-0x07ff */
|
||||
/* 0x0800-0x09ff */
|
||||
0x00, 0x00, 0xc0, 0xfb, 0xef, 0x3e, 0x00, 0x00, /* 0x0800-0x083f */
|
||||
0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, /* 0x0840-0x087f */
|
||||
0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0x0880-0x08bf */
|
||||
0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08c0-0x08ff */
|
||||
0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, /* 0x0900-0x093f */
|
||||
0xfe, 0x21, 0xfe, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0940-0x097f */
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0980-0x09bf */
|
||||
0x1e, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x40, /* 0x09c0-0x09ff */
|
||||
/* 0x0a00-0x0bff */
|
||||
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0a00-0x0a3f */
|
||||
0x86, 0x39, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, /* 0x0a40-0x0a7f */
|
||||
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0a80-0x0abf */
|
||||
0xbe, 0x21, 0x00, 0x00, 0x0c, 0x00, 0x00, 0xfc, /* 0x0ac0-0x0aff */
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, /* 0x0b00-0x0b3f */
|
||||
0x1e, 0x20, 0x60, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0b40-0x0b7f */
|
||||
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0b80-0x0bbf */
|
||||
0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0bc0-0x0bff */
|
||||
/* 0x0c00-0x0dff */
|
||||
0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, /* 0x0c00-0x0c3f */
|
||||
0xc1, 0x3d, 0x60, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0c40-0x0c7f */
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0c80-0x0cbf */
|
||||
0x00, 0x30, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0cc0-0x0cff */
|
||||
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, /* 0x0d00-0x0d3f */
|
||||
0x1e, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0d40-0x0d7f */
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0d80-0x0dbf */
|
||||
0x00, 0x04, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0dc0-0x0dff */
|
||||
/* 0x0e00-0x0fff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x07, /* 0x0e00-0x0e3f */
|
||||
0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0e40-0x0e7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x1f, /* 0x0e80-0x0ebf */
|
||||
0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0ec0-0x0eff */
|
||||
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xa0, 0x02, /* 0x0f00-0x0f3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, /* 0x0f40-0x0f7f */
|
||||
0xdf, 0xe0, 0xff, 0xfe, 0xff, 0xff, 0xff, 0x1f, /* 0x0f80-0x0fbf */
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0fc0-0x0fff */
|
||||
/* 0x1000-0x11ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x66, /* 0x1000-0x103f */
|
||||
0x00, 0x00, 0x00, 0xc3, 0x01, 0x00, 0x1e, 0x00, /* 0x1040-0x107f */
|
||||
0x64, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, /* 0x1080-0x10bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10c0-0x10ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1100-0x113f */
|
||||
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, /* 0x1140-0x117f */
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x1180-0x11bf */
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x11c0-0x11ff */
|
||||
/* 0x1200-0x13ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1200-0x123f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1240-0x127f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1280-0x12bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x12c0-0x12ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1300-0x133f */
|
||||
0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, /* 0x1340-0x137f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1380-0x13bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x13c0-0x13ff */
|
||||
/* 0x1600-0x17ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1600-0x163f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1640-0x167f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1680-0x16bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16c0-0x16ff */
|
||||
0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x0c, 0x00, /* 0x1700-0x173f */
|
||||
0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, /* 0x1740-0x177f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x3f, /* 0x1780-0x17bf */
|
||||
0x40, 0xfe, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x00, /* 0x17c0-0x17ff */
|
||||
/* 0x1800-0x19ff */
|
||||
0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1800-0x183f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1840-0x187f */
|
||||
0x60, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* 0x1880-0x18bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18c0-0x18ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x87, 0x01, 0x04, 0x0e, /* 0x1900-0x193f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1940-0x197f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1980-0x19bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x19c0-0x19ff */
|
||||
/* 0x1a00-0x1bff */
|
||||
0x00, 0x00, 0x80, 0x09, 0x00, 0x00, 0x00, 0x00, /* 0x1a00-0x1a3f */
|
||||
0x00, 0x00, 0x40, 0x7f, 0xe5, 0x1f, 0xf8, 0x9f, /* 0x1a40-0x1a7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, /* 0x1a80-0x1abf */
|
||||
0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1ac0-0x1aff */
|
||||
0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x17, /* 0x1b00-0x1b3f */
|
||||
0x04, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00, /* 0x1b40-0x1b7f */
|
||||
0x03, 0x00, 0x00, 0x00, 0x3c, 0x3b, 0x00, 0x00, /* 0x1b80-0x1bbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x40, 0xa3, 0x03, 0x00, /* 0x1bc0-0x1bff */
|
||||
/* 0x1c00-0x1dff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xcf, 0x00, /* 0x1c00-0x1c3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1c40-0x1c7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1c80-0x1cbf */
|
||||
0x00, 0x00, 0xf7, 0xff, 0xfd, 0x21, 0x10, 0x03, /* 0x1cc0-0x1cff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d00-0x1d3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d40-0x1d7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d80-0x1dbf */
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x1dc0-0x1dff */
|
||||
/* 0x2000-0x21ff */
|
||||
0x00, 0xf8, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, /* 0x2000-0x203f */
|
||||
0x00, 0x00, 0x00, 0x00, 0xdf, 0xff, 0x00, 0x00, /* 0x2040-0x207f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2080-0x20bf */
|
||||
0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, /* 0x20c0-0x20ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2100-0x213f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2140-0x217f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2180-0x21bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x21c0-0x21ff */
|
||||
/* 0x2c00-0x2dff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c00-0x2c3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c40-0x2c7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c80-0x2cbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, /* 0x2cc0-0x2cff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d00-0x2d3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0x2d40-0x2d7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d80-0x2dbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, /* 0x2dc0-0x2dff */
|
||||
/* 0x3000-0x31ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, /* 0x3000-0x303f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3040-0x307f */
|
||||
0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, /* 0x3080-0x30bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30c0-0x30ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3100-0x313f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3140-0x317f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3180-0x31bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x31c0-0x31ff */
|
||||
/* 0xa600-0xa7ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa600-0xa63f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xf7, 0x3f, /* 0xa640-0xa67f */
|
||||
0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, /* 0xa680-0xa6bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, /* 0xa6c0-0xa6ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa700-0xa73f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa740-0xa77f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa780-0xa7bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa7c0-0xa7ff */
|
||||
/* 0xa800-0xa9ff */
|
||||
0x44, 0x08, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, /* 0xa800-0xa83f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa840-0xa87f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa880-0xa8bf */
|
||||
0x30, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0x80, /* 0xa8c0-0xa8ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, /* 0xa900-0xa93f */
|
||||
0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa940-0xa97f */
|
||||
0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x33, /* 0xa980-0xa9bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, /* 0xa9c0-0xa9ff */
|
||||
/* 0xaa00-0xabff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x66, 0x00, /* 0xaa00-0xaa3f */
|
||||
0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0xaa40-0xaa7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9d, 0xc1, /* 0xaa80-0xaabf */
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x30, 0x40, 0x00, /* 0xaac0-0xaaff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab00-0xab3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab40-0xab7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab80-0xabbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x20, 0x21, 0x00, 0x00, /* 0xabc0-0xabff */
|
||||
/* 0xd600-0xd7ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd600-0xd63f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd640-0xd67f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd680-0xd6bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd6c0-0xd6ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd700-0xd73f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd740-0xd77f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, /* 0xd780-0xd7bf */
|
||||
0x7f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, /* 0xd7c0-0xd7ff */
|
||||
/* 0xfa00-0xfbff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa00-0xfa3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa40-0xfa7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa80-0xfabf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfac0-0xfaff */
|
||||
0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, /* 0xfb00-0xfb3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfb40-0xfb7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfb80-0xfbbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfbc0-0xfbff */
|
||||
/* 0xfe00-0xffff */
|
||||
0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, /* 0xfe00-0xfe3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfe40-0xfe7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfe80-0xfebf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0xfec0-0xfeff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff00-0xff3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff40-0xff7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff80-0xffbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, /* 0xffc0-0xffff */
|
||||
/* 0x10000-0x101ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10000-0x1003f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10040-0x1007f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10080-0x100bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x100c0-0x100ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10100-0x1013f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10140-0x1017f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10180-0x101bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, /* 0x101c0-0x101ff */
|
||||
/* 0x10200-0x103ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10200-0x1023f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10240-0x1027f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10280-0x102bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, /* 0x102c0-0x102ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10300-0x1033f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, /* 0x10340-0x1037f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10380-0x103bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x103c0-0x103ff */
|
||||
/* 0x10a00-0x10bff */
|
||||
0x6e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, /* 0x10a00-0x10a3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10a40-0x10a7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10a80-0x10abf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, /* 0x10ac0-0x10aff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b00-0x10b3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b40-0x10b7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b80-0x10bbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10bc0-0x10bff */
|
||||
/* 0x10c00-0x10dff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10c00-0x10c3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10c40-0x10c7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10c80-0x10cbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10cc0-0x10cff */
|
||||
0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, /* 0x10d00-0x10d3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10d40-0x10d7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10d80-0x10dbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10dc0-0x10dff */
|
||||
/* 0x10e00-0x10fff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10e00-0x10e3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10e40-0x10e7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, /* 0x10e80-0x10ebf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10ec0-0x10eff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10f00-0x10f3f */
|
||||
0xc0, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10f40-0x10f7f */
|
||||
0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10f80-0x10fbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10fc0-0x10fff */
|
||||
/* 0x11000-0x111ff */
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* 0x11000-0x1103f */
|
||||
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x80, /* 0x11040-0x1107f */
|
||||
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x26, /* 0x11080-0x110bf */
|
||||
0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x110c0-0x110ff */
|
||||
0x07, 0x00, 0x00, 0x00, 0x80, 0xef, 0x1f, 0x00, /* 0x11100-0x1113f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, /* 0x11140-0x1117f */
|
||||
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x7f, /* 0x11180-0x111bf */
|
||||
0x00, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x111c0-0x111ff */
|
||||
/* 0x11200-0x113ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xd3, 0x40, /* 0x11200-0x1123f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11240-0x1127f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11280-0x112bf */
|
||||
0x00, 0x00, 0x00, 0x80, 0xf8, 0x07, 0x00, 0x00, /* 0x112c0-0x112ff */
|
||||
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, /* 0x11300-0x1133f */
|
||||
0x01, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0x1f, 0x00, /* 0x11340-0x1137f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11380-0x113bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x113c0-0x113ff */
|
||||
/* 0x11400-0x115ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* 0x11400-0x1143f */
|
||||
0x5c, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, /* 0x11440-0x1147f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x85, /* 0x11480-0x114bf */
|
||||
0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x114c0-0x114ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11500-0x1153f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11540-0x1157f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0xb0, /* 0x11580-0x115bf */
|
||||
0x01, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, /* 0x115c0-0x115ff */
|
||||
/* 0x11600-0x117ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xa7, /* 0x11600-0x1163f */
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11640-0x1167f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0xbf, 0x00, /* 0x11680-0x116bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x116c0-0x116ff */
|
||||
0x00, 0x00, 0x00, 0xe0, 0xbc, 0x0f, 0x00, 0x00, /* 0x11700-0x1173f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11740-0x1177f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11780-0x117bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x117c0-0x117ff */
|
||||
/* 0x11800-0x119ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x06, /* 0x11800-0x1183f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11840-0x1187f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11880-0x118bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x118c0-0x118ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, /* 0x11900-0x1193f */
|
||||
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11940-0x1197f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11980-0x119bf */
|
||||
0x00, 0x00, 0xf0, 0x0c, 0x01, 0x00, 0x00, 0x00, /* 0x119c0-0x119ff */
|
||||
/* 0x11a00-0x11bff */
|
||||
0x7e, 0x06, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x79, /* 0x11a00-0x11a3f */
|
||||
0x80, 0x00, 0x7e, 0x0e, 0x00, 0x00, 0x00, 0x00, /* 0x11a40-0x11a7f */
|
||||
0x00, 0xfc, 0x7f, 0x03, 0x00, 0x00, 0x00, 0x00, /* 0x11a80-0x11abf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11ac0-0x11aff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11b00-0x11b3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11b40-0x11b7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11b80-0x11bbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11bc0-0x11bff */
|
||||
/* 0x11c00-0x11dff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x3f, /* 0x11c00-0x11c3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11c40-0x11c7f */
|
||||
0x00, 0x00, 0xfc, 0xff, 0xff, 0xfc, 0x6d, 0x00, /* 0x11c80-0x11cbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11cc0-0x11cff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xb4, /* 0x11d00-0x11d3f */
|
||||
0xbf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11d40-0x11d7f */
|
||||
0x00, 0x00, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11d80-0x11dbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11dc0-0x11dff */
|
||||
/* 0x11e00-0x11fff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11e00-0x11e3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11e40-0x11e7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11e80-0x11ebf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, /* 0x11ec0-0x11eff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11f00-0x11f3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11f40-0x11f7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11f80-0x11fbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11fc0-0x11fff */
|
||||
/* 0x13400-0x135ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, /* 0x13400-0x1343f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x13440-0x1347f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x13480-0x134bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x134c0-0x134ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x13500-0x1353f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x13540-0x1357f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x13580-0x135bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x135c0-0x135ff */
|
||||
/* 0x16a00-0x16bff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16a00-0x16a3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16a40-0x16a7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16a80-0x16abf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, /* 0x16ac0-0x16aff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, /* 0x16b00-0x16b3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16b40-0x16b7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16b80-0x16bbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16bc0-0x16bff */
|
||||
/* 0x16e00-0x16fff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16e00-0x16e3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16e40-0x16e7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16e80-0x16ebf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16ec0-0x16eff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16f00-0x16f3f */
|
||||
0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16f40-0x16f7f */
|
||||
0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16f80-0x16fbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, /* 0x16fc0-0x16fff */
|
||||
/* 0x1bc00-0x1bdff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1bc00-0x1bc3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1bc40-0x1bc7f */
|
||||
0x00, 0x00, 0x00, 0x60, 0x0f, 0x00, 0x00, 0x00, /* 0x1bc80-0x1bcbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1bcc0-0x1bcff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1bd00-0x1bd3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1bd40-0x1bd7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1bd80-0x1bdbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1bdc0-0x1bdff */
|
||||
/* 0x1ce00-0x1cfff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1ce00-0x1ce3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1ce40-0x1ce7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1ce80-0x1cebf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1cec0-0x1ceff */
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, /* 0x1cf00-0x1cf3f */
|
||||
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1cf40-0x1cf7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1cf80-0x1cfbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1cfc0-0x1cfff */
|
||||
/* 0x1d000-0x1d1ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d000-0x1d03f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d040-0x1d07f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d080-0x1d0bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d0c0-0x1d0ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d100-0x1d13f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0xf8, 0xff, /* 0x1d140-0x1d17f */
|
||||
0xe7, 0x0f, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, /* 0x1d180-0x1d1bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d1c0-0x1d1ff */
|
||||
/* 0x1d200-0x1d3ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d200-0x1d23f */
|
||||
0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d240-0x1d27f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d280-0x1d2bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d2c0-0x1d2ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d300-0x1d33f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d340-0x1d37f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d380-0x1d3bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d3c0-0x1d3ff */
|
||||
/* 0x1da00-0x1dbff */
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xf8, /* 0x1da00-0x1da3f */
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x20, 0x00, /* 0x1da40-0x1da7f */
|
||||
0x10, 0x00, 0x00, 0xf8, 0xfe, 0xff, 0x00, 0x00, /* 0x1da80-0x1dabf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1dac0-0x1daff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1db00-0x1db3f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1db40-0x1db7f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1db80-0x1dbbf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1dbc0-0x1dbff */
|
||||
/* 0x1e000-0x1e1ff */
|
||||
0x7f, 0xff, 0xff, 0xf9, 0xdb, 0x07, 0x00, 0x00, /* 0x1e000-0x1e03f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e040-0x1e07f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e080-0x1e0bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e0c0-0x1e0ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, /* 0x1e100-0x1e13f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e140-0x1e17f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e180-0x1e1bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e1c0-0x1e1ff */
|
||||
/* 0x1e200-0x1e3ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e200-0x1e23f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e240-0x1e27f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, /* 0x1e280-0x1e2bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, /* 0x1e2c0-0x1e2ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e300-0x1e33f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e340-0x1e37f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e380-0x1e3bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e3c0-0x1e3ff */
|
||||
/* 0x1e800-0x1e9ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e800-0x1e83f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e840-0x1e87f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e880-0x1e8bf */
|
||||
0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e8c0-0x1e8ff */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e900-0x1e93f */
|
||||
0xf0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e940-0x1e97f */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1e980-0x1e9bf */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0x1e9c0-0x1e9ff */
|
||||
};
|
||||
static const signed char nonspacing_table_ind[248] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, /* 0x0000-0x0fff */
|
||||
8, 9, -1, 10, 11, 12, 13, -1, /* 0x1000-0x1fff */
|
||||
14, -1, -1, -1, -1, -1, 15, -1, /* 0x2000-0x2fff */
|
||||
16, -1, -1, -1, -1, -1, -1, -1, /* 0x3000-0x3fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x4000-0x4fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x5000-0x5fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x6000-0x6fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x7000-0x7fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x8000-0x8fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x9000-0x9fff */
|
||||
-1, -1, -1, 17, 18, 19, -1, -1, /* 0xa000-0xafff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0xb000-0xbfff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0xc000-0xcfff */
|
||||
-1, -1, -1, 20, -1, -1, -1, -1, /* 0xd000-0xdfff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0xe000-0xefff */
|
||||
-1, -1, -1, -1, -1, 21, -1, 22, /* 0xf000-0xffff */
|
||||
23, 24, -1, -1, -1, 25, 26, 27, /* 0x10000-0x10fff */
|
||||
28, 29, 30, 31, 32, 33, 34, 35, /* 0x11000-0x11fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x12000-0x12fff */
|
||||
-1, -1, 36, -1, -1, -1, -1, -1, /* 0x13000-0x13fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x14000-0x14fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x15000-0x15fff */
|
||||
-1, -1, -1, -1, -1, 37, -1, 38, /* 0x16000-0x16fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x17000-0x17fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x18000-0x18fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x19000-0x19fff */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x1a000-0x1afff */
|
||||
-1, -1, -1, -1, -1, -1, 39, -1, /* 0x1b000-0x1bfff */
|
||||
-1, -1, -1, -1, -1, -1, -1, 40, /* 0x1c000-0x1cfff */
|
||||
41, 42, -1, -1, -1, 43, -1, -1, /* 0x1d000-0x1dfff */
|
||||
44, 45, -1, -1, 46, -1, -1, -1 /* 0x1e000-0x1efff */
|
||||
};
|
||||
@@ -1,549 +0,0 @@
|
||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||
/* Width 2 property of Unicode characters. */
|
||||
/* Generated automatically by gen-uni-tables.c for Unicode 14.0.0. */
|
||||
|
||||
/* Copyright (C) 2000-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software.
|
||||
It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
|
||||
You can redistribute it and/or modify it under either
|
||||
- the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation, either version 3, or (at your
|
||||
option) any later version, or
|
||||
- the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option)
|
||||
any later version, or
|
||||
- the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License and the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License and of the GNU General Public License along with this
|
||||
program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#define header_0 16
|
||||
#define header_2 9
|
||||
#define header_3 127
|
||||
#define header_4 15
|
||||
static const
|
||||
struct
|
||||
{
|
||||
int header[1];
|
||||
int level1[4];
|
||||
short level2[3 << 7];
|
||||
unsigned int level3[28 << 4];
|
||||
}
|
||||
u_width2 =
|
||||
{
|
||||
{ 4 },
|
||||
{
|
||||
5 * sizeof (int) / sizeof (short) + 0,
|
||||
5 * sizeof (int) / sizeof (short) + 128,
|
||||
5 * sizeof (int) / sizeof (short) + 256,
|
||||
5 * sizeof (int) / sizeof (short) + 256
|
||||
},
|
||||
{
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 0,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 16,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 32,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 48,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 64,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 80,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 96,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 112,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 144,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 160,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 176,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 192,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 208,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 224,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 240,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 256,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 272,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 288,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 304,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 320,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 336,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 352,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 368,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 384,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 400,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 416,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 432,
|
||||
-1,
|
||||
-1,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128,
|
||||
5 + 384 * sizeof (short) / sizeof (int) + 128
|
||||
},
|
||||
{
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x0C000000U, 0x00000600U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00091E00U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x60000000U,
|
||||
0x00300000U, 0x00000000U, 0x000FFF00U, 0x80000000U,
|
||||
0x00080000U, 0x60000C02U, 0x00104030U, 0x242C0400U,
|
||||
0x00000C20U, 0x00000100U, 0x00B85000U, 0x00000000U,
|
||||
0x00E00000U, 0x80010000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x18000000U, 0x00000000U, 0x00210000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0x7FFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFF00FFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0x00000000U, 0x00000000U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0x0000FFFFU, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x1FFFFFFFU,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0x0000000FU, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0xFFFF0000U, 0xFFFF0000U, 0xFFFFFFFFU, 0x0000FFFFU,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0x00000001U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x0000007FU,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x0003000FU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0x00FFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0x003FFFFFU, 0x00000000U,
|
||||
0x000001FFU, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x6FEF0000U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0x00000007U, 0x00070000U, 0xFFFF00F0U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0x0FFFFFFFU,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000010U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00008000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x07FE4000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFBFE001U, 0xFFFFFFFFU, 0xDFFFFFFFU,
|
||||
0x000FFFFFU, 0xFFFFFFFFU, 0x000F87FFU, 0xFF11FFFFU,
|
||||
0xFFFFFFFFU, 0x7FFFFFFFU, 0xFFFFFFFDU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0x9FFFFFFFU,
|
||||
0xFFFFFFFFU, 0x3FFFFFFFU, 0xFFFF7800U, 0x040000FFU,
|
||||
0x00600000U, 0x00000010U, 0x00000000U, 0xF8000000U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0x0000FFFFU, 0x00000000U,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xE0E7103FU, 0x1FF01800U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00010FFFU,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0xFFFFF000U, 0xF7FFFFFFU, 0xFFFFFFBFU, 0xFFFFFFFFU,
|
||||
0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x1F1F0000U,
|
||||
0xFFFF007FU, 0x07FF1FFFU, 0x03FF003FU, 0x007F00FFU,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U,
|
||||
0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U
|
||||
}
|
||||
};
|
||||
@@ -1,136 +0,0 @@
|
||||
/* Prefer faster, non-thread-safe stdio functions if available.
|
||||
|
||||
Copyright (C) 2001-2004, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
#ifndef UNLOCKED_IO_H
|
||||
# define UNLOCKED_IO_H 1
|
||||
|
||||
/* These are wrappers for functions/macros from the GNU C library, and
|
||||
from other C libraries supporting POSIX's optional thread-safe functions.
|
||||
|
||||
The standard I/O functions are thread-safe. These *_unlocked ones are
|
||||
more efficient but not thread-safe. That they're not thread-safe is
|
||||
fine since all of the applications in this package are single threaded.
|
||||
|
||||
Also, some code that is shared with the GNU C library may invoke
|
||||
the *_unlocked functions directly. On hosts that lack those
|
||||
functions, invoke the non-thread-safe versions instead. */
|
||||
|
||||
# include <stdio.h>
|
||||
|
||||
# if HAVE_DECL_CLEARERR_UNLOCKED || defined clearerr_unlocked
|
||||
# undef clearerr
|
||||
# define clearerr(x) clearerr_unlocked (x)
|
||||
# else
|
||||
# define clearerr_unlocked(x) clearerr (x)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_FEOF_UNLOCKED || defined feof_unlocked
|
||||
# undef feof
|
||||
# define feof(x) feof_unlocked (x)
|
||||
# else
|
||||
# define feof_unlocked(x) feof (x)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_FERROR_UNLOCKED || defined ferror_unlocked
|
||||
# undef ferror
|
||||
# define ferror(x) ferror_unlocked (x)
|
||||
# else
|
||||
# define ferror_unlocked(x) ferror (x)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_FFLUSH_UNLOCKED || defined fflush_unlocked
|
||||
# undef fflush
|
||||
# define fflush(x) fflush_unlocked (x)
|
||||
# else
|
||||
# define fflush_unlocked(x) fflush (x)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_FGETS_UNLOCKED || defined fgets_unlocked
|
||||
# undef fgets
|
||||
# define fgets(x,y,z) fgets_unlocked (x,y,z)
|
||||
# else
|
||||
# define fgets_unlocked(x,y,z) fgets (x,y,z)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_FPUTC_UNLOCKED || defined fputc_unlocked
|
||||
# undef fputc
|
||||
# define fputc(x,y) fputc_unlocked (x,y)
|
||||
# else
|
||||
# define fputc_unlocked(x,y) fputc (x,y)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_FPUTS_UNLOCKED || defined fputs_unlocked
|
||||
# undef fputs
|
||||
# define fputs(x,y) fputs_unlocked (x,y)
|
||||
# else
|
||||
# define fputs_unlocked(x,y) fputs (x,y)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_FREAD_UNLOCKED || defined fread_unlocked
|
||||
# undef fread
|
||||
# define fread(w,x,y,z) fread_unlocked (w,x,y,z)
|
||||
# else
|
||||
# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_FWRITE_UNLOCKED || defined fwrite_unlocked
|
||||
# undef fwrite
|
||||
# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
|
||||
# else
|
||||
# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_GETC_UNLOCKED || defined get_unlocked
|
||||
# undef getc
|
||||
# define getc(x) getc_unlocked (x)
|
||||
# else
|
||||
# define getc_unlocked(x) getc (x)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_GETCHAR_UNLOCKED || defined getchar_unlocked
|
||||
# undef getchar
|
||||
# define getchar() getchar_unlocked ()
|
||||
# else
|
||||
# define getchar_unlocked() getchar ()
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_PUTC_UNLOCKED || defined putc_unlocked
|
||||
# undef putc
|
||||
# define putc(x,y) putc_unlocked (x,y)
|
||||
# else
|
||||
# define putc_unlocked(x,y) putc (x,y)
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_PUTCHAR_UNLOCKED || defined putchar_unlocked
|
||||
# undef putchar
|
||||
# define putchar(x) putchar_unlocked (x)
|
||||
# else
|
||||
# define putchar_unlocked(x) putchar (x)
|
||||
# endif
|
||||
|
||||
# undef flockfile
|
||||
# define flockfile(x) ((void) 0)
|
||||
|
||||
# undef ftrylockfile
|
||||
# define ftrylockfile(x) 0
|
||||
|
||||
# undef funlockfile
|
||||
# define funlockfile(x) ((void) 0)
|
||||
|
||||
#endif /* UNLOCKED_IO_H */
|
||||
@@ -1,318 +0,0 @@
|
||||
/* Compile-time assert-like macros.
|
||||
|
||||
Copyright (C) 2005-2006, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
|
||||
|
||||
#ifndef _GL_VERIFY_H
|
||||
#define _GL_VERIFY_H
|
||||
|
||||
|
||||
/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC)
|
||||
works as per C11. This is supported by GCC 4.6.0+ and by clang 4+.
|
||||
|
||||
Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as
|
||||
per C2x. This is supported by GCC 9.1+.
|
||||
|
||||
Support compilers claiming conformance to the relevant standard,
|
||||
and also support GCC when not pedantic. If we were willing to slow
|
||||
'configure' down we could also use it with other compilers, but
|
||||
since this affects only the quality of diagnostics, why bother? */
|
||||
#ifndef __cplusplus
|
||||
# if (201112L <= __STDC_VERSION__ \
|
||||
|| (!defined __STRICT_ANSI__ \
|
||||
&& (4 < __GNUC__ + (6 <= __GNUC_MINOR__) || 5 <= __clang_major__)))
|
||||
# define _GL_HAVE__STATIC_ASSERT 1
|
||||
# endif
|
||||
# if (202000L <= __STDC_VERSION__ \
|
||||
|| (!defined __STRICT_ANSI__ && 9 <= __GNUC__))
|
||||
# define _GL_HAVE__STATIC_ASSERT1 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
|
||||
system headers, defines a conflicting _Static_assert that is no
|
||||
better than ours; override it. */
|
||||
#ifndef _GL_HAVE__STATIC_ASSERT
|
||||
# include <stddef.h>
|
||||
# undef _Static_assert
|
||||
#endif
|
||||
|
||||
/* Each of these macros verifies that its argument R is nonzero. To
|
||||
be portable, R should be an integer constant expression. Unlike
|
||||
assert (R), there is no run-time overhead.
|
||||
|
||||
If _Static_assert works, verify (R) uses it directly. Similarly,
|
||||
_GL_VERIFY_TRUE works by packaging a _Static_assert inside a struct
|
||||
that is an operand of sizeof.
|
||||
|
||||
The code below uses several ideas for C++ compilers, and for C
|
||||
compilers that do not support _Static_assert:
|
||||
|
||||
* The first step is ((R) ? 1 : -1). Given an expression R, of
|
||||
integral or boolean or floating-point type, this yields an
|
||||
expression of integral type, whose value is later verified to be
|
||||
constant and nonnegative.
|
||||
|
||||
* Next this expression W is wrapped in a type
|
||||
struct _gl_verify_type {
|
||||
unsigned int _gl_verify_error_if_negative: W;
|
||||
}.
|
||||
If W is negative, this yields a compile-time error. No compiler can
|
||||
deal with a bit-field of negative size.
|
||||
|
||||
One might think that an array size check would have the same
|
||||
effect, that is, that the type struct { unsigned int dummy[W]; }
|
||||
would work as well. However, inside a function, some compilers
|
||||
(such as C++ compilers and GNU C) allow local parameters and
|
||||
variables inside array size expressions. With these compilers,
|
||||
an array size check would not properly diagnose this misuse of
|
||||
the verify macro:
|
||||
|
||||
void function (int n) { verify (n < 0); }
|
||||
|
||||
* For the verify macro, the struct _gl_verify_type will need to
|
||||
somehow be embedded into a declaration. To be portable, this
|
||||
declaration must declare an object, a constant, a function, or a
|
||||
typedef name. If the declared entity uses the type directly,
|
||||
such as in
|
||||
|
||||
struct dummy {...};
|
||||
typedef struct {...} dummy;
|
||||
extern struct {...} *dummy;
|
||||
extern void dummy (struct {...} *);
|
||||
extern struct {...} *dummy (void);
|
||||
|
||||
two uses of the verify macro would yield colliding declarations
|
||||
if the entity names are not disambiguated. A workaround is to
|
||||
attach the current line number to the entity name:
|
||||
|
||||
#define _GL_CONCAT0(x, y) x##y
|
||||
#define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
|
||||
extern struct {...} * _GL_CONCAT (dummy, __LINE__);
|
||||
|
||||
But this has the problem that two invocations of verify from
|
||||
within the same macro would collide, since the __LINE__ value
|
||||
would be the same for both invocations. (The GCC __COUNTER__
|
||||
macro solves this problem, but is not portable.)
|
||||
|
||||
A solution is to use the sizeof operator. It yields a number,
|
||||
getting rid of the identity of the type. Declarations like
|
||||
|
||||
extern int dummy [sizeof (struct {...})];
|
||||
extern void dummy (int [sizeof (struct {...})]);
|
||||
extern int (*dummy (void)) [sizeof (struct {...})];
|
||||
|
||||
can be repeated.
|
||||
|
||||
* Should the implementation use a named struct or an unnamed struct?
|
||||
Which of the following alternatives can be used?
|
||||
|
||||
extern int dummy [sizeof (struct {...})];
|
||||
extern int dummy [sizeof (struct _gl_verify_type {...})];
|
||||
extern void dummy (int [sizeof (struct {...})]);
|
||||
extern void dummy (int [sizeof (struct _gl_verify_type {...})]);
|
||||
extern int (*dummy (void)) [sizeof (struct {...})];
|
||||
extern int (*dummy (void)) [sizeof (struct _gl_verify_type {...})];
|
||||
|
||||
In the second and sixth case, the struct type is exported to the
|
||||
outer scope; two such declarations therefore collide. GCC warns
|
||||
about the first, third, and fourth cases. So the only remaining
|
||||
possibility is the fifth case:
|
||||
|
||||
extern int (*dummy (void)) [sizeof (struct {...})];
|
||||
|
||||
* GCC warns about duplicate declarations of the dummy function if
|
||||
-Wredundant-decls is used. GCC 4.3 and later have a builtin
|
||||
__COUNTER__ macro that can let us generate unique identifiers for
|
||||
each dummy function, to suppress this warning.
|
||||
|
||||
* This implementation exploits the fact that older versions of GCC,
|
||||
which do not support _Static_assert, also do not warn about the
|
||||
last declaration mentioned above.
|
||||
|
||||
* GCC warns if -Wnested-externs is enabled and 'verify' is used
|
||||
within a function body; but inside a function, you can always
|
||||
arrange to use verify_expr instead.
|
||||
|
||||
* In C++, any struct definition inside sizeof is invalid.
|
||||
Use a template type to work around the problem. */
|
||||
|
||||
/* Concatenate two preprocessor tokens. */
|
||||
#define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
|
||||
#define _GL_CONCAT0(x, y) x##y
|
||||
|
||||
/* _GL_COUNTER is an integer, preferably one that changes each time we
|
||||
use it. Use __COUNTER__ if it works, falling back on __LINE__
|
||||
otherwise. __LINE__ isn't perfect, but it's better than a
|
||||
constant. */
|
||||
#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
|
||||
# define _GL_COUNTER __COUNTER__
|
||||
#else
|
||||
# define _GL_COUNTER __LINE__
|
||||
#endif
|
||||
|
||||
/* Generate a symbol with the given prefix, making it unique if
|
||||
possible. */
|
||||
#define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
|
||||
|
||||
/* Verify requirement R at compile-time, as an integer constant expression
|
||||
that returns 1. If R is false, fail at compile-time, preferably
|
||||
with a diagnostic that includes the string-literal DIAGNOSTIC. */
|
||||
|
||||
#define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \
|
||||
(!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
# if !GNULIB_defined_struct__gl_verify_type
|
||||
template <int w>
|
||||
struct _gl_verify_type {
|
||||
unsigned int _gl_verify_error_if_negative: w;
|
||||
};
|
||||
# define GNULIB_defined_struct__gl_verify_type 1
|
||||
# endif
|
||||
# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
|
||||
_gl_verify_type<(R) ? 1 : -1>
|
||||
#elif defined _GL_HAVE__STATIC_ASSERT
|
||||
# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
|
||||
struct { \
|
||||
_Static_assert (R, DIAGNOSTIC); \
|
||||
int _gl_dummy; \
|
||||
}
|
||||
#else
|
||||
# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
|
||||
struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; }
|
||||
#endif
|
||||
|
||||
/* Verify requirement R at compile-time, as a declaration without a
|
||||
trailing ';'. If R is false, fail at compile-time.
|
||||
|
||||
This macro requires three or more arguments but uses at most the first
|
||||
two, so that the _Static_assert macro optionally defined below supports
|
||||
both the C11 two-argument syntax and the C2x one-argument syntax.
|
||||
|
||||
Unfortunately, unlike C11, this implementation must appear as an
|
||||
ordinary declaration, and cannot appear inside struct { ... }. */
|
||||
|
||||
#if 200410 <= __cpp_static_assert
|
||||
# define _GL_VERIFY(R, DIAGNOSTIC, ...) static_assert (R, DIAGNOSTIC)
|
||||
#elif defined _GL_HAVE__STATIC_ASSERT
|
||||
# define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC)
|
||||
#else
|
||||
# define _GL_VERIFY(R, DIAGNOSTIC, ...) \
|
||||
extern int (*_GL_GENSYM (_gl_verify_function) (void)) \
|
||||
[_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
|
||||
# if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
|
||||
# pragma GCC diagnostic ignored "-Wnested-externs"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */
|
||||
#ifdef _GL_STATIC_ASSERT_H
|
||||
# if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
|
||||
# define _Static_assert(...) \
|
||||
_GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
|
||||
# endif
|
||||
# if __cpp_static_assert < 201411 && !defined static_assert
|
||||
# define static_assert _Static_assert /* C11 requires this #define. */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* @assert.h omit start@ */
|
||||
|
||||
#if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))
|
||||
# define _GL_HAS_BUILTIN_TRAP 1
|
||||
#elif defined __has_builtin
|
||||
# define _GL_HAS_BUILTIN_TRAP __has_builtin (__builtin_trap)
|
||||
#else
|
||||
# define _GL_HAS_BUILTIN_TRAP 0
|
||||
#endif
|
||||
|
||||
#if 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
|
||||
# define _GL_HAS_BUILTIN_UNREACHABLE 1
|
||||
#elif defined __has_builtin
|
||||
# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable)
|
||||
#else
|
||||
# define _GL_HAS_BUILTIN_UNREACHABLE 0
|
||||
#endif
|
||||
|
||||
/* Each of these macros verifies that its argument R is nonzero. To
|
||||
be portable, R should be an integer constant expression. Unlike
|
||||
assert (R), there is no run-time overhead.
|
||||
|
||||
There are two macros, since no single macro can be used in all
|
||||
contexts in C. verify_expr (R, E) is for scalar contexts, including
|
||||
integer constant expression contexts. verify (R) is for declaration
|
||||
contexts, e.g., the top level. */
|
||||
|
||||
/* Verify requirement R at compile-time. Return the value of the
|
||||
expression E. */
|
||||
|
||||
#define verify_expr(R, E) \
|
||||
(_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
|
||||
|
||||
/* Verify requirement R at compile-time, as a declaration without a
|
||||
trailing ';'. verify (R) acts like static_assert (R) except that
|
||||
it is portable to C11/C++14 and earlier, it can issue better
|
||||
diagnostics, and its name is shorter and may be more convenient. */
|
||||
|
||||
#ifdef __PGI
|
||||
/* PGI barfs if R is long. */
|
||||
# define verify(R) _GL_VERIFY (R, "verify (...)", -)
|
||||
#else
|
||||
# define verify(R) _GL_VERIFY (R, "verify (" #R ")", -)
|
||||
#endif
|
||||
|
||||
/* Assume that R always holds. Behavior is undefined if R is false,
|
||||
fails to evaluate, or has side effects.
|
||||
|
||||
'assume (R)' is a directive from the programmer telling the
|
||||
compiler that R is true so the compiler needn't generate code to
|
||||
test R. This is why 'assume' is in verify.h: it's related to
|
||||
static checking (in this case, static checking done by the
|
||||
programmer), not dynamic checking.
|
||||
|
||||
'assume (R)' can affect compilation of all the code, not just code
|
||||
that happens to be executed after the assume (R) is "executed".
|
||||
For example, if the code mistakenly does 'assert (R); assume (R);'
|
||||
the compiler is entitled to optimize away the 'assert (R)'.
|
||||
|
||||
Although assuming R can help a compiler generate better code or
|
||||
diagnostics, performance can suffer if R uses hard-to-optimize
|
||||
features such as function calls not inlined by the compiler.
|
||||
|
||||
Avoid Clang's __builtin_assume, as it breaks GNU Emacs master
|
||||
as of 2020-08-23T21:09:49Z!eggert@cs.ucla.edu; see
|
||||
<https://bugs.gnu.org/43152#71>. It's not known whether this breakage
|
||||
is a Clang bug or an Emacs bug; play it safe for now. */
|
||||
|
||||
#if _GL_HAS_BUILTIN_UNREACHABLE
|
||||
# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
|
||||
#elif 1200 <= _MSC_VER
|
||||
# define assume(R) __assume (R)
|
||||
#elif (defined GCC_LINT || defined lint) && _GL_HAS_BUILTIN_TRAP
|
||||
/* Doing it this way helps various packages when configured with
|
||||
--enable-gcc-warnings, which compiles with -Dlint. It's nicer
|
||||
when 'assume' silences warnings even with older GCCs. */
|
||||
# define assume(R) ((R) ? (void) 0 : __builtin_trap ())
|
||||
#else
|
||||
/* Some tools grok NOTREACHED, e.g., Oracle Studio 12.6. */
|
||||
# define assume(R) ((R) ? (void) 0 : /*NOTREACHED*/ (void) 0)
|
||||
#endif
|
||||
|
||||
/* @assert.h omit end@ */
|
||||
|
||||
#endif
|
||||
@@ -1,149 +0,0 @@
|
||||
/* A C macro for emitting warnings if a function is used.
|
||||
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
|
||||
for FUNCTION which will then trigger a compiler warning containing
|
||||
the text of "literal string" anywhere that function is called, if
|
||||
supported by the compiler. If the compiler does not support this
|
||||
feature, the macro expands to an unused extern declaration.
|
||||
|
||||
_GL_WARN_ON_USE_ATTRIBUTE ("literal string") expands to the
|
||||
attribute used in _GL_WARN_ON_USE. If the compiler does not support
|
||||
this feature, it expands to empty.
|
||||
|
||||
These macros are useful for marking a function as a potential
|
||||
portability trap, with the intent that "literal string" include
|
||||
instructions on the replacement function that should be used
|
||||
instead.
|
||||
_GL_WARN_ON_USE is for functions with 'extern' linkage.
|
||||
_GL_WARN_ON_USE_ATTRIBUTE is for functions with 'static' or 'inline'
|
||||
linkage.
|
||||
|
||||
However, one of the reasons that a function is a portability trap is
|
||||
if it has the wrong signature. Declaring FUNCTION with a different
|
||||
signature in C is a compilation error, so this macro must use the
|
||||
same type as any existing declaration so that programs that avoid
|
||||
the problematic FUNCTION do not fail to compile merely because they
|
||||
included a header that poisoned the function. But this implies that
|
||||
_GL_WARN_ON_USE is only safe to use if FUNCTION is known to already
|
||||
have a declaration. Use of this macro implies that there must not
|
||||
be any other macro hiding the declaration of FUNCTION; but
|
||||
undefining FUNCTION first is part of the poisoning process anyway
|
||||
(although for symbols that are provided only via a macro, the result
|
||||
is a compilation error rather than a warning containing
|
||||
"literal string"). Also note that in C++, it is only safe to use if
|
||||
FUNCTION has no overloads.
|
||||
|
||||
For an example, it is possible to poison 'getline' by:
|
||||
- adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
|
||||
[getline]) in configure.ac, which potentially defines
|
||||
HAVE_RAW_DECL_GETLINE
|
||||
- adding this code to a header that wraps the system <stdio.h>:
|
||||
#undef getline
|
||||
#if HAVE_RAW_DECL_GETLINE
|
||||
_GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
|
||||
"not universally present; use the gnulib module getline");
|
||||
#endif
|
||||
|
||||
It is not possible to directly poison global variables. But it is
|
||||
possible to write a wrapper accessor function, and poison that
|
||||
(less common usage, like &environ, will cause a compilation error
|
||||
rather than issue the nice warning, but the end result of informing
|
||||
the developer about their portability problem is still achieved):
|
||||
#if HAVE_RAW_DECL_ENVIRON
|
||||
static char ***
|
||||
rpl_environ (void) { return &environ; }
|
||||
_GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
|
||||
# undef environ
|
||||
# define environ (*rpl_environ ())
|
||||
#endif
|
||||
or better (avoiding contradictory use of 'static' and 'extern'):
|
||||
#if HAVE_RAW_DECL_ENVIRON
|
||||
static char ***
|
||||
_GL_WARN_ON_USE_ATTRIBUTE ("environ is not always properly declared")
|
||||
rpl_environ (void) { return &environ; }
|
||||
# undef environ
|
||||
# define environ (*rpl_environ ())
|
||||
#endif
|
||||
*/
|
||||
#ifndef _GL_WARN_ON_USE
|
||||
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function __attribute__ ((__warning__ (message)))
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
||||
__attribute__ ((__warning__ (message)))
|
||||
# elif __clang_major__ >= 4
|
||||
/* Another compiler attribute is available in clang. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function \
|
||||
__attribute__ ((__diagnose_if__ (1, message, "warning")))
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
||||
__attribute__ ((__diagnose_if__ (1, message, "warning")))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C __typeof__ (function) function
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message)
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE(function, message) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_ON_USE_CXX (function, rettype_gcc, rettype_clang, parameters_and_attributes, "message")
|
||||
is like _GL_WARN_ON_USE (function, "message"), except that in C++ mode the
|
||||
function is declared with the given prototype, consisting of return type,
|
||||
parameters, and attributes.
|
||||
This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
|
||||
not work in this case. */
|
||||
#ifndef _GL_WARN_ON_USE_CXX
|
||||
# if !defined __cplusplus
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
_GL_WARN_ON_USE (function, msg)
|
||||
# else
|
||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_gcc function parameters_and_attributes \
|
||||
__attribute__ ((__warning__ (msg)))
|
||||
# elif __clang_major__ >= 4
|
||||
/* Another compiler attribute is available in clang. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_clang function parameters_and_attributes \
|
||||
__attribute__ ((__diagnose_if__ (1, msg, "warning")))
|
||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||
/* Verify the existence of the function. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
extern rettype_gcc function parameters_and_attributes
|
||||
# else /* Unsupported. */
|
||||
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* _GL_WARN_EXTERN_C declaration;
|
||||
performs the declaration with C linkage. */
|
||||
#ifndef _GL_WARN_EXTERN_C
|
||||
# if defined __cplusplus
|
||||
# define _GL_WARN_EXTERN_C extern "C"
|
||||
# else
|
||||
# define _GL_WARN_EXTERN_C extern
|
||||
# endif
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,65 +0,0 @@
|
||||
/* xalloc-oversized.h -- memory allocation size checking
|
||||
|
||||
Copyright (C) 1990-2000, 2003-2004, 2006-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef XALLOC_OVERSIZED_H_
|
||||
#define XALLOC_OVERSIZED_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* True if N * S does not fit into both ptrdiff_t and size_t.
|
||||
N and S should be nonnegative and free of side effects.
|
||||
This expands to a constant expression if N and S are both constants.
|
||||
By gnulib convention, SIZE_MAX represents overflow in size_t
|
||||
calculations, so the conservative size_t-based dividend to use here
|
||||
is SIZE_MAX - 1. */
|
||||
#define __xalloc_oversized(n, s) \
|
||||
((s) != 0 \
|
||||
&& ((size_t) (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX - 1) / (s) \
|
||||
< (n)))
|
||||
|
||||
/* Return 1 if and only if an array of N objects, each of size S,
|
||||
cannot exist reliably because its total size in bytes would exceed
|
||||
MIN (PTRDIFF_MAX, SIZE_MAX - 1).
|
||||
|
||||
N and S should be nonnegative and free of side effects.
|
||||
|
||||
Warning: (xalloc_oversized (N, S) ? NULL : malloc (N * S)) can
|
||||
misbehave if N and S are both narrower than ptrdiff_t and size_t,
|
||||
and can be rewritten as (xalloc_oversized (N, S) ? NULL
|
||||
: malloc (N * (size_t) S)).
|
||||
|
||||
This is a macro, not a function, so that it works even if an
|
||||
argument exceeds MAX (PTRDIFF_MAX, SIZE_MAX). */
|
||||
#if 7 <= __GNUC__ && !defined __clang__ && PTRDIFF_MAX < SIZE_MAX
|
||||
# define xalloc_oversized(n, s) \
|
||||
__builtin_mul_overflow_p (n, s, (ptrdiff_t) 1)
|
||||
#elif (5 <= __GNUC__ && !defined __ICC && !__STRICT_ANSI__ \
|
||||
&& PTRDIFF_MAX < SIZE_MAX)
|
||||
# define xalloc_oversized(n, s) \
|
||||
(__builtin_constant_p (n) && __builtin_constant_p (s) \
|
||||
? __xalloc_oversized (n, s) \
|
||||
: ({ ptrdiff_t __xalloc_count; \
|
||||
__builtin_mul_overflow (n, s, &__xalloc_count); }))
|
||||
|
||||
/* Other compilers use integer division; this may be slower but is
|
||||
more portable. */
|
||||
#else
|
||||
# define xalloc_oversized(n, s) __xalloc_oversized (n, s)
|
||||
#endif
|
||||
|
||||
#endif /* !XALLOC_OVERSIZED_H_ */
|
||||
@@ -1,158 +0,0 @@
|
||||
/* malloc with out of memory checking.
|
||||
Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _XALLOC_H
|
||||
#define _XALLOC_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Defined in xmalloc.c. */
|
||||
|
||||
/* Allocate SIZE bytes of memory dynamically, with error checking. */
|
||||
extern void *xmalloc (size_t size);
|
||||
|
||||
/* Allocate memory for NMEMB elements of SIZE bytes, with error checking.
|
||||
SIZE must be > 0. */
|
||||
extern void *xnmalloc (size_t nmemb, size_t size);
|
||||
|
||||
/* Allocate SIZE bytes of memory dynamically, with error checking,
|
||||
and zero it. */
|
||||
extern void *xzalloc (size_t size);
|
||||
|
||||
/* Allocate memory for NMEMB elements of SIZE bytes, with error checking,
|
||||
and zero it. */
|
||||
extern void *xcalloc (size_t nmemb, size_t size);
|
||||
|
||||
/* Change the size of an allocated block of memory PTR to SIZE bytes,
|
||||
with error checking. If PTR is NULL, run xmalloc. */
|
||||
extern void *xrealloc (void *ptr, size_t size);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
template <typename T>
|
||||
inline T * xrealloc (T * ptr, size_t size)
|
||||
{
|
||||
return (T *) xrealloc ((void *) ptr, size);
|
||||
}
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This function is always triggered when memory is exhausted. It is
|
||||
in charge of honoring the three previous items. This is the
|
||||
function to call when one wants the program to die because of a
|
||||
memory allocation failure. */
|
||||
extern void xalloc_die (void)
|
||||
#if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) && !__STRICT_ANSI__
|
||||
__attribute__ ((__noreturn__))
|
||||
#endif
|
||||
;
|
||||
|
||||
/* In the following macros, T must be an elementary or structure/union or
|
||||
typedef'ed type, or a pointer to such a type. To apply one of the
|
||||
following macros to a function pointer or array type, you need to typedef
|
||||
it first and use the typedef name. */
|
||||
|
||||
/* Allocate an object of type T dynamically, with error checking. */
|
||||
/* extern T *XMALLOC (typename T); */
|
||||
#define XMALLOC(T) \
|
||||
((T *) xmalloc (sizeof (T)))
|
||||
|
||||
/* Allocate memory for NMEMB elements of type T, with error checking. */
|
||||
/* extern T *XNMALLOC (size_t nmemb, typename T); */
|
||||
#if HAVE_INLINE
|
||||
/* xnmalloc performs a division and multiplication by sizeof (T). Arrange to
|
||||
perform the division at compile-time and the multiplication with a factor
|
||||
known at compile-time. */
|
||||
# define XNMALLOC(N,T) \
|
||||
((T *) (sizeof (T) == 1 \
|
||||
? xmalloc (N) \
|
||||
: xnboundedmalloc(N, (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / sizeof (T), sizeof (T))))
|
||||
static inline void *
|
||||
xnboundedmalloc (size_t n, size_t bound, size_t s)
|
||||
{
|
||||
if (n > bound)
|
||||
xalloc_die ();
|
||||
return xmalloc (n * s);
|
||||
}
|
||||
#else
|
||||
# define XNMALLOC(N,T) \
|
||||
((T *) (sizeof (T) == 1 ? xmalloc (N) : xnmalloc (N, sizeof (T))))
|
||||
#endif
|
||||
|
||||
/* Allocate an object of type T dynamically, with error checking,
|
||||
and zero it. */
|
||||
/* extern T *XZALLOC (typename T); */
|
||||
#define XZALLOC(T) \
|
||||
((T *) xzalloc (sizeof (T)))
|
||||
|
||||
/* Allocate memory for NMEMB elements of type T, with error checking,
|
||||
and zero it. */
|
||||
/* extern T *XCALLOC (size_t nmemb, typename T); */
|
||||
#define XCALLOC(N,T) \
|
||||
((T *) xcalloc (N, sizeof (T)))
|
||||
|
||||
/* Return a pointer to a new buffer of N bytes. This is like xmalloc,
|
||||
except it returns char *. */
|
||||
#define xcharalloc(N) \
|
||||
XNMALLOC (N, char)
|
||||
|
||||
|
||||
/* Defined in xstrdup.c. */
|
||||
|
||||
/* Return a newly allocated copy of the N bytes of memory starting at P. */
|
||||
extern void *xmemdup (const void *p, size_t n);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
template <typename T>
|
||||
inline T * xmemdup (const T * p, size_t n)
|
||||
{
|
||||
return (T *) xmemdup ((const void *) p, n);
|
||||
}
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Return a newly allocated copy of STRING. */
|
||||
extern char *xstrdup (const char *string);
|
||||
|
||||
|
||||
/* Return 1 if an array of N objects, each of size S, cannot exist due
|
||||
to size arithmetic overflow. S must be positive and N must be
|
||||
nonnegative. This is a macro, not an inline function, so that it
|
||||
works correctly even when SIZE_MAX < N.
|
||||
|
||||
By gnulib convention, SIZE_MAX represents overflow in size
|
||||
calculations, so the conservative dividend to use here is
|
||||
SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
|
||||
However, malloc (SIZE_MAX) fails on all known hosts where
|
||||
sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
|
||||
exactly-SIZE_MAX allocations on such hosts; this avoids a test and
|
||||
branch when S is known to be 1. */
|
||||
# define xalloc_oversized(n, s) \
|
||||
((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _XALLOC_H */
|
||||
@@ -1,29 +0,0 @@
|
||||
/* Reading symbolic links without size limitation.
|
||||
|
||||
Copyright (C) 2001, 2003-2004, 2007, 2009-2022 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Jim Meyering <jim@meyering.net> */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
extern char *xreadlink (char const *filename)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
|
||||
#if GNULIB_XREADLINKAT
|
||||
extern char *xreadlinkat (int fd, char const *filename)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
#endif
|
||||
Reference in New Issue
Block a user