pmt: revert 7f8090b
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
# Run "make check" to ensure that the code passes some simple tests,
|
||||
# usually (always?) not involving compilation.
|
||||
all:
|
||||
|
||||
check:
|
||||
./t-idcache
|
||||
@@ -1,3 +0,0 @@
|
||||
The files in this directory are used in many GNU packages,
|
||||
including coreutils, diffutils, and tar.
|
||||
The autoconf tests required for these files are in ../m4.
|
||||
@@ -1,50 +0,0 @@
|
||||
/* A C macro for declaring that a function does not return.
|
||||
Copyright (C) 2011-2024 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 __clang__ && __clang_major__ < 16 \
|
||||
&& defined _GL_WORK_AROUND_LLVM_BUG_59792)
|
||||
/* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around
|
||||
that rare LLVM bug, though you may get many false-alarm warnings. */
|
||||
# define _Noreturn
|
||||
# elif ((!defined __cplusplus || defined __clang__) \
|
||||
&& (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
|
||||
|| (!defined __STRICT_ANSI__ \
|
||||
&& (4 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __clang__ \
|
||||
|| (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,300 +0,0 @@
|
||||
/* Internal implementation of access control lists. -*- coding: utf-8 -*-
|
||||
|
||||
Copyright (C) 2002-2003, 2005-2024 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 Paul Eggert, Andreas Grünbacher, and Bruno Haible. */
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_ATTRIBUTE_PURE. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include "acl.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* All systems define the ACL related API in <sys/acl.h>. */
|
||||
#if HAVE_SYS_ACL_H
|
||||
# include <sys/acl.h>
|
||||
#endif
|
||||
#if defined HAVE_FACL && ! defined GETACLCNT && defined ACL_CNT
|
||||
# define GETACLCNT ACL_CNT
|
||||
#endif
|
||||
|
||||
/* On Linux and Cygwin >= 2.5, additional ACL related API is available in
|
||||
<acl/libacl.h>. */
|
||||
#ifdef HAVE_ACL_LIBACL_H
|
||||
# include <acl/libacl.h>
|
||||
#endif
|
||||
|
||||
/* On HP-UX >= 11.11, additional ACL API is available in <aclv.h>. */
|
||||
#if HAVE_ACLV_H
|
||||
# include <sys/types.h>
|
||||
# include <aclv.h>
|
||||
/* HP-UX 11.11 lacks these declarations. */
|
||||
extern int acl (char *, int, int, struct acl *);
|
||||
extern int aclsort (int, int, struct acl *);
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FCHMOD
|
||||
# define HAVE_FCHMOD false
|
||||
# define fchmod(fd, mode) (-1)
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef ACL_INTERNAL_INLINE
|
||||
# define ACL_INTERNAL_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#if USE_ACL
|
||||
|
||||
# if HAVE_ACL_GET_FILE
|
||||
/* POSIX 1003.1e (draft 17 -- abandoned) specific version. */
|
||||
/* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
|
||||
|
||||
# ifndef MIN_ACL_ENTRIES
|
||||
# define MIN_ACL_ENTRIES 4
|
||||
# endif
|
||||
|
||||
/* POSIX 1003.1e (draft 17) */
|
||||
# ifdef HAVE_ACL_GET_FD
|
||||
/* Most platforms have a 1-argument acl_get_fd, only OSF/1 has a 2-argument
|
||||
macro(!). */
|
||||
# if HAVE_ACL_FREE_TEXT /* OSF/1 */
|
||||
ACL_INTERNAL_INLINE acl_t
|
||||
rpl_acl_get_fd (int fd)
|
||||
{
|
||||
return acl_get_fd (fd, ACL_TYPE_ACCESS);
|
||||
}
|
||||
# undef acl_get_fd
|
||||
# define acl_get_fd rpl_acl_get_fd
|
||||
# endif
|
||||
# else
|
||||
# define HAVE_ACL_GET_FD false
|
||||
# undef acl_get_fd
|
||||
# define acl_get_fd(fd) (NULL)
|
||||
# endif
|
||||
|
||||
/* POSIX 1003.1e (draft 17) */
|
||||
# ifdef HAVE_ACL_SET_FD
|
||||
/* Most platforms have a 2-argument acl_set_fd, only OSF/1 has a 3-argument
|
||||
macro(!). */
|
||||
# if HAVE_ACL_FREE_TEXT /* OSF/1 */
|
||||
ACL_INTERNAL_INLINE int
|
||||
rpl_acl_set_fd (int fd, acl_t acl)
|
||||
{
|
||||
return acl_set_fd (fd, ACL_TYPE_ACCESS, acl);
|
||||
}
|
||||
# undef acl_set_fd
|
||||
# define acl_set_fd rpl_acl_set_fd
|
||||
# endif
|
||||
# else
|
||||
# define HAVE_ACL_SET_FD false
|
||||
# undef acl_set_fd
|
||||
# define acl_set_fd(fd, acl) (-1)
|
||||
# endif
|
||||
|
||||
/* POSIX 1003.1e (draft 13) */
|
||||
# if ! HAVE_ACL_FREE_TEXT
|
||||
# define acl_free_text(buf) acl_free (buf)
|
||||
# endif
|
||||
|
||||
/* Linux-specific */
|
||||
/* Cygwin >= 2.5 implements this function, but it returns 1 for all
|
||||
directories, thus is unusable. */
|
||||
# if !defined HAVE_ACL_EXTENDED_FILE || defined __CYGWIN__
|
||||
# undef HAVE_ACL_EXTENDED_FILE
|
||||
# define HAVE_ACL_EXTENDED_FILE false
|
||||
# define acl_extended_file(name) (-1)
|
||||
# endif
|
||||
|
||||
# if ! defined HAVE_ACL_FROM_MODE && ! defined HAVE_ACL_FROM_TEXT
|
||||
# define acl_from_mode (NULL)
|
||||
# endif
|
||||
|
||||
/* Set to 0 if a file's mode is stored independently from the ACL. */
|
||||
# if (HAVE_ACL_COPY_EXT_NATIVE && HAVE_ACL_CREATE_ENTRY_NP) || defined __sgi /* Mac OS X, IRIX */
|
||||
# define MODE_INSIDE_ACL 0
|
||||
# endif
|
||||
|
||||
/* Return the number of entries in ACL.
|
||||
Return -1 and set errno upon failure to determine it. */
|
||||
/* Define a replacement for acl_entries if needed. (Only Linux has it.) */
|
||||
# if !HAVE_ACL_ENTRIES
|
||||
# define acl_entries rpl_acl_entries
|
||||
extern int acl_entries (acl_t);
|
||||
# endif
|
||||
|
||||
# if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */
|
||||
/* ACL is an ACL, from a file, stored as type ACL_TYPE_EXTENDED.
|
||||
Return 1 if the given ACL is non-trivial.
|
||||
Return 0 if it is trivial. */
|
||||
extern int acl_extended_nontrivial (acl_t);
|
||||
# else
|
||||
/* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS.
|
||||
Return 1 if the given ACL is non-trivial.
|
||||
Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.
|
||||
Return -1 and set errno upon failure to determine it. */
|
||||
extern int acl_access_nontrivial (acl_t);
|
||||
|
||||
/* ACL is an ACL, from a file, stored as type ACL_TYPE_DEFAULT.
|
||||
Return 1 if the given ACL is non-trivial.
|
||||
Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.
|
||||
Return -1 and set errno upon failure to determine it. */
|
||||
extern int acl_default_nontrivial (acl_t);
|
||||
# endif
|
||||
|
||||
# elif HAVE_FACL && defined GETACL /* Solaris, Cygwin < 2.5, not HP-UX */
|
||||
|
||||
/* Set to 0 if a file's mode is stored independently from the ACL. */
|
||||
# if defined __CYGWIN__ /* Cygwin */
|
||||
# define MODE_INSIDE_ACL 0
|
||||
# endif
|
||||
|
||||
/* Return 1 if the given ACL is non-trivial.
|
||||
Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */
|
||||
extern int acl_nontrivial (int count, aclent_t *entries) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
# ifdef ACE_GETACL /* Solaris 10 */
|
||||
|
||||
/* Test an ACL retrieved with ACE_GETACL.
|
||||
Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
|
||||
Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */
|
||||
extern int acl_ace_nontrivial (int count, ace_t *entries) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* Definitions for when the built executable is executed on Solaris 10
|
||||
(newer version) or Solaris 11. */
|
||||
/* For a_type. */
|
||||
# define OLD_ALLOW 0
|
||||
# define OLD_DENY 1
|
||||
# define NEW_ACE_ACCESS_ALLOWED_ACE_TYPE 0 /* replaces ALLOW */
|
||||
# define NEW_ACE_ACCESS_DENIED_ACE_TYPE 1 /* replaces DENY */
|
||||
/* For a_flags. */
|
||||
# define OLD_ACE_OWNER 0x0100
|
||||
# define OLD_ACE_GROUP 0x0200
|
||||
# define OLD_ACE_OTHER 0x0400
|
||||
# define NEW_ACE_OWNER 0x1000
|
||||
# define NEW_ACE_GROUP 0x2000
|
||||
# define NEW_ACE_IDENTIFIER_GROUP 0x0040
|
||||
# define NEW_ACE_EVERYONE 0x4000
|
||||
/* For a_access_mask. */
|
||||
# define NEW_ACE_READ_DATA 0x001 /* corresponds to 'r' */
|
||||
# define NEW_ACE_WRITE_DATA 0x002 /* corresponds to 'w' */
|
||||
# define NEW_ACE_APPEND_DATA 0x004
|
||||
# define NEW_ACE_READ_NAMED_ATTRS 0x008
|
||||
# define NEW_ACE_WRITE_NAMED_ATTRS 0x010
|
||||
# define NEW_ACE_EXECUTE 0x020
|
||||
# define NEW_ACE_DELETE_CHILD 0x040
|
||||
# define NEW_ACE_READ_ATTRIBUTES 0x080
|
||||
# define NEW_ACE_WRITE_ATTRIBUTES 0x100
|
||||
# define NEW_ACE_DELETE 0x10000
|
||||
# define NEW_ACE_READ_ACL 0x20000
|
||||
# define NEW_ACE_WRITE_ACL 0x40000
|
||||
# define NEW_ACE_WRITE_OWNER 0x80000
|
||||
# define NEW_ACE_SYNCHRONIZE 0x100000
|
||||
|
||||
# endif
|
||||
|
||||
# elif HAVE_GETACL /* HP-UX */
|
||||
|
||||
/* Return 1 if the given ACL is non-trivial.
|
||||
Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */
|
||||
extern int acl_nontrivial (int count, struct acl_entry *entries);
|
||||
|
||||
# if HAVE_ACLV_H /* HP-UX >= 11.11 */
|
||||
|
||||
/* Return 1 if the given ACL is non-trivial.
|
||||
Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */
|
||||
extern int aclv_nontrivial (int count, struct acl *entries);
|
||||
|
||||
# endif
|
||||
|
||||
# elif HAVE_ACLX_GET && 0 /* AIX */
|
||||
|
||||
/* TODO */
|
||||
|
||||
# elif HAVE_STATACL /* older AIX */
|
||||
|
||||
/* Return 1 if the given ACL is non-trivial.
|
||||
Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */
|
||||
extern int acl_nontrivial (struct acl *a);
|
||||
|
||||
# elif HAVE_ACLSORT /* NonStop Kernel */
|
||||
|
||||
/* Return 1 if the given ACL is non-trivial.
|
||||
Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */
|
||||
extern int acl_nontrivial (int count, struct acl *entries);
|
||||
|
||||
# endif
|
||||
|
||||
/* Set to 1 if a file's mode is implicit by the ACL. */
|
||||
# ifndef MODE_INSIDE_ACL
|
||||
# define MODE_INSIDE_ACL 1
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
struct permission_context {
|
||||
mode_t mode;
|
||||
#if USE_ACL
|
||||
# if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
|
||||
acl_t acl;
|
||||
# if !HAVE_ACL_TYPE_EXTENDED
|
||||
acl_t default_acl;
|
||||
# endif
|
||||
bool acls_not_supported;
|
||||
|
||||
# elif defined GETACL /* Solaris, Cygwin < 2.5 */
|
||||
int count;
|
||||
aclent_t *entries;
|
||||
# ifdef ACE_GETACL
|
||||
int ace_count;
|
||||
ace_t *ace_entries;
|
||||
# endif
|
||||
|
||||
# elif HAVE_GETACL /* HP-UX */
|
||||
struct acl_entry entries[NACLENTRIES];
|
||||
int count;
|
||||
# if HAVE_ACLV_H
|
||||
struct acl aclv_entries[NACLVENTRIES];
|
||||
int aclv_count;
|
||||
# endif
|
||||
|
||||
# elif HAVE_STATACL /* older AIX */
|
||||
union { struct acl a; char room[4096]; } u;
|
||||
bool have_u;
|
||||
|
||||
# elif HAVE_ACLSORT /* NonStop Kernel */
|
||||
struct acl entries[NACLENTRIES];
|
||||
int count;
|
||||
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
int get_permissions (const char *, int, mode_t, struct permission_context *);
|
||||
int set_permissions (struct permission_context *, const char *, int);
|
||||
void free_permission_context (struct permission_context *);
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
@@ -1,114 +0,0 @@
|
||||
/* acl.c - access control lists
|
||||
|
||||
Copyright (C) 2002, 2008-2024 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 Paul Eggert. */
|
||||
|
||||
#ifndef _GL_ACL_H
|
||||
#define _GL_ACL_H 1
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_CONST, _GL_ATTRIBUTE_DEPRECATED. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Follow symlinks when getting an ACL. This is a bitmask that is guaranteed
|
||||
not to collide with any <dirent.h> DT_* or _GL_DT_* value. */
|
||||
enum { ACL_SYMLINK_FOLLOW = 0x10000 };
|
||||
|
||||
/* Information about an ACL. */
|
||||
struct aclinfo
|
||||
{
|
||||
/* If 'size' is nonnegative, a buffer holding the concatenation
|
||||
of extended attribute names, each terminated by NUL
|
||||
(either u.__gl_acl_ch, or heap-allocated). */
|
||||
char *buf;
|
||||
|
||||
/* The number of useful bytes at the start of buf, counting trailing NULs.
|
||||
If negative, there was an error in getting the ACL info,
|
||||
and u.err is the corresponding errno. */
|
||||
ssize_t size;
|
||||
|
||||
/* The allocated size of buf. This is sizeof u.__gl_acl_ch if the
|
||||
buffer is not heap-allocated, and is larger otherwise.
|
||||
For internal use only. */
|
||||
ssize_t __gl_acl_alloc;
|
||||
|
||||
/* Security context string. Do not modify its contents. */
|
||||
char *scontext;
|
||||
/* Security context errno value. It is zero if there was no
|
||||
error getting the security context. When nonzero, scontext is "?". */
|
||||
int scontext_err;
|
||||
|
||||
union
|
||||
{
|
||||
/* An errno value, when there was an error getting the ACL info. */
|
||||
int err;
|
||||
|
||||
/* A small array of char, big enough for most listxattr results.
|
||||
The size is somewhat arbitrary; it equals the max length of a
|
||||
trivial NFSv4 ACL (a size used by file-has-acl.c in 2023-2024
|
||||
but no longer relevant now), and a different value might be
|
||||
better once experience is gained. For internal use only. */
|
||||
char __gl_acl_ch[152];
|
||||
} u;
|
||||
};
|
||||
|
||||
bool acl_errno_valid (int) _GL_ATTRIBUTE_CONST;
|
||||
int file_has_acl (char const *, struct stat const *);
|
||||
int file_has_aclinfo (char const *restrict, struct aclinfo *restrict, int);
|
||||
|
||||
#if USE_ACL && HAVE_LINUX_XATTR_H && HAVE_LISTXATTR
|
||||
bool aclinfo_has_xattr (struct aclinfo const *, char const *)
|
||||
_GL_ATTRIBUTE_PURE;
|
||||
void aclinfo_free (struct aclinfo *);
|
||||
#else
|
||||
# define aclinfo_has_xattr(ai, xattr) false
|
||||
# define aclinfo_free(ai) ((void) 0)
|
||||
#endif
|
||||
#if (USE_ACL && HAVE_LINUX_XATTR_H && HAVE_LISTXATTR \
|
||||
&& (HAVE_SMACK || USE_SELINUX_SELINUX_H))
|
||||
void aclinfo_scontext_free (char *);
|
||||
#else
|
||||
# define aclinfo_scontext_free(s) ((void) 0)
|
||||
#endif
|
||||
|
||||
int qset_acl (char const *, int, mode_t);
|
||||
int xset_acl (char const *, int, mode_t);
|
||||
/* Old name of xset_acl. */
|
||||
_GL_ATTRIBUTE_DEPRECATED int set_acl (char const *, int, mode_t);
|
||||
|
||||
int qcopy_acl (char const *, int, char const *, int, mode_t);
|
||||
int xcopy_acl (char const *, int, char const *, int, mode_t);
|
||||
/* Old name of xcopy_acl. */
|
||||
_GL_ATTRIBUTE_DEPRECATED int copy_acl (char const *, int, char const *, int,
|
||||
mode_t);
|
||||
|
||||
int chmod_or_fchmod (char const *, int, mode_t);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,115 +0,0 @@
|
||||
/* af_alg.h - Compute message digests from file streams and buffers.
|
||||
Copyright (C) 2018-2024 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 Matteo Croce <mcroce@redhat.com>, 2018.
|
||||
Documentation by Bruno Haible <bruno@clisp.org>, 2018. */
|
||||
|
||||
/* Declare specific functions for computing message digests
|
||||
using the Linux kernel crypto API, if available. This kernel API gives
|
||||
access to specialized crypto instructions (that would also be available
|
||||
in user space) or to crypto devices (not directly available in user space).
|
||||
|
||||
For a more complete set of facilities that use the Linux kernel crypto API,
|
||||
look at libkcapi. */
|
||||
|
||||
#ifndef AF_ALG_H
|
||||
# define AF_ALG_H 1
|
||||
|
||||
# include <stdio.h>
|
||||
# include <errno.h>
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
# if USE_LINUX_CRYPTO_API
|
||||
|
||||
/* Compute a message digest of a memory region.
|
||||
|
||||
The memory region starts at BUFFER and is LEN bytes long.
|
||||
|
||||
ALG is the message digest algorithm; see the file /proc/crypto.
|
||||
|
||||
RESBLOCK points to a block of HASHLEN bytes, for the result.
|
||||
HASHLEN must be the length of the message digest, in bytes, in particular:
|
||||
|
||||
alg | hashlen
|
||||
-------+--------
|
||||
md5 | 16
|
||||
sha1 | 20
|
||||
sha224 | 28
|
||||
sha256 | 32
|
||||
sha384 | 48
|
||||
sha512 | 64
|
||||
|
||||
If successful, fill RESBLOCK and return 0.
|
||||
Upon failure, return a negated error number. */
|
||||
int
|
||||
afalg_buffer (const char *buffer, size_t len, const char *alg,
|
||||
void *resblock, ssize_t hashlen);
|
||||
|
||||
/* Compute a message digest of data read from STREAM.
|
||||
|
||||
STREAM is an open file stream. The last operation on STREAM should
|
||||
not be 'ungetc', and if STREAM is also open for writing it should
|
||||
have been fflushed since its last write. Read from the current
|
||||
position to the end of STREAM. Handle regular files efficiently.
|
||||
|
||||
ALG is the message digest algorithm; see the file /proc/crypto.
|
||||
|
||||
RESBLOCK points to a block of HASHLEN bytes, for the result.
|
||||
HASHLEN must be the length of the message digest, in bytes, in particular:
|
||||
|
||||
alg | hashlen
|
||||
-------+--------
|
||||
md5 | 16
|
||||
sha1 | 20
|
||||
sha224 | 28
|
||||
sha256 | 32
|
||||
sha384 | 48
|
||||
sha512 | 64
|
||||
|
||||
If successful, fill RESBLOCK and return 0.
|
||||
Upon failure, return a negated error number.
|
||||
Unless returning 0 or -EIO, restore STREAM's file position so that
|
||||
the caller can fall back on some other method. */
|
||||
int
|
||||
afalg_stream (FILE *stream, const char *alg,
|
||||
void *resblock, ssize_t hashlen);
|
||||
|
||||
# else
|
||||
|
||||
static inline int
|
||||
afalg_buffer (const char *buffer, size_t len, const char *alg,
|
||||
void *resblock, ssize_t hashlen)
|
||||
{
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
static inline int
|
||||
afalg_stream (FILE *stream, const char *alg,
|
||||
void *resblock, ssize_t hashlen)
|
||||
{
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif /* AF_ALG_H */
|
||||
@@ -1,133 +0,0 @@
|
||||
/* aligned memory allocation
|
||||
|
||||
Copyright 2022-2024 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 ALIGNALLOC_H_
|
||||
#define ALIGNALLOC_H_
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_ATTRIBUTE_ALLOC_SIZE,
|
||||
_GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_RETURNS_NONNULL, HAVE_POSIX_MEMALIGN. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include "idx.h"
|
||||
#if defined __CHERI_PURE_CAPABILITY__
|
||||
# include <cheri.h>
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef ALIGNALLOC_INLINE
|
||||
# define ALIGNALLOC_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Whether aligned_alloc supports any power-of-two alignment,
|
||||
returns a nonnull pointer for size-zero allocations,
|
||||
and sets errno on failure. */
|
||||
#if 2 < __GLIBC__ + (16 <= __GLIBC_MINOR__)
|
||||
# define ALIGNALLOC_VIA_ALIGNED_ALLOC 1
|
||||
#else
|
||||
# define ALIGNALLOC_VIA_ALIGNED_ALLOC 0
|
||||
#endif
|
||||
|
||||
/* Work around AddressSanitizer bug.
|
||||
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104262
|
||||
https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20220124/1001910.html
|
||||
*/
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
# undef ALIGNALLOC_VIA_ALIGNED_ALLOC
|
||||
# define ALIGNALLOC_VIA_ALIGNED_ALLOC 0
|
||||
#endif
|
||||
#ifdef __has_feature
|
||||
# if __has_feature (address_sanitizer)
|
||||
# undef ALIGNALLOC_VIA_ALIGNED_ALLOC
|
||||
# define ALIGNALLOC_VIA_ALIGNED_ALLOC 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if ALIGNALLOC_VIA_ALIGNED_ALLOC || HAVE_POSIX_MEMALIGN
|
||||
|
||||
/* Free storage allocated via alignalloc. Do nothing if PTR is null. */
|
||||
|
||||
ALIGNALLOC_INLINE void
|
||||
alignfree (void *ptr)
|
||||
{
|
||||
free (ptr);
|
||||
}
|
||||
|
||||
/* Return an ALIGNMENT-aligned pointer to new storage of size SIZE,
|
||||
or a null pointer (setting errno) if memory is exhausted.
|
||||
ALIGNMENT must be a power of two.
|
||||
If SIZE is zero, on success return a unique pointer each time.
|
||||
To free storage later, call alignfree. */
|
||||
|
||||
ALIGNALLOC_INLINE
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2))
|
||||
/* _GL_ATTRIBUTE_DEALLOC (alignfree, 1) */
|
||||
void *
|
||||
alignalloc (idx_t alignment, idx_t size)
|
||||
{
|
||||
if ((size_t) -1 < alignment)
|
||||
alignment = (size_t) -1;
|
||||
if ((size_t) -1 < size)
|
||||
size = (size_t) -1;
|
||||
|
||||
# if ALIGNALLOC_VIA_ALIGNED_ALLOC
|
||||
return aligned_alloc (alignment, size);
|
||||
# else
|
||||
void *ptr = NULL;
|
||||
if (alignment < sizeof (void *))
|
||||
alignment = sizeof (void *);
|
||||
errno = posix_memalign (&ptr, alignment, size | !size);
|
||||
# if defined __CHERI_PURE_CAPABILITY__
|
||||
if (ptr != NULL)
|
||||
ptr = cheri_bounds_set (ptr, size);
|
||||
# endif
|
||||
return ptr;
|
||||
# endif
|
||||
}
|
||||
|
||||
#else /* ! (ALIGNALLOC_VIA_ALIGNED_ALLOC || HAVE_POSIX_MEMALIGN) */
|
||||
|
||||
void alignfree (void *);
|
||||
void *alignalloc (idx_t, idx_t)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2))
|
||||
_GL_ATTRIBUTE_DEALLOC (alignfree, 1);
|
||||
|
||||
#endif
|
||||
|
||||
/* Like alignalloc, but die instead of returning a null pointer. */
|
||||
void *xalignalloc (idx_t, idx_t)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2))
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL /* _GL_ATTRIBUTE_DEALLOC (alignfree, 1) */;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif /* !ALIGNALLOC_H_ */
|
||||
@@ -1,197 +0,0 @@
|
||||
/* Allocate memory with indefinite extent and specified alignment.
|
||||
|
||||
Copyright (C) 2020-2024 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>, 2020. */
|
||||
|
||||
/* Before including this file, you need to define the following macro:
|
||||
|
||||
ALIGNMENT A constant expression that evaluates to the desired alignment
|
||||
(a power of 2).
|
||||
|
||||
And you also need to #include <stdint.h> and <stdlib.h>. */
|
||||
|
||||
/* aligned_malloc allocates a block of memory of SIZE bytes, aligned on a
|
||||
boundary of ALIGNMENT bytes.
|
||||
The block can be freed through aligned_free(), NOT through free().
|
||||
Upon failure, it returns NULL. */
|
||||
|
||||
/* This module exists instead of a posix_memalign(), aligned_alloc(), or
|
||||
memalign() emulation, because we can't reasonably emulate posix_memalign(),
|
||||
aligned_alloc(), or memalign():
|
||||
If malloc() returned p, only free (p) is allowed, not free (p + 1),
|
||||
free (p + 2), free (p + 4), free (p + 8), or similar.
|
||||
|
||||
We can use posix_memalign(), a POSIX function.
|
||||
|
||||
We can also use aligned_alloc(), an ISO C11 and POSIX function. But it's
|
||||
a bit more awkward to use.
|
||||
|
||||
On older systems, we can alternatively use memalign() instead. In the
|
||||
Solaris documentation of memalign() it is not specified how a memory block
|
||||
returned by memalign() can be freed, but it actually can be freed with
|
||||
free(). */
|
||||
|
||||
/* This file uses MALLOC_ALIGNMENT, HAVE_POSIX_MEMALIGN, HAVE_ALIGNED_ALLOC,
|
||||
HAVE_MEMALIGN. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined ALIGNMENT
|
||||
# error "ALIGNMENT is not defined"
|
||||
#endif
|
||||
#if !((ALIGNMENT) > 0 && ((ALIGNMENT) & ((ALIGNMENT) - 1)) == 0)
|
||||
# error "ALIGNMENT is not a power of 2"
|
||||
#endif
|
||||
#if ((ALIGNMENT) <= MALLOC_ALIGNMENT) || HAVE_POSIX_MEMALIGN || HAVE_ALIGNED_ALLOC || HAVE_MEMALIGN
|
||||
|
||||
# if defined aligned_free || (__GNUC__ >= 11 && !defined __clang__)
|
||||
/* The caller wants an inline function, not a macro,
|
||||
or we can use GCC's -Wmismatched-dealloc warning. */
|
||||
static inline void
|
||||
aligned_free (void *q)
|
||||
{
|
||||
free (q);
|
||||
}
|
||||
# else
|
||||
# define aligned_free free
|
||||
# endif
|
||||
|
||||
# if (ALIGNMENT) <= MALLOC_ALIGNMENT
|
||||
/* Simply use malloc. */
|
||||
|
||||
# if defined aligned_malloc || (__GNUC__ >= 11 && !defined __clang__)
|
||||
/* The caller wants an inline function, not a macro,
|
||||
or GCC's -Wmismatched-dealloc warning might be in effect. */
|
||||
static inline
|
||||
/*_GL_ATTRIBUTE_DEALLOC (aligned_free, 1)*/
|
||||
void *
|
||||
aligned_malloc (size_t size)
|
||||
{
|
||||
return malloc (size);
|
||||
}
|
||||
# else
|
||||
# define aligned_malloc malloc
|
||||
# endif
|
||||
|
||||
# elif HAVE_POSIX_MEMALIGN
|
||||
/* Use posix_memalign.
|
||||
This is OK since ALIGNMENT > MALLOC_ALIGNMENT >= sizeof (void *). */
|
||||
|
||||
static inline
|
||||
/*_GL_ATTRIBUTE_DEALLOC (aligned_free, 1)*/
|
||||
void *
|
||||
aligned_malloc (size_t size)
|
||||
{
|
||||
void *p;
|
||||
int ret = posix_memalign (&p, (ALIGNMENT), size);
|
||||
if (ret == 0)
|
||||
return p;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
# elif HAVE_ALIGNED_ALLOC
|
||||
/* Use aligned_alloc. */
|
||||
|
||||
static inline
|
||||
/*_GL_ATTRIBUTE_DEALLOC (aligned_free, 1)*/
|
||||
void *
|
||||
aligned_malloc (size_t size)
|
||||
{
|
||||
/* Round up SIZE to the next multiple of ALIGNMENT,
|
||||
namely (SIZE + ALIGNMENT - 1) & ~(ALIGNMENT - 1). */
|
||||
size += (ALIGNMENT) - 1;
|
||||
if (size >= (ALIGNMENT) - 1) /* no overflow? */
|
||||
{
|
||||
size &= ~(size_t)((ALIGNMENT) - 1);
|
||||
return aligned_alloc ((ALIGNMENT), size);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
# elif HAVE_MEMALIGN /* HP-UX, IRIX, Solaris <= 10 */
|
||||
/* Use memalign. */
|
||||
|
||||
static inline
|
||||
/*_GL_ATTRIBUTE_DEALLOC (aligned_free, 1)*/
|
||||
void *
|
||||
aligned_malloc (size_t size)
|
||||
{
|
||||
return memalign ((ALIGNMENT), size);
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
#else
|
||||
/* Use malloc and waste a bit of memory. */
|
||||
|
||||
static inline void
|
||||
aligned_free (void *q)
|
||||
{
|
||||
if (q != NULL)
|
||||
{
|
||||
if ((uintptr_t) q & ((ALIGNMENT) - 1))
|
||||
/* Argument not aligned as expected. */
|
||||
abort ();
|
||||
else
|
||||
{
|
||||
void *p = ((void **) q)[-1];
|
||||
if (!((uintptr_t) p <= (uintptr_t) q
|
||||
&& (uintptr_t) q - (uintptr_t) p >= MALLOC_ALIGNMENT
|
||||
&& (uintptr_t) q - (uintptr_t) p <= (ALIGNMENT)))
|
||||
abort ();
|
||||
free (p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline
|
||||
/*_GL_ATTRIBUTE_DEALLOC (aligned_free, 1)*/
|
||||
void *
|
||||
aligned_malloc (size_t size)
|
||||
{
|
||||
size += (ALIGNMENT);
|
||||
if (size >= (ALIGNMENT)) /* no overflow? */
|
||||
{
|
||||
void *p = malloc (size);
|
||||
if (p != NULL)
|
||||
{
|
||||
/* Go to the next multiple of ALIGNMENT. */
|
||||
void *q =
|
||||
(void *) (((uintptr_t) p + (ALIGNMENT)) & -(intptr_t)(ALIGNMENT));
|
||||
/* Now q - p <= ALIGNMENT and
|
||||
q - p >= MALLOC_ALIGNMENT >= sizeof (void *).
|
||||
This is enough to store a back pointer to p. */
|
||||
((void **) q)[-1] = p;
|
||||
return q;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,56 +0,0 @@
|
||||
/* Determine alignment of types.
|
||||
Copyright (C) 2003-2004, 2006, 2009-2024 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 _ALIGNOF_H
|
||||
#define _ALIGNOF_H
|
||||
|
||||
/* This file uses alignof. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* alignof_slot (TYPE)
|
||||
Determine the alignment of a structure slot (field) of a given type,
|
||||
at compile time. Note that the result depends on the ABI.
|
||||
This is the same as alignof (TYPE).
|
||||
Note: The result cannot be used as a value for an 'enum' constant,
|
||||
due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */
|
||||
#if defined __cplusplus
|
||||
template <class type> struct alignof_helper { char __slot1; type __slot2; };
|
||||
# define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
|
||||
#else
|
||||
# define alignof_slot(type) alignof (type)
|
||||
#endif
|
||||
|
||||
/* alignof_type (TYPE)
|
||||
Determine the good alignment of an object of the given type at compile time.
|
||||
Note that this is not necessarily the same as alignof_slot(type).
|
||||
For example, with GNU C on x86 platforms and with clang on Linux/x86:
|
||||
alignof_type(long long) = 8, but alignof_slot(long long) = 4.
|
||||
And alignof_type(double) = 8, but
|
||||
- when -malign-double is not specified: alignof_slot(double) = 4,
|
||||
- when -malign-double is specified: alignof_slot(double) = 8.
|
||||
Note: The result cannot be used as a value for an 'enum' constant,
|
||||
due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */
|
||||
#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
|
||||
# define alignof_type __alignof__
|
||||
#else
|
||||
# define alignof_type alignof_slot
|
||||
#endif
|
||||
|
||||
#endif /* _ALIGNOF_H */
|
||||
@@ -1,68 +0,0 @@
|
||||
/* Memory allocators such as malloc+free.
|
||||
|
||||
Copyright (C) 2011-2024 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>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* 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;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _GL_ALLOCATOR_H */
|
||||
@@ -1,49 +0,0 @@
|
||||
/* Locale dependent memory area transformation for comparison.
|
||||
Copyright (C) 2009-2024 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 AMEMXFRM_H
|
||||
#define AMEMXFRM_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Generalization of strxfrm() to strings with embedded NUL bytes. */
|
||||
|
||||
/* Transform the memory area [S..S+N-1] to a memory area, in such a way that
|
||||
comparing (S1,N1) and (S2,N2) with memcoll() is equivalent to comparing
|
||||
amemxfrm(S1,N1) and amemxfrm(S2,N2) with memcmp2().
|
||||
The byte S[N] may be temporarily overwritten by this function, but will be
|
||||
restored before this function returns.
|
||||
The result of this function depends on the LC_COLLATE category of the
|
||||
current locale.
|
||||
If successful: If resultbuf is not NULL and the result fits into *lengthp
|
||||
bytes, it is put in resultbuf, and resultbuf is returned. Otherwise, a
|
||||
freshly allocated string is returned. In both cases, *lengthp is set to the
|
||||
length of the returned string.
|
||||
Upon failure, return NULL, with errno set. */
|
||||
extern char * amemxfrm (char *restrict s, size_t n,
|
||||
char *restrict resultbuf, size_t *lengthp);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AMEMXFRM_H */
|
||||
@@ -1,58 +0,0 @@
|
||||
/* arcfour.h --- The arcfour stream cipher
|
||||
* Copyright (C) 2000-2005, 2009-2024 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Code from Libgcrypt adapted for gnulib by Simon Josefsson. */
|
||||
|
||||
#ifndef ARCFOUR_H
|
||||
#define ARCFOUR_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define ARCFOUR_SBOX_SIZE 256
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char sbox[ARCFOUR_SBOX_SIZE];
|
||||
uint8_t idx_i, idx_j;
|
||||
} arcfour_context;
|
||||
|
||||
/* Apply ARCFOUR stream to INBUF placing the result in OUTBUF, both of
|
||||
LENGTH size. CONTEXT must be initialized with arcfour_setkey
|
||||
before this function is called. */
|
||||
extern void
|
||||
arcfour_stream (arcfour_context * context,
|
||||
const char *inbuf, char *restrict outbuf, size_t length);
|
||||
|
||||
/* Initialize CONTEXT using encryption KEY of KEYLEN bytes. KEY
|
||||
should be 40 bits (5 bytes) or longer. The KEY cannot be zero
|
||||
length. */
|
||||
extern void
|
||||
arcfour_setkey (arcfour_context * context, const char *key, size_t keylen);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ARCFOUR_H */
|
||||
@@ -1,71 +0,0 @@
|
||||
/* arctwo.h --- The arctwo block cipher
|
||||
* Copyright (C) 2000-2003, 2005, 2009-2024 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Code from Libgcrypt adapted for gnulib by Simon Josefsson. */
|
||||
|
||||
#ifndef ARCTWO_H
|
||||
#define ARCTWO_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t S[64];
|
||||
} arctwo_context;
|
||||
|
||||
#define ARCTWO_BLOCK_SIZE 8
|
||||
|
||||
/* Initialize CONTEXT using KEY of KEYLEN length. If
|
||||
EFFECTIVE_KEYLEN, truncate the key (using a special algorithm) to
|
||||
only be of EFFECTIVE_KEYLEN bits. Normally, you use
|
||||
EFFECTIVE_KEYLEN of 0, but see RFC 2268 for more information. */
|
||||
void
|
||||
arctwo_setkey_ekb (arctwo_context *context,
|
||||
size_t keylen, const char *key, size_t effective_keylen);
|
||||
|
||||
#define arctwo_setkey(context,keylen,key) \
|
||||
arctwo_setkey_ekb (context, keylen, key, 8 * (keylen))
|
||||
|
||||
/* Encrypt INBUF of size LENGTH into OUTBUF. LENGTH must be a
|
||||
multiple of ARCTWO_BLOCK_SIZE. CONTEXT hold the encryption key,
|
||||
and must have been initialized with arctwo_setkey or
|
||||
arctwo_setkey_ekb. */
|
||||
extern void
|
||||
arctwo_encrypt (arctwo_context *context, const char *inbuf,
|
||||
char *restrict outbuf, size_t length);
|
||||
|
||||
/* Decrypt INBUF of size LENGTH into OUTBUF. LENGTH must be a
|
||||
multiple of ARCTWO_BLOCK_SIZE. CONTEXT hold the decryption key,
|
||||
and must have been initialized with arctwo_setkey or
|
||||
arctwo_setkey_ekb. */
|
||||
extern void
|
||||
arctwo_decrypt (arctwo_context *context, const char *inbuf,
|
||||
char *restrict outbuf, size_t length);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ARCTWO_H */
|
||||
@@ -1,47 +0,0 @@
|
||||
/* Read symbolic links without size limitation.
|
||||
|
||||
Copyright (C) 2001, 2003-2004, 2007, 2009-2024 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>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
/* A C macro for declaring that specific arguments must not be NULL.
|
||||
Copyright (C) 2009-2024 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,350 +0,0 @@
|
||||
/* argmatch.h -- definitions and prototypes for argmatch.c
|
||||
|
||||
Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2024 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 David MacKenzie <djm@ai.mit.edu>
|
||||
Modified by Akim Demaille <demaille@inf.enst.fr> */
|
||||
|
||||
#ifndef ARGMATCH_H_
|
||||
# define ARGMATCH_H_ 1
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_PURE. */
|
||||
# if !_GL_CONFIG_H_INCLUDED
|
||||
# error "Please include config.h first."
|
||||
# endif
|
||||
|
||||
# include <limits.h>
|
||||
# include <stddef.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h> /* memcmp */
|
||||
|
||||
# include "gettext.h"
|
||||
# include "quote.h"
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
|
||||
|
||||
/* Assert there are as many real arguments as there are values
|
||||
(argument list ends with a NULL guard). */
|
||||
|
||||
# define ARGMATCH_VERIFY(Arglist, Vallist) \
|
||||
static_assert (ARRAY_CARDINALITY (Arglist) \
|
||||
== ARRAY_CARDINALITY (Vallist) + 1)
|
||||
|
||||
/* Return the index of the element of ARGLIST (NULL terminated) that
|
||||
matches with ARG. If VALLIST is not NULL, then use it to resolve
|
||||
false ambiguities (i.e., different matches of ARG but corresponding
|
||||
to the same values in VALLIST). */
|
||||
|
||||
ptrdiff_t argmatch (char const *arg, char const *const *arglist,
|
||||
void const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
ptrdiff_t argmatch_exact (char const *arg, char const *const *arglist)
|
||||
_GL_ATTRIBUTE_PURE;
|
||||
|
||||
# define ARGMATCH(Arg, Arglist, Vallist) \
|
||||
argmatch (Arg, Arglist, (void const *) (Vallist), sizeof *(Vallist))
|
||||
|
||||
# define ARGMATCH_EXACT(Arg, Arglist) \
|
||||
argmatch_exact (Arg, Arglist)
|
||||
|
||||
/* xargmatch calls this function when it fails. This function should not
|
||||
return. By default, this is a function that calls ARGMATCH_DIE which
|
||||
in turn defaults to 'exit (exit_failure)'. */
|
||||
typedef void (*argmatch_exit_fn) (void);
|
||||
extern argmatch_exit_fn argmatch_die;
|
||||
|
||||
/* Report on stderr why argmatch failed. Report correct values. */
|
||||
|
||||
void argmatch_invalid (char const *context, char const *value,
|
||||
ptrdiff_t problem);
|
||||
|
||||
/* Left for compatibility with the old name invalid_arg */
|
||||
|
||||
# define invalid_arg(Context, Value, Problem) \
|
||||
argmatch_invalid (Context, Value, Problem)
|
||||
|
||||
|
||||
|
||||
/* Report on stderr the list of possible arguments. */
|
||||
|
||||
void argmatch_valid (char const *const *arglist,
|
||||
void const *vallist, size_t valsize);
|
||||
|
||||
# define ARGMATCH_VALID(Arglist, Vallist) \
|
||||
argmatch_valid (Arglist, (void const *) (Vallist), sizeof *(Vallist))
|
||||
|
||||
|
||||
|
||||
/* Like argmatch/argmatch_exact, but upon failure, report an explanation
|
||||
of the failure, and exit using the function EXIT_FN. */
|
||||
|
||||
ptrdiff_t __xargmatch_internal (char const *context,
|
||||
char const *arg, char const *const *arglist,
|
||||
void const *vallist, size_t valsize,
|
||||
argmatch_exit_fn exit_fn,
|
||||
bool allow_abbreviation);
|
||||
|
||||
/* Programmer friendly interface to __xargmatch_internal. */
|
||||
|
||||
# define XARGMATCH(Context, Arg, Arglist, Vallist) \
|
||||
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
||||
(void const *) (Vallist), \
|
||||
sizeof *(Vallist), \
|
||||
argmatch_die, \
|
||||
true)])
|
||||
|
||||
# define XARGMATCH_EXACT(Context, Arg, Arglist, Vallist) \
|
||||
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
||||
(void const *) (Vallist), \
|
||||
sizeof *(Vallist), \
|
||||
argmatch_die, \
|
||||
false)])
|
||||
|
||||
/* Convert a value into a corresponding argument. */
|
||||
|
||||
char const *argmatch_to_argument (void const *value,
|
||||
char const *const *arglist,
|
||||
void const *vallist, size_t valsize)
|
||||
_GL_ATTRIBUTE_PURE;
|
||||
|
||||
# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
|
||||
argmatch_to_argument (Value, Arglist, \
|
||||
(void const *) (Vallist), sizeof *(Vallist))
|
||||
|
||||
# define ARGMATCH_DEFINE_GROUP(Name, Type) \
|
||||
/* The type of the values of this group. */ \
|
||||
typedef Type argmatch_##Name##_type; \
|
||||
\
|
||||
/* The size of the type of the values of this group. */ \
|
||||
enum argmatch_##Name##_size_enum \
|
||||
{ \
|
||||
argmatch_##Name##_size = sizeof (argmatch_##Name##_type) \
|
||||
}; \
|
||||
\
|
||||
/* Argument mapping of this group. */ \
|
||||
typedef struct \
|
||||
{ \
|
||||
/* Argument (e.g., "simple"). */ \
|
||||
const char *arg; \
|
||||
/* Value (e.g., simple_backups). */ \
|
||||
const argmatch_##Name##_type val; \
|
||||
} argmatch_##Name##_arg; \
|
||||
\
|
||||
/* Documentation of this group. */ \
|
||||
typedef struct \
|
||||
{ \
|
||||
/* Argument (e.g., "simple"). */ \
|
||||
const char *arg; \
|
||||
/* Documentation (e.g., N_("always make simple backups")). */ \
|
||||
const char *doc; \
|
||||
} argmatch_##Name##_doc; \
|
||||
\
|
||||
/* All the features of an argmatch group. */ \
|
||||
typedef struct \
|
||||
{ \
|
||||
const argmatch_##Name##_arg* args; \
|
||||
const argmatch_##Name##_doc* docs; \
|
||||
\
|
||||
/* Printed before the usage message. */ \
|
||||
const char *doc_pre; \
|
||||
/* Printed after the usage message. */ \
|
||||
const char *doc_post; \
|
||||
} argmatch_##Name##_group_type; \
|
||||
\
|
||||
/* The structure the user must build. */ \
|
||||
extern const argmatch_##Name##_group_type argmatch_##Name##_group; \
|
||||
\
|
||||
/* Print the documentation of this group. */ \
|
||||
void argmatch_##Name##_usage (FILE *out); \
|
||||
\
|
||||
/* If nonnegative, the index I of ARG in ARGS, i.e, \
|
||||
ARGS[I] == ARG. \
|
||||
Return -1 for invalid argument, -2 for ambiguous argument. */ \
|
||||
ptrdiff_t argmatch_##Name##_choice (const char *arg); \
|
||||
\
|
||||
/* A pointer to the corresponding value if it exists, or \
|
||||
report an error and exit with failure if the argument was \
|
||||
not recognized. */ \
|
||||
const argmatch_##Name##_type* \
|
||||
argmatch_##Name##_value (const char *context, const char *arg); \
|
||||
\
|
||||
/* The first argument in ARGS that matches this value, or NULL. */ \
|
||||
const char * \
|
||||
argmatch_##Name##_argument (const argmatch_##Name##_type *val); \
|
||||
\
|
||||
ptrdiff_t \
|
||||
argmatch_##Name##_choice (const char *arg) \
|
||||
{ \
|
||||
const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \
|
||||
size_t size = argmatch_##Name##_size; \
|
||||
ptrdiff_t res = -1; /* Index of first nonexact match. */ \
|
||||
bool ambiguous = false; /* Whether multiple nonexact match(es). */ \
|
||||
size_t arglen = strlen (arg); \
|
||||
\
|
||||
/* Test all elements for either exact match or abbreviated \
|
||||
matches. */ \
|
||||
for (size_t i = 0; g->args[i].arg; i++) \
|
||||
if (!strncmp (g->args[i].arg, arg, arglen)) \
|
||||
{ \
|
||||
if (strlen (g->args[i].arg) == arglen) \
|
||||
/* Exact match found. */ \
|
||||
return i; \
|
||||
else if (res == -1) \
|
||||
/* First nonexact match found. */ \
|
||||
res = i; \
|
||||
else if (memcmp (&g->args[res].val, &g->args[i].val, size)) \
|
||||
/* Second nonexact match found. */ \
|
||||
/* There is a real ambiguity, or we could not \
|
||||
disambiguate. */ \
|
||||
ambiguous = true; \
|
||||
} \
|
||||
return ambiguous ? -2 : res; \
|
||||
} \
|
||||
\
|
||||
const char * \
|
||||
argmatch_##Name##_argument (const argmatch_##Name##_type *val) \
|
||||
{ \
|
||||
const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \
|
||||
size_t size = argmatch_##Name##_size; \
|
||||
for (size_t i = 0; g->args[i].arg; i++) \
|
||||
if (!memcmp (val, &g->args[i].val, size)) \
|
||||
return g->args[i].arg; \
|
||||
return NULL; \
|
||||
} \
|
||||
\
|
||||
/* List the valid values of this group. */ \
|
||||
static void \
|
||||
argmatch_##Name##_valid (FILE *out) \
|
||||
{ \
|
||||
const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \
|
||||
size_t size = argmatch_##Name##_size; \
|
||||
\
|
||||
/* Try to put synonyms on the same line. Synonyms are expected \
|
||||
to follow each other. */ \
|
||||
fputs (gettext ("Valid arguments are:"), out); \
|
||||
for (int i = 0; g->args[i].arg; i++) \
|
||||
if (i == 0 \
|
||||
|| memcmp (&g->args[i-1].val, &g->args[i].val, size)) \
|
||||
fprintf (out, "\n - %s", quote (g->args[i].arg)); \
|
||||
else \
|
||||
fprintf (out, ", %s", quote (g->args[i].arg)); \
|
||||
putc ('\n', out); \
|
||||
} \
|
||||
\
|
||||
const argmatch_##Name##_type* \
|
||||
argmatch_##Name##_value (const char *context, const char *arg) \
|
||||
{ \
|
||||
const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \
|
||||
ptrdiff_t res = argmatch_##Name##_choice (arg); \
|
||||
if (res < 0) \
|
||||
{ \
|
||||
argmatch_invalid (context, arg, res); \
|
||||
argmatch_##Name##_valid (stderr); \
|
||||
argmatch_die (); \
|
||||
} \
|
||||
return &g->args[res].val; \
|
||||
} \
|
||||
\
|
||||
/* The column in which the documentation is displayed. \
|
||||
The leftmost possible, but no more than 20. */ \
|
||||
static int \
|
||||
argmatch_##Name##_doc_col (void) \
|
||||
{ \
|
||||
const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \
|
||||
size_t size = argmatch_##Name##_size; \
|
||||
int res = 0; \
|
||||
for (int i = 0; g->docs[i].arg; ++i) \
|
||||
{ \
|
||||
int col = 4; \
|
||||
int ival = argmatch_##Name##_choice (g->docs[i].arg); \
|
||||
if (ival < 0) \
|
||||
/* Pseudo argument, display it. */ \
|
||||
col += strlen (g->docs[i].arg); \
|
||||
else \
|
||||
/* Genuine argument, display it with its synonyms. */ \
|
||||
for (int j = 0; g->args[j].arg; ++j) \
|
||||
if (! memcmp (&g->args[ival].val, &g->args[j].val, size)) \
|
||||
col += (col == 4 ? 0 : 2) + strlen (g->args[j].arg); \
|
||||
if (res <= col) \
|
||||
res = col <= 20 ? col : 20; \
|
||||
} \
|
||||
return res ? res : 20; \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
argmatch_##Name##_usage (FILE *out) \
|
||||
{ \
|
||||
const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \
|
||||
size_t size = argmatch_##Name##_size; \
|
||||
/* Width of the screen. Help2man does not seem to support \
|
||||
arguments on several lines, so in that case pretend a very \
|
||||
large width. */ \
|
||||
const int screen_width = getenv ("HELP2MAN") ? INT_MAX : 80; \
|
||||
if (g->doc_pre) \
|
||||
fprintf (out, "%s\n", gettext (g->doc_pre)); \
|
||||
int doc_col = argmatch_##Name##_doc_col (); \
|
||||
for (int i = 0; g->docs[i].arg; ++i) \
|
||||
{ \
|
||||
int col = 0; \
|
||||
bool first = true; \
|
||||
int ival = argmatch_##Name##_choice (g->docs[i].arg); \
|
||||
if (ival < 0) \
|
||||
/* Pseudo argument, display it. */ \
|
||||
col += fprintf (out, " %s", g->docs[i].arg); \
|
||||
else \
|
||||
/* Genuine argument, display it with its synonyms. */ \
|
||||
for (int j = 0; g->args[j].arg; ++j) \
|
||||
if (! memcmp (&g->args[ival].val, &g->args[j].val, size)) \
|
||||
{ \
|
||||
if (!first \
|
||||
&& screen_width < col + 2 + strlen (g->args[j].arg)) \
|
||||
{ \
|
||||
fprintf (out, ",\n"); \
|
||||
col = 0; \
|
||||
first = true; \
|
||||
} \
|
||||
if (first) \
|
||||
{ \
|
||||
col += fprintf (out, " "); \
|
||||
first = false; \
|
||||
} \
|
||||
else \
|
||||
col += fprintf (out, ","); \
|
||||
col += fprintf (out, " %s", g->args[j].arg); \
|
||||
} \
|
||||
/* The doc. Separated by at least two spaces. */ \
|
||||
if (doc_col < col + 2) \
|
||||
{ \
|
||||
fprintf (out, "\n"); \
|
||||
col = 0; \
|
||||
} \
|
||||
fprintf (out, "%*s%s\n", \
|
||||
doc_col - col, "", gettext (g->docs[i].doc)); \
|
||||
} \
|
||||
if (g->doc_post) \
|
||||
fprintf (out, "%s\n", gettext (g->doc_post)); \
|
||||
}
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif /* ARGMATCH_H_ */
|
||||
@@ -1,303 +0,0 @@
|
||||
/* Word-wrapping and line-truncating streams.
|
||||
Copyright (C) 1997-2024 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||
|
||||
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 3 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/>. */
|
||||
|
||||
/* This package emulates glibc 'line_wrap_stream' semantics for systems that
|
||||
don't have that. If the system does have it, it is just a wrapper for
|
||||
that. This header file is only used internally while compiling argp, and
|
||||
shouldn't be installed. */
|
||||
|
||||
#ifndef _ARGP_FMTSTREAM_H
|
||||
#define _ARGP_FMTSTREAM_H
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, __GL_INLINE, _GL_ATTRIBUTE_DEALLOC,
|
||||
_GL_ATTRIBUTE_FORMAT. */
|
||||
#if !_LIBC && !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H)
|
||||
/* line_wrap_stream is available, so use that. */
|
||||
#define ARGP_FMTSTREAM_USE_LINEWRAP
|
||||
#endif
|
||||
|
||||
#ifdef ARGP_FMTSTREAM_USE_LINEWRAP
|
||||
/* Just be a simple wrapper for line_wrap_stream; the semantics are
|
||||
*slightly* different, as line_wrap_stream doesn't actually make a new
|
||||
object, it just modifies the given stream (reversibly) to do
|
||||
line-wrapping. Since we control who uses this code, it doesn't matter. */
|
||||
|
||||
#include <linewrap.h>
|
||||
|
||||
typedef FILE *argp_fmtstream_t;
|
||||
|
||||
#define argp_make_fmtstream line_wrap_stream
|
||||
#define __argp_make_fmtstream line_wrap_stream
|
||||
#define argp_fmtstream_free line_unwrap_stream
|
||||
#define __argp_fmtstream_free line_unwrap_stream
|
||||
|
||||
#define __argp_fmtstream_putc(fs,ch) putc(ch,fs)
|
||||
#define argp_fmtstream_putc(fs,ch) putc(ch,fs)
|
||||
#define __argp_fmtstream_puts(fs,str) fputs(str,fs)
|
||||
#define argp_fmtstream_puts(fs,str) fputs(str,fs)
|
||||
#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
|
||||
#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
|
||||
#define __argp_fmtstream_printf fprintf
|
||||
#define argp_fmtstream_printf fprintf
|
||||
|
||||
#define __argp_fmtstream_lmargin line_wrap_lmargin
|
||||
#define argp_fmtstream_lmargin line_wrap_lmargin
|
||||
#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin
|
||||
#define argp_fmtstream_set_lmargin line_wrap_set_lmargin
|
||||
#define __argp_fmtstream_rmargin line_wrap_rmargin
|
||||
#define argp_fmtstream_rmargin line_wrap_rmargin
|
||||
#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin
|
||||
#define argp_fmtstream_set_rmargin line_wrap_set_rmargin
|
||||
#define __argp_fmtstream_wmargin line_wrap_wmargin
|
||||
#define argp_fmtstream_wmargin line_wrap_wmargin
|
||||
#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin
|
||||
#define argp_fmtstream_set_wmargin line_wrap_set_wmargin
|
||||
#define __argp_fmtstream_point line_wrap_point
|
||||
#define argp_fmtstream_point line_wrap_point
|
||||
|
||||
#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */
|
||||
/* Guess we have to define our own version. */
|
||||
|
||||
|
||||
struct argp_fmtstream
|
||||
{
|
||||
FILE *stream; /* The stream we're outputting to. */
|
||||
|
||||
size_t lmargin, rmargin; /* Left and right margins. */
|
||||
ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */
|
||||
|
||||
/* Point in buffer to which we've processed for wrapping, but not output. */
|
||||
size_t point_offs;
|
||||
/* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */
|
||||
ssize_t point_col;
|
||||
|
||||
char *buf; /* Output buffer. */
|
||||
char *p; /* Current end of text in BUF. */
|
||||
char *end; /* Absolute end of BUF. */
|
||||
};
|
||||
|
||||
typedef struct argp_fmtstream *argp_fmtstream_t;
|
||||
|
||||
/* Flush __FS to its stream, and free it (but don't close the stream). */
|
||||
extern void __argp_fmtstream_free (argp_fmtstream_t __fs);
|
||||
extern void argp_fmtstream_free (argp_fmtstream_t __fs);
|
||||
|
||||
/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
|
||||
written on it with LMARGIN spaces and limits them to RMARGIN columns
|
||||
total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
|
||||
replacing the whitespace before them with a newline and WMARGIN spaces.
|
||||
Otherwise, chars beyond RMARGIN are simply dropped until a newline.
|
||||
Returns NULL if there was an error. */
|
||||
extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream,
|
||||
size_t __lmargin,
|
||||
size_t __rmargin,
|
||||
ssize_t __wmargin)
|
||||
_GL_ATTRIBUTE_DEALLOC (__argp_fmtstream_free, 1);
|
||||
extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream,
|
||||
size_t __lmargin,
|
||||
size_t __rmargin,
|
||||
ssize_t __wmargin)
|
||||
_GL_ATTRIBUTE_DEALLOC (argp_fmtstream_free, 1);
|
||||
|
||||
extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs,
|
||||
const char *__fmt, ...)
|
||||
_GL_ATTRIBUTE_FORMAT ((printf, 2, 3));
|
||||
extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
|
||||
const char *__fmt, ...)
|
||||
_GL_ATTRIBUTE_FORMAT ((printf, 2, 3));
|
||||
|
||||
#if _LIBC
|
||||
extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
|
||||
extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
|
||||
|
||||
extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
|
||||
extern int argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
|
||||
|
||||
extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs,
|
||||
const char *__str, size_t __len);
|
||||
extern size_t argp_fmtstream_write (argp_fmtstream_t __fs,
|
||||
const char *__str, size_t __len);
|
||||
#endif
|
||||
|
||||
/* Access macros for various bits of state. */
|
||||
#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin)
|
||||
#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin)
|
||||
#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin)
|
||||
#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
|
||||
#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
|
||||
#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
|
||||
|
||||
#if _LIBC
|
||||
/* Set __FS's left margin to LMARGIN and return the old value. */
|
||||
extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
|
||||
size_t __lmargin);
|
||||
extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
|
||||
size_t __lmargin);
|
||||
|
||||
/* Set __FS's right margin to __RMARGIN and return the old value. */
|
||||
extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
|
||||
size_t __rmargin);
|
||||
extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
|
||||
size_t __rmargin);
|
||||
|
||||
/* Set __FS's wrap margin to __WMARGIN and return the old value. */
|
||||
extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
|
||||
size_t __wmargin);
|
||||
extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
|
||||
size_t __wmargin);
|
||||
|
||||
/* Return the column number of the current output point in __FS. */
|
||||
extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
|
||||
extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);
|
||||
#endif
|
||||
|
||||
/* Internal routines. */
|
||||
extern void _argp_fmtstream_update (argp_fmtstream_t __fs);
|
||||
extern void __argp_fmtstream_update (argp_fmtstream_t __fs);
|
||||
extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
|
||||
extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
|
||||
|
||||
#if !_LIBC || defined __OPTIMIZE__
|
||||
/* Inline versions of above routines. */
|
||||
|
||||
#if !_LIBC
|
||||
#define __argp_fmtstream_putc argp_fmtstream_putc
|
||||
#define __argp_fmtstream_puts argp_fmtstream_puts
|
||||
#define __argp_fmtstream_write argp_fmtstream_write
|
||||
#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
|
||||
#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
|
||||
#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
|
||||
#define __argp_fmtstream_point argp_fmtstream_point
|
||||
#define __argp_fmtstream_update _argp_fmtstream_update
|
||||
#define __argp_fmtstream_ensure _argp_fmtstream_ensure
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef ARGP_FS_EI
|
||||
# define ARGP_FS_EI _GL_INLINE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ARGP_FS_EI
|
||||
#define ARGP_FS_EI extern inline
|
||||
#endif
|
||||
|
||||
ARGP_FS_EI size_t
|
||||
__argp_fmtstream_write (argp_fmtstream_t __fs, const char *__str, size_t __len)
|
||||
{
|
||||
if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
|
||||
{
|
||||
memcpy (__fs->p, __str, __len);
|
||||
__fs->p += __len;
|
||||
return __len;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
ARGP_FS_EI int
|
||||
__argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str)
|
||||
{
|
||||
size_t __len = strlen (__str);
|
||||
if (__len)
|
||||
{
|
||||
size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
|
||||
return __wrote == __len ? 0 : -1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
ARGP_FS_EI int
|
||||
__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
|
||||
{
|
||||
if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1))
|
||||
return *__fs->p++ = __ch;
|
||||
else
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* Set __FS's left margin to __LMARGIN and return the old value. */
|
||||
ARGP_FS_EI size_t
|
||||
__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
|
||||
{
|
||||
size_t __old;
|
||||
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
|
||||
__argp_fmtstream_update (__fs);
|
||||
__old = __fs->lmargin;
|
||||
__fs->lmargin = __lmargin;
|
||||
return __old;
|
||||
}
|
||||
|
||||
/* Set __FS's right margin to __RMARGIN and return the old value. */
|
||||
ARGP_FS_EI size_t
|
||||
__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
|
||||
{
|
||||
size_t __old;
|
||||
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
|
||||
__argp_fmtstream_update (__fs);
|
||||
__old = __fs->rmargin;
|
||||
__fs->rmargin = __rmargin;
|
||||
return __old;
|
||||
}
|
||||
|
||||
/* Set FS's wrap margin to __WMARGIN and return the old value. */
|
||||
ARGP_FS_EI size_t
|
||||
__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
|
||||
{
|
||||
size_t __old;
|
||||
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
|
||||
__argp_fmtstream_update (__fs);
|
||||
__old = __fs->wmargin;
|
||||
__fs->wmargin = __wmargin;
|
||||
return __old;
|
||||
}
|
||||
|
||||
/* Return the column number of the current output point in __FS. */
|
||||
ARGP_FS_EI size_t
|
||||
__argp_fmtstream_point (argp_fmtstream_t __fs)
|
||||
{
|
||||
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
|
||||
__argp_fmtstream_update (__fs);
|
||||
return __fs->point_col >= 0 ? __fs->point_col : 0;
|
||||
}
|
||||
|
||||
#if !_LIBC
|
||||
#undef __argp_fmtstream_putc
|
||||
#undef __argp_fmtstream_puts
|
||||
#undef __argp_fmtstream_write
|
||||
#undef __argp_fmtstream_set_lmargin
|
||||
#undef __argp_fmtstream_set_rmargin
|
||||
#undef __argp_fmtstream_set_wmargin
|
||||
#undef __argp_fmtstream_point
|
||||
#undef __argp_fmtstream_update
|
||||
#undef __argp_fmtstream_ensure
|
||||
_GL_INLINE_HEADER_END
|
||||
#endif
|
||||
|
||||
#endif /* !_LIBC || __OPTIMIZE__ */
|
||||
|
||||
#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */
|
||||
|
||||
#endif /* argp-fmtstream.h */
|
||||
@@ -1,170 +0,0 @@
|
||||
/* Name frobnication for compiling argp outside of glibc
|
||||
Copyright (C) 1997-2024 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||
|
||||
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 3 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
|
||||
/* This code is written for inclusion in gnu-libc, and uses names in the
|
||||
namespace reserved for libc. If we're not compiling in libc, define those
|
||||
names to be the normal ones instead. */
|
||||
|
||||
/* argp-parse functions */
|
||||
#undef __argp_parse
|
||||
#define __argp_parse argp_parse
|
||||
#undef __option_is_end
|
||||
#define __option_is_end _option_is_end
|
||||
#undef __option_is_short
|
||||
#define __option_is_short _option_is_short
|
||||
#undef __argp_input
|
||||
#define __argp_input _argp_input
|
||||
|
||||
/* argp-help functions */
|
||||
#undef __argp_help
|
||||
#define __argp_help argp_help
|
||||
#undef __argp_error
|
||||
#define __argp_error argp_error
|
||||
#undef __argp_failure
|
||||
#define __argp_failure argp_failure
|
||||
#undef __argp_state_help
|
||||
#define __argp_state_help argp_state_help
|
||||
#undef __argp_usage
|
||||
#define __argp_usage argp_usage
|
||||
|
||||
/* argp-fmtstream functions */
|
||||
#undef __argp_make_fmtstream
|
||||
#define __argp_make_fmtstream argp_make_fmtstream
|
||||
#undef __argp_fmtstream_free
|
||||
#define __argp_fmtstream_free argp_fmtstream_free
|
||||
#undef __argp_fmtstream_putc
|
||||
#define __argp_fmtstream_putc argp_fmtstream_putc
|
||||
#undef __argp_fmtstream_puts
|
||||
#define __argp_fmtstream_puts argp_fmtstream_puts
|
||||
#undef __argp_fmtstream_write
|
||||
#define __argp_fmtstream_write argp_fmtstream_write
|
||||
#undef __argp_fmtstream_printf
|
||||
#define __argp_fmtstream_printf argp_fmtstream_printf
|
||||
#undef __argp_fmtstream_set_lmargin
|
||||
#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
|
||||
#undef __argp_fmtstream_set_rmargin
|
||||
#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
|
||||
#undef __argp_fmtstream_set_wmargin
|
||||
#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
|
||||
#undef __argp_fmtstream_point
|
||||
#define __argp_fmtstream_point argp_fmtstream_point
|
||||
#undef __argp_fmtstream_update
|
||||
#define __argp_fmtstream_update _argp_fmtstream_update
|
||||
#undef __argp_fmtstream_ensure
|
||||
#define __argp_fmtstream_ensure _argp_fmtstream_ensure
|
||||
#undef __argp_fmtstream_lmargin
|
||||
#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
|
||||
#undef __argp_fmtstream_rmargin
|
||||
#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
|
||||
#undef __argp_fmtstream_wmargin
|
||||
#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
|
||||
|
||||
/* normal libc functions we call */
|
||||
#undef __flockfile
|
||||
#define __flockfile flockfile
|
||||
#undef __funlockfile
|
||||
#define __funlockfile funlockfile
|
||||
#undef __mempcpy
|
||||
#define __mempcpy mempcpy
|
||||
#undef __sleep
|
||||
#define __sleep sleep
|
||||
#undef __strcasecmp
|
||||
#define __strcasecmp strcasecmp
|
||||
#undef __strchrnul
|
||||
#define __strchrnul strchrnul
|
||||
#undef __strerror_r
|
||||
#define __strerror_r strerror_r
|
||||
#undef __strndup
|
||||
#define __strndup strndup
|
||||
#undef __vsnprintf
|
||||
#define __vsnprintf vsnprintf
|
||||
|
||||
#if (defined HAVE_DECL_CLEARERR_UNLOCKED && !HAVE_DECL_CLEARERR_UNLOCKED \
|
||||
&& !defined clearerr_unlocked)
|
||||
# define clearerr_unlocked(x) clearerr (x)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_FEOF_UNLOCKED && !HAVE_DECL_FEOF_UNLOCKED \
|
||||
&& !defined feof_unlocked)
|
||||
# define feof_unlocked(x) feof (x)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_FERROR_UNLOCKED && !HAVE_DECL_FERROR_UNLOCKED \
|
||||
&& !defined ferror_unlocked)
|
||||
# define ferror_unlocked(x) ferror (x)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_FFLUSH_UNLOCKED && !HAVE_DECL_FFLUSH_UNLOCKED \
|
||||
&& !defined fflush_unlocked)
|
||||
# define fflush_unlocked(x) fflush (x)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_FGETS_UNLOCKED && !HAVE_DECL_FGETS_UNLOCKED \
|
||||
&& !defined fgets_unlocked)
|
||||
# define fgets_unlocked(x,y,z) fgets (x,y,z)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_FPUTC_UNLOCKED && !HAVE_DECL_FPUTC_UNLOCKED \
|
||||
&& !defined fputc_unlocked)
|
||||
# define fputc_unlocked(x,y) fputc (x,y)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_FPUTS_UNLOCKED && !HAVE_DECL_FPUTS_UNLOCKED \
|
||||
&& !defined fputs_unlocked)
|
||||
# define fputs_unlocked(x,y) fputs (x,y)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_FREAD_UNLOCKED && !HAVE_DECL_FREAD_UNLOCKED \
|
||||
&& !defined fread_unlocked)
|
||||
# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_FWRITE_UNLOCKED && !HAVE_DECL_FWRITE_UNLOCKED \
|
||||
&& !defined fwrite_unlocked)
|
||||
# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_GETC_UNLOCKED && !HAVE_DECL_GETC_UNLOCKED \
|
||||
&& !defined getc_unlocked)
|
||||
# define getc_unlocked(x) getc (x)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_GETCHAR_UNLOCKED && !HAVE_DECL_GETCHAR_UNLOCKED \
|
||||
&& !defined getchar_unlocked)
|
||||
# define getchar_unlocked() getchar ()
|
||||
#endif
|
||||
#if (defined HAVE_DECL_PUTC_UNLOCKED && !HAVE_DECL_PUTC_UNLOCKED \
|
||||
&& !defined putc_unlocked)
|
||||
# define putc_unlocked(x,y) putc (x,y)
|
||||
#endif
|
||||
#if (defined HAVE_DECL_PUTCHAR_UNLOCKED && !HAVE_DECL_PUTCHAR_UNLOCKED \
|
||||
&& !defined putchar_unlocked)
|
||||
# define putchar_unlocked(x) putchar (x)
|
||||
#endif
|
||||
|
||||
#endif /* !_LIBC */
|
||||
|
||||
#ifndef __set_errno
|
||||
#define __set_errno(e) (errno = (e))
|
||||
#endif
|
||||
|
||||
#if defined GNULIB_ARGP_DISABLE_DIRNAME
|
||||
# define __argp_base_name(arg) arg
|
||||
#elif defined GNULIB_ARGP_EXTERN_BASENAME
|
||||
extern char *__argp_base_name (const char *arg);
|
||||
#else
|
||||
# include "basename-lgpl.h"
|
||||
# define __argp_base_name last_component
|
||||
#endif
|
||||
|
||||
#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
|
||||
# define __argp_short_program_name() (program_invocation_short_name)
|
||||
#else
|
||||
extern char *__argp_short_program_name (void);
|
||||
#endif
|
||||
@@ -1,40 +0,0 @@
|
||||
/* Version hook for Argp.
|
||||
Copyright (C) 2009-2024 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/>. */
|
||||
|
||||
#ifndef _ARGP_VERSION_ETC_H
|
||||
#define _ARGP_VERSION_ETC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Setup standard display of the version information for the '--version'
|
||||
option. NAME is the canonical program name, and AUTHORS is a NULL-
|
||||
terminated array of author names. At least one author name must be
|
||||
given.
|
||||
|
||||
If NAME is NULL, the package name (as given by the PACKAGE macro)
|
||||
is assumed to be the name of the program.
|
||||
|
||||
This function is intended to be called before argp_parse().
|
||||
*/
|
||||
extern void argp_version_setup (const char *name, const char * const *authors);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ARGP_VERSION_ETC_H */
|
||||
@@ -1,645 +0,0 @@
|
||||
/* Hierarchical argument parsing, layered over getopt.
|
||||
Copyright (C) 1995-2024 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||
|
||||
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 3 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 _ARGP_H
|
||||
#define _ARGP_H
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_ATTRIBUTE_FORMAT. */
|
||||
#if !_LIBC && !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define __need_error_t
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef __THROW
|
||||
# define __THROW
|
||||
#endif
|
||||
#ifndef __NTH
|
||||
# define __NTH(fct) fct __THROW
|
||||
#endif
|
||||
|
||||
/* GCC 2.95 and later have "__restrict"; C99 compilers have
|
||||
"restrict", and "configure" may have defined "restrict".
|
||||
Other compilers use __restrict, __restrict__, and _Restrict, and
|
||||
'configure' might #define 'restrict' to those words. */
|
||||
#ifndef __restrict
|
||||
# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__) \
|
||||
|| __clang_major__ >= 3)
|
||||
# if 199901L <= __STDC_VERSION__
|
||||
# define __restrict restrict
|
||||
# else
|
||||
# define __restrict
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __error_t_defined
|
||||
typedef int error_t;
|
||||
# define __error_t_defined
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Glibc documentation:
|
||||
https://www.gnu.org/software/libc/manual/html_node/Argp.html */
|
||||
|
||||
/* A description of a particular option. A pointer to an array of
|
||||
these is passed in the OPTIONS field of an argp structure. Each option
|
||||
entry can correspond to one long option and/or one short option; more
|
||||
names for the same option can be added by following an entry in an option
|
||||
array with options having the OPTION_ALIAS flag set. */
|
||||
struct argp_option
|
||||
{
|
||||
/* The long option name. For more than one name for the same option, you
|
||||
can use following options with the OPTION_ALIAS flag set. */
|
||||
const char *name;
|
||||
|
||||
/* What key is returned for this option. If > 0 and printable, then it's
|
||||
also accepted as a short option. */
|
||||
int key;
|
||||
|
||||
/* If non-NULL, this is the name of the argument associated with this
|
||||
option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */
|
||||
const char *arg;
|
||||
|
||||
/* OPTION_ flags. */
|
||||
int flags;
|
||||
|
||||
/* The doc string for this option. If both NAME and KEY are 0, This string
|
||||
will be printed outdented from the normal option column, making it
|
||||
useful as a group header (it will be the first thing printed in its
|
||||
group); in this usage, it's conventional to end the string with a ':'.
|
||||
|
||||
Write the initial value as N_("TEXT") if you want xgettext to collect
|
||||
it into a POT file. */
|
||||
const char *doc;
|
||||
|
||||
/* The group this option is in. In a long help message, options are sorted
|
||||
alphabetically within each group, and the groups presented in the order
|
||||
0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with
|
||||
if this field 0 will inherit the group number of the previous entry, or
|
||||
zero if it's the first one, unless its a group header (NAME and KEY both
|
||||
0), in which case, the previous entry + 1 is the default. Automagic
|
||||
options such as --help are put into group -1. */
|
||||
int group;
|
||||
};
|
||||
|
||||
/* The argument associated with this option is optional. */
|
||||
#define OPTION_ARG_OPTIONAL 0x1
|
||||
|
||||
/* This option isn't displayed in any help messages. */
|
||||
#define OPTION_HIDDEN 0x2
|
||||
|
||||
/* This option is an alias for the closest previous non-alias option. This
|
||||
means that it will be displayed in the same help entry, and will inherit
|
||||
fields other than NAME and KEY from the aliased option. */
|
||||
#define OPTION_ALIAS 0x4
|
||||
|
||||
/* This option isn't actually an option (and so should be ignored by the
|
||||
actual option parser), but rather an arbitrary piece of documentation that
|
||||
should be displayed in much the same manner as the options. If this flag
|
||||
is set, then the option NAME field is displayed unmodified (e.g., no '--'
|
||||
prefix is added) at the left-margin (where a *short* option would normally
|
||||
be displayed), and the documentation string in the normal place. The NAME
|
||||
field will be translated using gettext, unless OPTION_NO_TRANS is set (see
|
||||
below). For purposes of sorting, any leading whitespace and punctuation is
|
||||
ignored, except that if the first non-whitespace character is not '-', this
|
||||
entry is displayed after all options (and OPTION_DOC entries with a leading
|
||||
'-') in the same group. */
|
||||
#define OPTION_DOC 0x8
|
||||
|
||||
/* This option shouldn't be included in "long" usage messages (but is still
|
||||
included in help messages). This is mainly intended for options that are
|
||||
completely documented in an argp's ARGS_DOC field, in which case including
|
||||
the option in the generic usage list would be redundant. For instance,
|
||||
if ARGS_DOC is "FOO BAR\n-x BLAH", and the '-x' option's purpose is to
|
||||
distinguish these two cases, -x should probably be marked
|
||||
OPTION_NO_USAGE. */
|
||||
#define OPTION_NO_USAGE 0x10
|
||||
|
||||
/* Valid only in conjunction with OPTION_DOC. This option disables translation
|
||||
of option name. */
|
||||
#define OPTION_NO_TRANS 0x20
|
||||
|
||||
struct argp; /* fwd declare this type */
|
||||
struct argp_state; /* " */
|
||||
struct argp_child; /* " */
|
||||
|
||||
/* The type of a pointer to an argp parsing function. */
|
||||
typedef error_t (*argp_parser_t) (int __key, char *__arg,
|
||||
struct argp_state *__state);
|
||||
|
||||
/* What to return for unrecognized keys. For special ARGP_KEY_ keys, such
|
||||
returns will simply be ignored. For user keys, this error will be turned
|
||||
into EINVAL (if the call to argp_parse is such that errors are propagated
|
||||
back to the user instead of exiting); returning EINVAL itself would result
|
||||
in an immediate stop to parsing in *all* cases. */
|
||||
#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */
|
||||
|
||||
/* Special values for the KEY argument to an argument parsing function.
|
||||
ARGP_ERR_UNKNOWN should be returned if they aren't understood.
|
||||
|
||||
The sequence of keys to a parsing function is either (where each
|
||||
uppercased word should be prefixed by 'ARGP_KEY_' and opt is a user key):
|
||||
|
||||
INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all
|
||||
or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed
|
||||
or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized
|
||||
|
||||
The third case is where every parser returned ARGP_KEY_UNKNOWN for an
|
||||
argument, in which case parsing stops at that argument (returning the
|
||||
unparsed arguments to the caller of argp_parse if requested, or stopping
|
||||
with an error message if not).
|
||||
|
||||
If an error occurs (either detected by argp, or because the parsing
|
||||
function returned an error value), then the parser is called with
|
||||
ARGP_KEY_ERROR, and no further calls are made. */
|
||||
|
||||
/* This is not an option at all, but rather a command line argument. If a
|
||||
parser receiving this key returns success, the fact is recorded, and the
|
||||
ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the
|
||||
argument, a parser function decrements the NEXT field of the state it's
|
||||
passed, the option won't be considered processed; this is to allow you to
|
||||
actually modify the argument (perhaps into an option), and have it
|
||||
processed again. */
|
||||
#define ARGP_KEY_ARG 0
|
||||
/* There are remaining arguments not parsed by any parser, which may be found
|
||||
starting at (STATE->argv + STATE->next). If success is returned, but
|
||||
STATE->next left untouched, it's assumed that all arguments were consume,
|
||||
otherwise, the parser should adjust STATE->next to reflect any arguments
|
||||
consumed. */
|
||||
#define ARGP_KEY_ARGS 0x1000006
|
||||
/* There are no more command line arguments at all. */
|
||||
#define ARGP_KEY_END 0x1000001
|
||||
/* Because it's common to want to do some special processing if there aren't
|
||||
any non-option args, user parsers are called with this key if they didn't
|
||||
successfully process any non-option arguments. Called just before
|
||||
ARGP_KEY_END (where more general validity checks on previously parsed
|
||||
arguments can take place). */
|
||||
#define ARGP_KEY_NO_ARGS 0x1000002
|
||||
/* Passed in before any parsing is done. Afterwards, the values of each
|
||||
element of the CHILD_INPUT field, if any, in the state structure is
|
||||
copied to each child's state to be the initial value of the INPUT field. */
|
||||
#define ARGP_KEY_INIT 0x1000003
|
||||
/* Use after all other keys, including SUCCESS & END. */
|
||||
#define ARGP_KEY_FINI 0x1000007
|
||||
/* Passed in when parsing has successfully been completed (even if there are
|
||||
still arguments remaining). */
|
||||
#define ARGP_KEY_SUCCESS 0x1000004
|
||||
/* Passed in if an error occurs. */
|
||||
#define ARGP_KEY_ERROR 0x1000005
|
||||
|
||||
/* An argp structure contains a set of options declarations, a function to
|
||||
deal with parsing one, documentation string, a possible vector of child
|
||||
argp's, and perhaps a function to filter help output. When actually
|
||||
parsing options, getopt is called with the union of all the argp
|
||||
structures chained together through their CHILD pointers, with conflicts
|
||||
being resolved in favor of the first occurrence in the chain. */
|
||||
struct argp
|
||||
{
|
||||
/* An array of argp_option structures, terminated by an entry with both
|
||||
NAME and KEY having a value of 0. */
|
||||
const struct argp_option *options;
|
||||
|
||||
/* What to do with an option from this structure. KEY is the key
|
||||
associated with the option, and ARG is any associated argument (NULL if
|
||||
none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be
|
||||
returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then
|
||||
parsing is stopped immediately, and that value is returned from
|
||||
argp_parse(). For special (non-user-supplied) values of KEY, see the
|
||||
ARGP_KEY_ definitions below. */
|
||||
argp_parser_t parser;
|
||||
|
||||
/* If non-NULL, a string describing what other arguments are wanted by this
|
||||
program. It is only used by argp_usage to print the "Usage:" message.
|
||||
If it contains newlines, the strings separated by them are considered
|
||||
alternative usage patterns, and printed on separate lines (lines after
|
||||
the first are prefix by " or: " instead of "Usage:"). */
|
||||
const char *args_doc;
|
||||
|
||||
/* If non-NULL, a string containing extra text to be printed before and
|
||||
after the options in a long help message (separated by a vertical tab
|
||||
'\v' character).
|
||||
Write the initial value as N_("BEFORE-TEXT") "\v" N_("AFTER-TEXT") if
|
||||
you want xgettext to collect the two pieces of text into a POT file. */
|
||||
const char *doc;
|
||||
|
||||
/* A vector of argp_children structures, terminated by a member with a 0
|
||||
argp field, pointing to child argps should be parsed with this one. Any
|
||||
conflicts are resolved in favor of this argp, or early argps in the
|
||||
CHILDREN list. This field is useful if you use libraries that supply
|
||||
their own argp structure, which you want to use in conjunction with your
|
||||
own. */
|
||||
const struct argp_child *children;
|
||||
|
||||
/* If non-zero, this should be a function to filter the output of help
|
||||
messages. KEY is either a key from an option, in which case TEXT is
|
||||
that option's help text, or a special key from the ARGP_KEY_HELP_
|
||||
defines, below, describing which other help text TEXT is. The function
|
||||
should return either TEXT, if it should be used as-is, a replacement
|
||||
string, which should be malloced, and will be freed by argp, or NULL,
|
||||
meaning "print nothing". The value for TEXT is *after* any translation
|
||||
has been done, so if any of the replacement text also needs translation,
|
||||
that should be done by the filter function. INPUT is either the input
|
||||
supplied to argp_parse, or NULL, if argp_help was called directly. */
|
||||
char *(*help_filter) (int __key, const char *__text, void *__input);
|
||||
|
||||
/* If non-zero the strings used in the argp library are translated using
|
||||
the domain described by this string. Otherwise the currently installed
|
||||
default domain is used. */
|
||||
const char *argp_domain;
|
||||
};
|
||||
|
||||
/* Possible KEY arguments to a help filter function. */
|
||||
#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceding options. */
|
||||
#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */
|
||||
#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */
|
||||
#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation;
|
||||
TEXT is NULL for this key. */
|
||||
/* Explanatory note emitted when duplicate option arguments have been
|
||||
suppressed. */
|
||||
#define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005
|
||||
#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */
|
||||
|
||||
/* When an argp has a non-zero CHILDREN field, it should point to a vector of
|
||||
argp_child structures, each of which describes a subsidiary argp. */
|
||||
struct argp_child
|
||||
{
|
||||
/* The child parser. */
|
||||
const struct argp *argp;
|
||||
|
||||
/* Flags for this child. */
|
||||
int flags;
|
||||
|
||||
/* If non-zero, an optional header to be printed in help output before the
|
||||
child options. As a side-effect, a non-zero value forces the child
|
||||
options to be grouped together; to achieve this effect without actually
|
||||
printing a header string, use a value of "". */
|
||||
const char *header;
|
||||
|
||||
/* Where to group the child options relative to the other ("consolidated")
|
||||
options in the parent argp; the values are the same as the GROUP field
|
||||
in argp_option structs, but all child-groupings follow parent options at
|
||||
a particular group level. If both this field and HEADER are zero, then
|
||||
they aren't grouped at all, but rather merged with the parent options
|
||||
(merging the child's grouping levels with the parents). */
|
||||
int group;
|
||||
};
|
||||
|
||||
/* Parsing state. This is provided to parsing functions called by argp,
|
||||
which may examine and, as noted, modify fields. */
|
||||
struct argp_state
|
||||
{
|
||||
/* The top level ARGP being parsed. */
|
||||
const struct argp *root_argp;
|
||||
|
||||
/* The argument vector being parsed. May be modified. */
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
/* The index in ARGV of the next arg that to be parsed. May be modified. */
|
||||
int next;
|
||||
|
||||
/* The flags supplied to argp_parse. May be modified. */
|
||||
unsigned flags;
|
||||
|
||||
/* While calling a parsing function with a key of ARGP_KEY_ARG, this is the
|
||||
number of the current arg, starting at zero, and incremented after each
|
||||
such call returns. At all other times, this is the number of such
|
||||
arguments that have been processed. */
|
||||
unsigned arg_num;
|
||||
|
||||
/* If non-zero, the index in ARGV of the first argument following a special
|
||||
'--' argument (which prevents anything following being interpreted as an
|
||||
option). Only set once argument parsing has proceeded past this point. */
|
||||
int quoted;
|
||||
|
||||
/* An arbitrary pointer passed in from the user. */
|
||||
void *input;
|
||||
/* Values to pass to child parsers. This vector will be the same length as
|
||||
the number of children for the current parser. */
|
||||
void **child_inputs;
|
||||
|
||||
/* For the parser's use. Initialized to 0. */
|
||||
void *hook;
|
||||
|
||||
/* The name used when printing messages. This is initialized to ARGV[0],
|
||||
or PROGRAM_INVOCATION_NAME if that is unavailable. */
|
||||
char *name;
|
||||
|
||||
/* Streams used when argp prints something. */
|
||||
FILE *err_stream; /* For errors; initialized to stderr. */
|
||||
FILE *out_stream; /* For information; initialized to stdout. */
|
||||
|
||||
void *pstate; /* Private, for use by argp. */
|
||||
};
|
||||
|
||||
/* Flags for argp_parse (note that the defaults are those that are
|
||||
convenient for program command line parsing): */
|
||||
|
||||
/* Don't ignore the first element of ARGV. Normally (and always unless
|
||||
ARGP_NO_ERRS is set) the first element of the argument vector is
|
||||
skipped for option parsing purposes, as it corresponds to the program name
|
||||
in a command line. */
|
||||
#define ARGP_PARSE_ARGV0 0x01
|
||||
|
||||
/* Don't print error messages for unknown options to stderr; unless this flag
|
||||
is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program
|
||||
name in the error messages. This flag implies ARGP_NO_EXIT (on the
|
||||
assumption that silent exiting upon errors is bad behaviour). */
|
||||
#define ARGP_NO_ERRS 0x02
|
||||
|
||||
/* Don't parse any non-option args. Normally non-option args are parsed by
|
||||
calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg
|
||||
as the value. Since it's impossible to know which parse function wants to
|
||||
handle it, each one is called in turn, until one returns 0 or an error
|
||||
other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the
|
||||
argp_parse returns prematurely (but with a return value of 0). If all
|
||||
args have been parsed without error, all parsing functions are called one
|
||||
last time with a key of ARGP_KEY_END. This flag needn't normally be set,
|
||||
as the normal behavior is to stop parsing as soon as some argument can't
|
||||
be handled. */
|
||||
#define ARGP_NO_ARGS 0x04
|
||||
|
||||
/* Parse options and arguments in the same order they occur on the command
|
||||
line -- normally they're rearranged so that all options come first. */
|
||||
#define ARGP_IN_ORDER 0x08
|
||||
|
||||
/* Don't provide the standard long option --help, which causes usage and
|
||||
option help information to be output to stdout, and exit (0) called. */
|
||||
#define ARGP_NO_HELP 0x10
|
||||
|
||||
/* Don't exit on errors (they may still result in error messages). */
|
||||
#define ARGP_NO_EXIT 0x20
|
||||
|
||||
/* Use the gnu getopt "long-only" rules for parsing arguments. */
|
||||
#define ARGP_LONG_ONLY 0x40
|
||||
|
||||
/* Turns off any message-printing/exiting options. */
|
||||
#define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP)
|
||||
|
||||
/* Parse the options strings in ARGC & ARGV according to the options in ARGP.
|
||||
FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the
|
||||
index in ARGV of the first unparsed option is returned in it. If an
|
||||
unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser
|
||||
routine returned a non-zero value, it is returned; otherwise 0 is
|
||||
returned. This function may also call exit unless the ARGP_NO_HELP flag
|
||||
is set. INPUT is a pointer to a value to be passed to the parser. */
|
||||
extern error_t argp_parse (const struct argp *__restrict __argp,
|
||||
int /*argc*/, char **__restrict /*argv*/,
|
||||
unsigned __flags, int *__restrict __arg_index,
|
||||
void *__restrict __input);
|
||||
extern error_t __argp_parse (const struct argp *__restrict __argp,
|
||||
int /*argc*/, char **__restrict /*argv*/,
|
||||
unsigned __flags, int *__restrict __arg_index,
|
||||
void *__restrict __input);
|
||||
|
||||
/* Global variables. */
|
||||
|
||||
/* GNULIB makes sure both program_invocation_name and
|
||||
program_invocation_short_name are available */
|
||||
#ifdef GNULIB_PROGRAM_INVOCATION_NAME
|
||||
extern char *program_invocation_name;
|
||||
# undef HAVE_DECL_PROGRAM_INVOCATION_NAME
|
||||
# define HAVE_DECL_PROGRAM_INVOCATION_NAME 1
|
||||
#endif
|
||||
|
||||
#ifdef GNULIB_PROGRAM_INVOCATION_SHORT_NAME
|
||||
extern char *program_invocation_short_name;
|
||||
# undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
|
||||
# define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 1
|
||||
#endif
|
||||
|
||||
/* If defined or set by the user program to a non-zero value, then a default
|
||||
option --version is added (unless the ARGP_NO_HELP flag is used), which
|
||||
will print this string followed by a newline and exit (unless the
|
||||
ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
|
||||
extern const char *argp_program_version;
|
||||
|
||||
/* If defined or set by the user program to a non-zero value, then a default
|
||||
option --version is added (unless the ARGP_NO_HELP flag is used), which
|
||||
calls this function with a stream to print the version to and a pointer to
|
||||
the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
|
||||
used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
|
||||
extern void (*argp_program_version_hook) (FILE *__restrict __stream,
|
||||
struct argp_state *__restrict
|
||||
__state);
|
||||
|
||||
/* If defined or set by the user program, it should point to string that is
|
||||
the bug-reporting address for the program. It will be printed by
|
||||
argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various
|
||||
standard help messages), embedded in a sentence that says something like
|
||||
"Report bugs to ADDR." */
|
||||
extern const char *argp_program_bug_address;
|
||||
|
||||
/* The exit status that argp will use when exiting due to a parsing error.
|
||||
If not defined or set by the user program, this defaults to EX_USAGE from
|
||||
<sysexits.h>. */
|
||||
extern error_t argp_err_exit_status;
|
||||
|
||||
/* Flags for argp_help. */
|
||||
#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */
|
||||
#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */
|
||||
#define ARGP_HELP_SEE 0x04 /* a "Try ... for more help" message. */
|
||||
#define ARGP_HELP_LONG 0x08 /* a long help message. */
|
||||
#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */
|
||||
#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */
|
||||
#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)
|
||||
#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */
|
||||
#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to
|
||||
reflect ARGP_LONG_ONLY mode. */
|
||||
|
||||
/* These ARGP_HELP flags are only understood by argp_state_help. */
|
||||
#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */
|
||||
#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */
|
||||
|
||||
/* The standard thing to do after a program command line parsing error, if an
|
||||
error message has already been printed. */
|
||||
#define ARGP_HELP_STD_ERR \
|
||||
(ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
|
||||
/* The standard thing to do after a program command line parsing error, if no
|
||||
more specific error message has been printed. */
|
||||
#define ARGP_HELP_STD_USAGE \
|
||||
(ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
|
||||
/* The standard thing to do in response to a --help option. */
|
||||
#define ARGP_HELP_STD_HELP \
|
||||
(ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \
|
||||
| ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR)
|
||||
|
||||
/* Output a usage message for ARGP to STREAM. FLAGS are from the set
|
||||
ARGP_HELP_*. */
|
||||
extern void argp_help (const struct argp *__restrict __argp,
|
||||
FILE *__restrict __stream,
|
||||
unsigned __flags, char *__restrict __name);
|
||||
extern void __argp_help (const struct argp *__restrict __argp,
|
||||
FILE *__restrict __stream, unsigned __flags,
|
||||
char *__name);
|
||||
|
||||
/* The following routines are intended to be called from within an argp
|
||||
parsing routine (thus taking an argp_state structure as the first
|
||||
argument). They may or may not print an error message and exit, depending
|
||||
on the flags in STATE -- in any case, the caller should be prepared for
|
||||
them *not* to exit, and should return an appropriate error after calling
|
||||
them. [argp_usage & argp_error should probably be called argp_state_...,
|
||||
but they're used often enough that they should be short] */
|
||||
|
||||
/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are
|
||||
from the set ARGP_HELP_*. */
|
||||
extern void argp_state_help (const struct argp_state *__restrict __state,
|
||||
FILE *__restrict __stream,
|
||||
unsigned int __flags);
|
||||
extern void __argp_state_help (const struct argp_state *__restrict __state,
|
||||
FILE *__restrict __stream,
|
||||
unsigned int __flags);
|
||||
|
||||
#if _LIBC
|
||||
/* Possibly output the standard usage message for ARGP to stderr and exit. */
|
||||
extern void argp_usage (const struct argp_state *__state);
|
||||
extern void __argp_usage (const struct argp_state *__state);
|
||||
#endif
|
||||
|
||||
/* If appropriate, print the printf string FMT and following args, preceded
|
||||
by the program name and ':', to stderr, and followed by a "Try ... --help"
|
||||
message, then exit (1). */
|
||||
extern void argp_error (const struct argp_state *__restrict __state,
|
||||
const char *__restrict __fmt, ...)
|
||||
#if GNULIB_VFPRINTF_POSIX
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3))
|
||||
#else
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 2, 3))
|
||||
#endif
|
||||
;
|
||||
extern void __argp_error (const struct argp_state *__restrict __state,
|
||||
const char *__restrict __fmt, ...)
|
||||
#if GNULIB_VFPRINTF_POSIX
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3))
|
||||
#else
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 2, 3))
|
||||
#endif
|
||||
;
|
||||
|
||||
/* Similar to the standard gnu error-reporting function error(), but will
|
||||
respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
|
||||
to STATE->err_stream. This is useful for argument parsing code that is
|
||||
shared between program startup (when exiting is desired) and runtime
|
||||
option parsing (when typically an error code is returned instead). The
|
||||
difference between this function and argp_error is that the latter is for
|
||||
*parsing errors*, and the former is for other problems that occur during
|
||||
parsing but don't reflect a (syntactic) problem with the input. */
|
||||
extern void argp_failure (const struct argp_state *__restrict __state,
|
||||
int __status, int __errnum,
|
||||
const char *__restrict __fmt, ...)
|
||||
#if GNULIB_VFPRINTF_POSIX
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 4, 5))
|
||||
#else
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 4, 5))
|
||||
#endif
|
||||
;
|
||||
extern void __argp_failure (const struct argp_state *__restrict __state,
|
||||
int __status, int __errnum,
|
||||
const char *__restrict __fmt, ...)
|
||||
#if GNULIB_VFPRINTF_POSIX
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 4, 5))
|
||||
#else
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 4, 5))
|
||||
#endif
|
||||
;
|
||||
|
||||
#if _LIBC
|
||||
/* Returns true if the option OPT is a valid short option. */
|
||||
extern int _option_is_short (const struct argp_option *__opt) __THROW;
|
||||
extern int __option_is_short (const struct argp_option *__opt) __THROW;
|
||||
|
||||
/* Returns true if the option OPT is in fact the last (unused) entry in an
|
||||
options array. */
|
||||
extern int _option_is_end (const struct argp_option *__opt) __THROW;
|
||||
extern int __option_is_end (const struct argp_option *__opt) __THROW;
|
||||
#endif
|
||||
|
||||
/* Return the input field for ARGP in the parser corresponding to STATE; used
|
||||
by the help routines. */
|
||||
extern void *_argp_input (const struct argp *__restrict __argp,
|
||||
const struct argp_state *__restrict __state)
|
||||
__THROW;
|
||||
extern void *__argp_input (const struct argp *__restrict __argp,
|
||||
const struct argp_state *__restrict __state)
|
||||
__THROW;
|
||||
|
||||
#if !_LIBC || defined __USE_EXTERN_INLINES
|
||||
|
||||
# if !_LIBC
|
||||
# define __argp_usage argp_usage
|
||||
# define __argp_state_help argp_state_help
|
||||
# define __option_is_short _option_is_short
|
||||
# define __option_is_end _option_is_end
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
# ifndef ARGP_EI
|
||||
# define ARGP_EI _GL_INLINE
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef ARGP_EI
|
||||
# define ARGP_EI __extern_inline
|
||||
# endif
|
||||
|
||||
ARGP_EI void
|
||||
__argp_usage (const struct argp_state *__state)
|
||||
{
|
||||
__argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);
|
||||
}
|
||||
|
||||
ARGP_EI int
|
||||
__NTH (__option_is_short (const struct argp_option *__opt))
|
||||
{
|
||||
if (__opt->flags & OPTION_DOC)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
int __key = __opt->key;
|
||||
return __key > 0 && __key <= UCHAR_MAX && isprint (__key);
|
||||
}
|
||||
}
|
||||
|
||||
ARGP_EI int
|
||||
__NTH (__option_is_end (const struct argp_option *__opt))
|
||||
{
|
||||
return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
|
||||
}
|
||||
|
||||
# if !_LIBC
|
||||
# undef __argp_usage
|
||||
# undef __argp_state_help
|
||||
# undef __option_is_short
|
||||
# undef __option_is_end
|
||||
_GL_INLINE_HEADER_END
|
||||
# endif
|
||||
#endif /* Use extern inlines. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* argp.h */
|
||||
@@ -1,57 +0,0 @@
|
||||
/* Iterate over arguments from argv or --files0-from=FILE
|
||||
Copyright (C) 2008-2024 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/>. */
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_PURE. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Definition of _GL_ARG_NONNULL. */
|
||||
#include "arg-nonnull.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct argv_iterator;
|
||||
|
||||
enum argv_iter_err
|
||||
{
|
||||
AI_ERR_OK = 1,
|
||||
AI_ERR_EOF,
|
||||
AI_ERR_MEM,
|
||||
AI_ERR_READ
|
||||
};
|
||||
|
||||
void argv_iter_free (struct argv_iterator *)
|
||||
_GL_ARG_NONNULL ((1));
|
||||
|
||||
struct argv_iterator *argv_iter_init_argv (char **argv)
|
||||
_GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_DEALLOC (argv_iter_free, 1);
|
||||
struct argv_iterator *argv_iter_init_stream (FILE *fp)
|
||||
_GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_DEALLOC (argv_iter_free, 1);
|
||||
char *argv_iter (struct argv_iterator *, enum argv_iter_err *)
|
||||
_GL_ARG_NONNULL ((1, 2));
|
||||
size_t argv_iter_n_args (struct argv_iterator const *)
|
||||
_GL_ATTRIBUTE_PURE _GL_ARG_NONNULL ((1));
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,281 +0,0 @@
|
||||
/* Stable-sorting of an array using mergesort.
|
||||
Copyright (C) 2009-2024 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2009.
|
||||
|
||||
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/>. */
|
||||
|
||||
/* This file implements stable sorting of an array, using the mergesort
|
||||
algorithm.
|
||||
Worst-case running time for an array of length N is O(N log N).
|
||||
Unlike the mpsort module, the algorithm here attempts to minimize not
|
||||
only the number of comparisons, but also the number of copying operations.
|
||||
|
||||
Before including this file, you need to define
|
||||
ELEMENT The type of every array element.
|
||||
COMPARE A two-argument macro that takes two 'const ELEMENT *'
|
||||
pointers and returns a negative, zero, or positive 'int'
|
||||
value if the element pointed to by the first argument is,
|
||||
respectively, less, equal, or greater than the element
|
||||
pointed to by the second argument.
|
||||
STATIC The storage class of the functions being defined.
|
||||
STATIC_FROMTO (Optional.) Overrides STATIC for the 'merge_sort_fromto'
|
||||
function.
|
||||
Before including this file, you also need to include:
|
||||
#include <stddef.h>
|
||||
*/
|
||||
|
||||
/* Merge the sorted arrays src1[0..n1-1] and src2[0..n2-1] into
|
||||
dst[0..n1+n2-1]. In case of ambiguity, put the elements of src1
|
||||
before the elements of src2.
|
||||
n1 and n2 must be > 0.
|
||||
The arrays src1 and src2 must not overlap the dst array, except that
|
||||
src1 may be dst[n2..n1+n2-1], or src2 may be dst[n1..n1+n2-1]. */
|
||||
static void
|
||||
merge (const ELEMENT *src1, size_t n1,
|
||||
const ELEMENT *src2, size_t n2,
|
||||
ELEMENT *dst)
|
||||
{
|
||||
for (;;) /* while (n1 > 0 && n2 > 0) */
|
||||
{
|
||||
if (COMPARE (src1, src2) <= 0)
|
||||
{
|
||||
*dst++ = *src1++;
|
||||
n1--;
|
||||
if (n1 == 0)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst++ = *src2++;
|
||||
n2--;
|
||||
if (n2 == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Here n1 == 0 || n2 == 0 but also n1 > 0 || n2 > 0. */
|
||||
if (n1 > 0)
|
||||
{
|
||||
if (dst != src1)
|
||||
do
|
||||
{
|
||||
*dst++ = *src1++;
|
||||
n1--;
|
||||
}
|
||||
while (n1 > 0);
|
||||
}
|
||||
else /* n2 > 0 */
|
||||
{
|
||||
if (dst != src2)
|
||||
do
|
||||
{
|
||||
*dst++ = *src2++;
|
||||
n2--;
|
||||
}
|
||||
while (n2 > 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Sort src[0..n-1] into dst[0..n-1], using tmp[0..n/2-1] as temporary
|
||||
(scratch) storage.
|
||||
The arrays src, dst, tmp must not overlap. */
|
||||
#ifdef STATIC_FROMTO
|
||||
STATIC_FROMTO
|
||||
#else
|
||||
STATIC
|
||||
#endif
|
||||
void
|
||||
merge_sort_fromto (const ELEMENT *src, ELEMENT *dst, size_t n, ELEMENT *tmp)
|
||||
{
|
||||
switch (n)
|
||||
{
|
||||
case 0:
|
||||
return;
|
||||
case 1:
|
||||
/* Nothing to do. */
|
||||
dst[0] = src[0];
|
||||
return;
|
||||
case 2:
|
||||
/* Trivial case. */
|
||||
if (COMPARE (&src[0], &src[1]) <= 0)
|
||||
{
|
||||
/* src[0] <= src[1] */
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
dst[0] = src[1];
|
||||
dst[1] = src[0];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
/* Simple case. */
|
||||
if (COMPARE (&src[0], &src[1]) <= 0)
|
||||
{
|
||||
if (COMPARE (&src[1], &src[2]) <= 0)
|
||||
{
|
||||
/* src[0] <= src[1] <= src[2] */
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[2];
|
||||
}
|
||||
else if (COMPARE (&src[0], &src[2]) <= 0)
|
||||
{
|
||||
/* src[0] <= src[2] < src[1] */
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[2];
|
||||
dst[2] = src[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* src[2] < src[0] <= src[1] */
|
||||
dst[0] = src[2];
|
||||
dst[1] = src[0];
|
||||
dst[2] = src[1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (COMPARE (&src[0], &src[2]) <= 0)
|
||||
{
|
||||
/* src[1] < src[0] <= src[2] */
|
||||
dst[0] = src[1];
|
||||
dst[1] = src[0];
|
||||
dst[2] = src[2];
|
||||
}
|
||||
else if (COMPARE (&src[1], &src[2]) <= 0)
|
||||
{
|
||||
/* src[1] <= src[2] < src[0] */
|
||||
dst[0] = src[1];
|
||||
dst[1] = src[2];
|
||||
dst[2] = src[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* src[2] < src[1] < src[0] */
|
||||
dst[0] = src[2];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
size_t n1 = n / 2;
|
||||
size_t n2 = (n + 1) / 2;
|
||||
/* Note: n1 + n2 = n, n1 <= n2. */
|
||||
/* Sort src[n1..n-1] into dst[n1..n-1], scratching tmp[0..n2/2-1]. */
|
||||
merge_sort_fromto (src + n1, dst + n1, n2, tmp);
|
||||
/* Sort src[0..n1-1] into tmp[0..n1-1], scratching dst[0..n1-1]. */
|
||||
merge_sort_fromto (src, tmp, n1, dst);
|
||||
/* Merge the two half results. */
|
||||
merge (tmp, n1, dst + n1, n2, dst);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Sort src[0..n-1], using tmp[0..n-1] as temporary (scratch) storage.
|
||||
The arrays src, tmp must not overlap. */
|
||||
STATIC void
|
||||
merge_sort_inplace (ELEMENT *src, size_t n, ELEMENT *tmp)
|
||||
{
|
||||
switch (n)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
/* Nothing to do. */
|
||||
return;
|
||||
case 2:
|
||||
/* Trivial case. */
|
||||
if (COMPARE (&src[0], &src[1]) <= 0)
|
||||
{
|
||||
/* src[0] <= src[1] */
|
||||
}
|
||||
else
|
||||
{
|
||||
ELEMENT t = src[0];
|
||||
src[0] = src[1];
|
||||
src[1] = t;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
/* Simple case. */
|
||||
if (COMPARE (&src[0], &src[1]) <= 0)
|
||||
{
|
||||
if (COMPARE (&src[1], &src[2]) <= 0)
|
||||
{
|
||||
/* src[0] <= src[1] <= src[2] */
|
||||
}
|
||||
else if (COMPARE (&src[0], &src[2]) <= 0)
|
||||
{
|
||||
/* src[0] <= src[2] < src[1] */
|
||||
ELEMENT t = src[1];
|
||||
src[1] = src[2];
|
||||
src[2] = t;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* src[2] < src[0] <= src[1] */
|
||||
ELEMENT t = src[0];
|
||||
src[0] = src[2];
|
||||
src[2] = src[1];
|
||||
src[1] = t;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (COMPARE (&src[0], &src[2]) <= 0)
|
||||
{
|
||||
/* src[1] < src[0] <= src[2] */
|
||||
ELEMENT t = src[0];
|
||||
src[0] = src[1];
|
||||
src[1] = t;
|
||||
}
|
||||
else if (COMPARE (&src[1], &src[2]) <= 0)
|
||||
{
|
||||
/* src[1] <= src[2] < src[0] */
|
||||
ELEMENT t = src[0];
|
||||
src[0] = src[1];
|
||||
src[1] = src[2];
|
||||
src[2] = t;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* src[2] < src[1] < src[0] */
|
||||
ELEMENT t = src[0];
|
||||
src[0] = src[2];
|
||||
src[2] = t;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
size_t n1 = n / 2;
|
||||
size_t n2 = (n + 1) / 2;
|
||||
/* Note: n1 + n2 = n, n1 <= n2. */
|
||||
/* Sort src[n1..n-1], scratching tmp[0..n2-1]. */
|
||||
merge_sort_inplace (src + n1, n2, tmp);
|
||||
/* Sort src[0..n1-1] into tmp[0..n1-1], scratching tmp[n1..2*n1-1]. */
|
||||
merge_sort_fromto (src, tmp, n1, tmp + n1);
|
||||
/* Merge the two half results. */
|
||||
merge (tmp, n1, src + n1, n2, src);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#undef ELEMENT
|
||||
#undef COMPARE
|
||||
#undef STATIC
|
||||
@@ -1,57 +0,0 @@
|
||||
/* Run-time assert-like macros.
|
||||
|
||||
Copyright (C) 2014-2024 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_ASSURE_H
|
||||
#define _GL_ASSURE_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "verify.h"
|
||||
|
||||
/* Evaluate an assertion E that is guaranteed to be true.
|
||||
If NDEBUG is not defined, abort the program if E is false.
|
||||
If NDEBUG is defined, the compiler can assume E and behavior is
|
||||
undefined if E is false, fails to evaluate, or has side effects.
|
||||
|
||||
Unlike standard 'assert', this macro evaluates E even when NDEBUG
|
||||
is defined, so as to catch typos, avoid some GCC warnings, and
|
||||
improve performance when E is simple enough.
|
||||
|
||||
Also see the documentation for 'assume' in verify.h. */
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define affirm(E) assume (E)
|
||||
#else
|
||||
# define affirm(E) assert (E)
|
||||
#endif
|
||||
|
||||
/* Check E's value at runtime, and report an error and abort if not.
|
||||
However, do nothing if NDEBUG is defined.
|
||||
|
||||
Unlike standard 'assert', this macro compiles E even when NDEBUG
|
||||
is defined, so as to catch typos and avoid some GCC warnings.
|
||||
Unlike 'affirm', it is OK for E to use hard-to-optimize features,
|
||||
since E is not executed if NDEBUG is defined. */
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define assure(E) ((void) (0 && (E)))
|
||||
#else
|
||||
# define assure(E) assert (E)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,48 +0,0 @@
|
||||
/* Locale dependent string transformation for comparison.
|
||||
Copyright (C) 2010-2024 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 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
|
||||
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 ASTRXFRM_H
|
||||
#define ASTRXFRM_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Variant of strxfrm() with a calling convention that reduces the number
|
||||
of strxfrm calls. */
|
||||
|
||||
/* Transform the string starting at S to a string, in such a way that
|
||||
comparing S1 and S2 with strcoll() is equivalent to comparing astrxfrm(S1)
|
||||
and astrxfrm(S2) with strcmp().
|
||||
The result of this function depends on the LC_COLLATE category of the
|
||||
current locale.
|
||||
If successful: If resultbuf is not NULL and the result fits into *lengthp
|
||||
bytes, it is put in resultbuf, and resultbuf is returned. Otherwise, a
|
||||
freshly allocated string is returned. In both cases, *lengthp is set to the
|
||||
length of the returned string.
|
||||
Upon failure, return NULL, with errno set. */
|
||||
extern char * astrxfrm (const char *s,
|
||||
char *restrict resultbuf, size_t *lengthp);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ASTRXFRM_H */
|
||||
@@ -1,69 +0,0 @@
|
||||
/* Spin locks for communication between threads and signal handlers.
|
||||
Copyright (C) 2020-2024 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>, 2020. */
|
||||
|
||||
#ifndef _ASYNCSAFE_SPIN_H
|
||||
#define _ASYNCSAFE_SPIN_H
|
||||
|
||||
/* Usual spin locks are not allowed for communication between threads and signal
|
||||
handlers, because the pthread_spin_* functions are not async-safe; see
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html>
|
||||
section 2.4.3 Signal Actions.
|
||||
|
||||
This module provides spin locks with a similar API. It can be used like this,
|
||||
both in regular multithreaded code and in signal handlers:
|
||||
|
||||
sigset_t saved_mask;
|
||||
asyncsafe_spin_lock (&lock, &mask, &saved_mask);
|
||||
do_something_contentious ();
|
||||
asyncsafe_spin_unlock (&lock, &saved_mask);
|
||||
|
||||
The mask you specify here is the set of signals whose handlers might want to
|
||||
take the same lock.
|
||||
|
||||
asyncsafe_spin_lock/unlock use pthread_sigmask, to ensure that while a thread
|
||||
is executing such code, no signal handler will start such code for the same
|
||||
lock *in the same thread* (because if this happened, the signal handler would
|
||||
hang!). */
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#if defined _WIN32 && ! defined __CYGWIN__
|
||||
# include "windows-spin.h"
|
||||
typedef glwthread_spinlock_t asyncsafe_spinlock_t;
|
||||
# define ASYNCSAFE_SPIN_INIT GLWTHREAD_SPIN_INIT
|
||||
#else
|
||||
typedef unsigned int asyncsafe_spinlock_t;
|
||||
# define ASYNCSAFE_SPIN_INIT 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void asyncsafe_spin_init (asyncsafe_spinlock_t *lock);
|
||||
extern void asyncsafe_spin_lock (asyncsafe_spinlock_t *lock,
|
||||
const sigset_t *mask, sigset_t *saved_mask);
|
||||
extern void asyncsafe_spin_unlock (asyncsafe_spinlock_t *lock,
|
||||
const sigset_t *saved_mask);
|
||||
extern void asyncsafe_spin_destroy (asyncsafe_spinlock_t *lock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASYNCSAFE_SPIN_H */
|
||||
@@ -1,320 +0,0 @@
|
||||
/* ATTRIBUTE_* macros for using attributes in GCC and similar compilers
|
||||
|
||||
Copyright 2020-2024 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. */
|
||||
|
||||
/* Provide public ATTRIBUTE_* names for the private _GL_ATTRIBUTE_*
|
||||
macros used within Gnulib. */
|
||||
|
||||
/* The placement of these attributes depends on the kind of declaration
|
||||
and, in some cases, also on the programming language (C vs. C++).
|
||||
|
||||
In function declarations and function definitions:
|
||||
|
||||
* ATTRIBUTE_NOTHROW must come after the parameter list.
|
||||
|
||||
* The macros
|
||||
ATTRIBUTE_CONST
|
||||
ATTRIBUTE_PURE
|
||||
DEPRECATED
|
||||
MAYBE_UNUSED
|
||||
NODISCARD
|
||||
REPRODUCIBLE
|
||||
UNSEQUENCED
|
||||
must come before the return type, and more precisely:
|
||||
- In a function declaration/definition without a storage-class
|
||||
specifier: at the beginning of the declaration/definition.
|
||||
- In a function declaration/definition with a storage-class
|
||||
specifier:
|
||||
- In C: before the storage-class specifier.
|
||||
- In C++: between the storage-class specifier and the return type.
|
||||
|
||||
* The other macros can be placed
|
||||
- Either
|
||||
- In a function declaration/definition without a storage-class
|
||||
specifier: at the beginning of the declaration/definition.
|
||||
- In a function declaration/definition with a storage-class
|
||||
specifier: between the storage-class specifier and the return
|
||||
type.
|
||||
- Or after the parameter list,
|
||||
∙ but after ATTRIBUTE_NOTHROW if present.
|
||||
|
||||
In other declarations, such as variable declarations:
|
||||
|
||||
* Either
|
||||
- In C: before the storage-class specifier.
|
||||
- In C++: between the storage-class specifier and the return type.
|
||||
Then they apply to all entities that are declared by the declaration.
|
||||
|
||||
* Or immediately after the name of an entity being declared by the
|
||||
declaration. Then they apply to that entity only.
|
||||
*/
|
||||
|
||||
#ifndef _GL_ATTRIBUTE_H
|
||||
#define _GL_ATTRIBUTE_H
|
||||
|
||||
|
||||
/* This file defines two types of attributes:
|
||||
* C23 standard attributes. These have macro names that do not begin with
|
||||
'ATTRIBUTE_'.
|
||||
* Selected GCC attributes; see:
|
||||
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
|
||||
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
|
||||
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html
|
||||
These names begin with 'ATTRIBUTE_' to avoid name clashes. */
|
||||
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_ALLOC_SIZE, _GL_ATTRIBUTE_ALWAYS_INLINE,
|
||||
_GL_ATTRIBUTE_ARTIFICIAL, _GL_ATTRIBUTE_COLD, _GL_ATTRIBUTE_CONST,
|
||||
_GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_DEPRECATED, _GL_ATTRIBUTE_ERROR,
|
||||
_GL_ATTRIBUTE_WARNING, _GL_ATTRIBUTE_EXTERNALLY_VISIBLE,
|
||||
_GL_ATTRIBUTE_FALLTHROUGH, _GL_ATTRIBUTE_FORMAT, _GL_ATTRIBUTE_LEAF,
|
||||
_GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_MAY_ALIAS, _GL_ATTRIBUTE_MAYBE_UNUSED,
|
||||
_GL_ATTRIBUTE_NODISCARD, _GL_ATTRIBUTE_NOINLINE, _GL_ATTRIBUTE_NONNULL,
|
||||
_GL_ATTRIBUTE_NONSTRING, _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PACKED,
|
||||
_GL_ATTRIBUTE_PURE, _GL_ATTRIBUTE_REPRODUCIBLE,
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL, _GL_ATTRIBUTE_SENTINEL,
|
||||
_GL_ATTRIBUTE_UNSEQUENCED. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
|
||||
/* =============== Attributes for specific kinds of functions =============== */
|
||||
|
||||
/* Attributes for functions that should not be used. */
|
||||
|
||||
/* Warn if the entity is used. */
|
||||
/* Applies to:
|
||||
- function, variable,
|
||||
- struct, union, struct/union member,
|
||||
- enumeration, enumeration item,
|
||||
- typedef,
|
||||
in C++ also: namespace, class, template specialization. */
|
||||
#define DEPRECATED _GL_ATTRIBUTE_DEPRECATED
|
||||
|
||||
/* If a function call is not optimized way, warn with MSG. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_WARNING(msg) _GL_ATTRIBUTE_WARNING (msg)
|
||||
|
||||
/* If a function call is not optimized way, report an error with MSG. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_ERROR(msg) _GL_ATTRIBUTE_ERROR (msg)
|
||||
|
||||
|
||||
/* Attributes for memory-allocating functions. */
|
||||
|
||||
/* The function returns a pointer to freshly allocated memory. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_MALLOC _GL_ATTRIBUTE_MALLOC
|
||||
|
||||
/* ATTRIBUTE_ALLOC_SIZE ((N)) - The Nth argument of the function
|
||||
is the size of the returned memory block.
|
||||
ATTRIBUTE_ALLOC_SIZE ((M, N)) - Multiply the Mth and Nth arguments
|
||||
to determine the size of the returned memory block. */
|
||||
/* Applies to: functions, pointer to functions, function types. */
|
||||
#define ATTRIBUTE_ALLOC_SIZE(args) _GL_ATTRIBUTE_ALLOC_SIZE (args)
|
||||
|
||||
/* ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
|
||||
that can be freed by passing them as the Ith argument to the
|
||||
function F.
|
||||
ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
|
||||
can be freed via 'free'; it can be used only after declaring 'free'. */
|
||||
/* Applies to: functions. Cannot be used on inline functions. */
|
||||
#define ATTRIBUTE_DEALLOC(f, i) _GL_ATTRIBUTE_DEALLOC(f, i)
|
||||
#define ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC_FREE
|
||||
|
||||
/* Attributes for variadic functions. */
|
||||
|
||||
/* The variadic function expects a trailing NULL argument.
|
||||
ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
|
||||
ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_SENTINEL(pos) _GL_ATTRIBUTE_SENTINEL (pos)
|
||||
|
||||
|
||||
/* ================== Attributes for compiler diagnostics ================== */
|
||||
|
||||
/* Attributes that help the compiler diagnose programmer mistakes.
|
||||
Some of them may also help for some compiler optimizations. */
|
||||
|
||||
/* ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)) -
|
||||
The STRING-INDEXth function argument is a format string of style
|
||||
ARCHETYPE, which is one of:
|
||||
printf, gnu_printf
|
||||
scanf, gnu_scanf,
|
||||
strftime, gnu_strftime,
|
||||
strfmon,
|
||||
or the same thing prefixed and suffixed with '__'.
|
||||
If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
|
||||
are suitable for the format string. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_FORMAT(spec) _GL_ATTRIBUTE_FORMAT (spec)
|
||||
|
||||
/* ATTRIBUTE_NONNULL ((N1, N2,...)) - Arguments N1, N2,... must not be NULL.
|
||||
ATTRIBUTE_NONNULL () - All pointer arguments must not be null. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_NONNULL(args) _GL_ATTRIBUTE_NONNULL (args)
|
||||
|
||||
/* The function's return value is a non-NULL pointer. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_RETURNS_NONNULL _GL_ATTRIBUTE_RETURNS_NONNULL
|
||||
|
||||
/* Warn if the caller does not use the return value,
|
||||
unless the caller uses something like ignore_value. */
|
||||
/* Applies to: function, enumeration, class. */
|
||||
#define NODISCARD _GL_ATTRIBUTE_NODISCARD
|
||||
|
||||
|
||||
/* Attributes that disable false alarms when the compiler diagnoses
|
||||
programmer "mistakes". */
|
||||
|
||||
/* Do not warn if the entity is not used. */
|
||||
/* Applies to:
|
||||
- function, variable,
|
||||
- struct, union, struct/union member,
|
||||
- enumeration, enumeration item,
|
||||
- typedef,
|
||||
in C++ also: class. */
|
||||
#define MAYBE_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
|
||||
|
||||
/* The contents of a character array is not meant to be NUL-terminated. */
|
||||
/* Applies to: struct/union members and variables that are arrays of element
|
||||
type '[[un]signed] char'. */
|
||||
#define ATTRIBUTE_NONSTRING _GL_ATTRIBUTE_NONSTRING
|
||||
|
||||
/* Do not warn if control flow falls through to the immediately
|
||||
following 'case' or 'default' label. */
|
||||
/* Applies to: Empty statement (;), inside a 'switch' statement. */
|
||||
#define FALLTHROUGH _GL_ATTRIBUTE_FALLTHROUGH
|
||||
|
||||
|
||||
/* ================== Attributes for debugging information ================== */
|
||||
|
||||
/* Attributes regarding debugging information emitted by the compiler. */
|
||||
|
||||
/* Omit the function from stack traces when debugging. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_ARTIFICIAL _GL_ATTRIBUTE_ARTIFICIAL
|
||||
|
||||
/* Make the entity visible to debuggers etc., even with '-fwhole-program'. */
|
||||
/* Applies to: functions, variables. */
|
||||
#define ATTRIBUTE_EXTERNALLY_VISIBLE _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
|
||||
|
||||
|
||||
/* ========== Attributes that mainly direct compiler optimizations ========== */
|
||||
|
||||
/* The function does not throw exceptions. */
|
||||
/* Applies to: functions. */
|
||||
/* After a function's parameter list, this attribute must come first, before
|
||||
other attributes. */
|
||||
#define ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_NOTHROW
|
||||
|
||||
/* Do not inline the function. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_NOINLINE _GL_ATTRIBUTE_NOINLINE
|
||||
|
||||
/* Always inline the function, and report an error if the compiler
|
||||
cannot inline. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE
|
||||
|
||||
/* It is OK for a compiler to move calls to the function and to omit
|
||||
calls to the function if another call has the same arguments or the
|
||||
result is not used.
|
||||
This attribute is safe for a function that neither depends on
|
||||
nor affects state, and always returns exactly once -
|
||||
e.g., does not raise an exception, call longjmp, or loop forever.
|
||||
(This attribute is stricter than ATTRIBUTE_PURE because the
|
||||
function cannot observe state. It is stricter than UNSEQUENCED
|
||||
because the function must return exactly once and cannot depend on
|
||||
state addressed by its arguments.) */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
|
||||
|
||||
/* It is OK for a compiler to move calls to the function and to omit duplicate
|
||||
calls to the function with the same arguments, so long as the state
|
||||
addressed by its arguments is the same.
|
||||
This attribute is safe for a function that is effectless, idempotent,
|
||||
stateless, and independent; see ISO C 23 § 6.7.12.7 for a definition of
|
||||
these terms.
|
||||
(This attribute is stricter than REPRODUCIBLE because the function
|
||||
must be stateless and independent. It is looser than ATTRIBUTE_CONST
|
||||
because the function need not return exactly once and can depend
|
||||
on state addressed by its arguments.)
|
||||
See also <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and
|
||||
<https://stackoverflow.com/questions/76847905/>. */
|
||||
/* Applies to: functions, pointer to functions, function type. */
|
||||
#define UNSEQUENCED _GL_ATTRIBUTE_UNSEQUENCED
|
||||
|
||||
/* It is OK for a compiler to move calls to the function and to omit
|
||||
calls to the function if another call has the same arguments or the
|
||||
result is not used, and if observable state is the same.
|
||||
This attribute is safe for a function that does not affect observable state
|
||||
and always returns exactly once.
|
||||
(This attribute is looser than ATTRIBUTE_CONST because the function
|
||||
can depend on observable state. It is stricter than REPRODUCIBLE
|
||||
because the function must return exactly once and cannot affect
|
||||
state addressed by its arguments.) */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE
|
||||
|
||||
/* It is OK for a compiler to move calls to the function and to omit duplicate
|
||||
calls to the function with the same arguments, so long as the state
|
||||
addressed by its arguments is the same and is updated in time for
|
||||
the rest of the program.
|
||||
This attribute is safe for a function that is effectless and idempotent; see
|
||||
ISO C 23 § 6.7.12.7 for a definition of these terms.
|
||||
(This attribute is looser than UNSEQUENCED because the function need
|
||||
not be stateless and idempotent. It is looser than ATTRIBUTE_PURE
|
||||
because the function need not return exactly once and can affect
|
||||
state addressed by its arguments.)
|
||||
See also <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and
|
||||
<https://stackoverflow.com/questions/76847905/>. */
|
||||
/* Applies to: functions, pointer to functions, function type. */
|
||||
#define REPRODUCIBLE _GL_ATTRIBUTE_REPRODUCIBLE
|
||||
|
||||
/* The function is rarely executed. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_COLD _GL_ATTRIBUTE_COLD
|
||||
|
||||
/* If called from some other compilation unit, the function executes
|
||||
code from that unit only by return or by exception handling,
|
||||
letting the compiler optimize that unit more aggressively. */
|
||||
/* Applies to: functions. */
|
||||
#define ATTRIBUTE_LEAF _GL_ATTRIBUTE_LEAF
|
||||
|
||||
/* For struct members: The member has the smallest possible alignment.
|
||||
For struct, union, class: All members have the smallest possible alignment,
|
||||
minimizing the memory required. */
|
||||
/* Applies to: struct members, struct, union,
|
||||
in C++ also: class. */
|
||||
#define ATTRIBUTE_PACKED _GL_ATTRIBUTE_PACKED
|
||||
|
||||
|
||||
/* ================ Attributes that make invalid code valid ================ */
|
||||
|
||||
/* Attributes that prevent fatal compiler optimizations for code that is not
|
||||
fully ISO C compliant. */
|
||||
|
||||
/* Pointers to the type may point to the same storage as pointers to
|
||||
other types, thus disabling strict aliasing optimization. */
|
||||
/* Applies to: types. */
|
||||
#define ATTRIBUTE_MAY_ALIAS _GL_ATTRIBUTE_MAY_ALIAS
|
||||
|
||||
|
||||
#endif /* _GL_ATTRIBUTE_H */
|
||||
@@ -1,22 +0,0 @@
|
||||
/* Backup files.
|
||||
|
||||
Copyright (C) 2017-2024 Free Software Foundation, Inc.
|
||||
|
||||
This file 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 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 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/>. */
|
||||
|
||||
#include "backupfile.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
extern char *backupfile_internal (int, char const *, enum backup_type, bool)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
@@ -1,73 +0,0 @@
|
||||
/* backupfile.h -- declarations for making Emacs style backup file names
|
||||
|
||||
Copyright (C) 1990-1992, 1997-1999, 2003-2004, 2009-2024 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/>. */
|
||||
|
||||
#ifndef BACKUPFILE_H_
|
||||
#define BACKUPFILE_H_
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_RETURNS_NONNULL. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
/* Get AT_FDCWD, as a convenience for users of this file. */
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* When to make backup files. */
|
||||
enum backup_type
|
||||
{
|
||||
/* Never make backups. */
|
||||
no_backups,
|
||||
|
||||
/* Make simple backups of every file. */
|
||||
simple_backups,
|
||||
|
||||
/* Make numbered backups of files that already have numbered backups,
|
||||
and simple backups of the others. */
|
||||
numbered_existing_backups,
|
||||
|
||||
/* Make numbered backups of every file. */
|
||||
numbered_backups
|
||||
};
|
||||
|
||||
#define VALID_BACKUP_TYPE(Type) \
|
||||
((unsigned int) (Type) <= numbered_backups)
|
||||
|
||||
extern char const *simple_backup_suffix;
|
||||
|
||||
void set_simple_backup_suffix (char const *);
|
||||
char *backup_file_rename (int, char const *, enum backup_type)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
char *find_backup_file_name (int, char const *, enum backup_type)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL;
|
||||
enum backup_type get_version (char const *context, char const *arg);
|
||||
enum backup_type xget_version (char const *context, char const *arg);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ! BACKUPFILE_H_ */
|
||||
@@ -1,99 +0,0 @@
|
||||
/* base32.h -- Encode binary data using printable characters.
|
||||
Copyright (C) 2004-2006, 2009-2024 Free Software Foundation, Inc.
|
||||
Adapted from Simon Josefsson's base64 code by Gijs van Tulder.
|
||||
|
||||
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 BASE32_H
|
||||
#define BASE32_H
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
/* Get idx_t. */
|
||||
#include <idx.h>
|
||||
|
||||
/* Pacify GCC in isubase32. */
|
||||
#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__) && !defined __clang__
|
||||
# pragma GCC diagnostic ignored "-Wtype-limits"
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef BASE32_INLINE
|
||||
# define BASE32_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This uses that the expression (n+(k-1))/k means the smallest
|
||||
integer >= n/k, i.e., the ceiling of n/k. */
|
||||
#define BASE32_LENGTH(inlen) ((((inlen) + 4) / 5) * 8)
|
||||
|
||||
struct base32_decode_context
|
||||
{
|
||||
int i;
|
||||
char buf[8];
|
||||
};
|
||||
|
||||
extern signed char const base32_to_int[256];
|
||||
|
||||
BASE32_INLINE bool
|
||||
isubase32 (unsigned char ch)
|
||||
{
|
||||
return ch < sizeof base32_to_int && 0 <= base32_to_int[ch];
|
||||
}
|
||||
|
||||
BASE32_INLINE bool
|
||||
isbase32 (char ch)
|
||||
{
|
||||
return isubase32 (ch);
|
||||
}
|
||||
|
||||
extern void base32_encode (const char *restrict in, idx_t inlen,
|
||||
char *restrict out, idx_t outlen);
|
||||
|
||||
extern idx_t base32_encode_alloc (const char *in, idx_t inlen, char **out);
|
||||
|
||||
/* Initialize decode-context buffer, CTX. */
|
||||
BASE32_INLINE void
|
||||
base32_decode_ctx_init (struct base32_decode_context *ctx)
|
||||
{
|
||||
ctx->i = 0;
|
||||
}
|
||||
|
||||
extern bool base32_decode_ctx (struct base32_decode_context *ctx,
|
||||
const char *restrict in, idx_t inlen,
|
||||
char *restrict out, idx_t *outlen);
|
||||
|
||||
extern bool base32_decode_alloc_ctx (struct base32_decode_context *ctx,
|
||||
const char *in, idx_t inlen,
|
||||
char **out, idx_t *outlen);
|
||||
|
||||
#define base32_decode(in, inlen, out, outlen) \
|
||||
base32_decode_ctx (NULL, in, inlen, out, outlen)
|
||||
|
||||
#define base32_decode_alloc(in, inlen, out, outlen) \
|
||||
base32_decode_alloc_ctx (NULL, in, inlen, out, outlen)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif /* BASE32_H */
|
||||
@@ -1,99 +0,0 @@
|
||||
/* base64.h -- Encode binary data using printable characters.
|
||||
Copyright (C) 2004-2006, 2009-2024 Free Software Foundation, Inc.
|
||||
Written by Simon Josefsson.
|
||||
|
||||
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 BASE64_H
|
||||
#define BASE64_H
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
/* Get idx_t. */
|
||||
#include <idx.h>
|
||||
|
||||
/* Pacify GCC in isubase64. */
|
||||
#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__) && !defined __clang__
|
||||
# pragma GCC diagnostic ignored "-Wtype-limits"
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef BASE64_INLINE
|
||||
# define BASE64_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This uses that the expression (n+(k-1))/k means the smallest
|
||||
integer >= n/k, i.e., the ceiling of n/k. */
|
||||
#define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
|
||||
|
||||
struct base64_decode_context
|
||||
{
|
||||
int i;
|
||||
char buf[4];
|
||||
};
|
||||
|
||||
extern signed char const base64_to_int[256];
|
||||
|
||||
BASE64_INLINE bool
|
||||
isubase64 (unsigned char ch)
|
||||
{
|
||||
return ch < sizeof base64_to_int && 0 <= base64_to_int[ch];
|
||||
}
|
||||
|
||||
BASE64_INLINE bool
|
||||
isbase64 (char ch)
|
||||
{
|
||||
return isubase64 (ch);
|
||||
}
|
||||
|
||||
extern void base64_encode (const char *restrict in, idx_t inlen,
|
||||
char *restrict out, idx_t outlen);
|
||||
|
||||
extern idx_t base64_encode_alloc (const char *in, idx_t inlen, char **out);
|
||||
|
||||
/* Initialize decode-context buffer, CTX. */
|
||||
BASE64_INLINE void
|
||||
base64_decode_ctx_init (struct base64_decode_context *ctx)
|
||||
{
|
||||
ctx->i = 0;
|
||||
}
|
||||
|
||||
extern bool base64_decode_ctx (struct base64_decode_context *ctx,
|
||||
const char *restrict in, idx_t inlen,
|
||||
char *restrict out, idx_t *outlen);
|
||||
|
||||
extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx,
|
||||
const char *in, idx_t inlen,
|
||||
char **out, idx_t *outlen);
|
||||
|
||||
#define base64_decode(in, inlen, out, outlen) \
|
||||
base64_decode_ctx (NULL, in, inlen, out, outlen)
|
||||
|
||||
#define base64_decode_alloc(in, inlen, out, outlen) \
|
||||
base64_decode_alloc_ctx (NULL, in, inlen, out, outlen)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif /* BASE64_H */
|
||||
@@ -1,83 +0,0 @@
|
||||
/* Extract the last component (base name) of a file name.
|
||||
|
||||
Copyright (C) 1998, 2001, 2003-2006, 2009-2024 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
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_PURE. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#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,75 +0,0 @@
|
||||
/* Support for locale names in BCP 47 syntax.
|
||||
Copyright (C) 2024 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 3 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>, 2024. */
|
||||
|
||||
#ifndef _BCP47_H
|
||||
#define _BCP47_H
|
||||
|
||||
/* A locale name can exist in three possible forms:
|
||||
|
||||
* The XPG syntax
|
||||
language[_territory][.codeset][@modifier]
|
||||
where
|
||||
- The language is an ISO 639 (two-letter) language code.
|
||||
- The territory is an ISO 3166 (two-letter) country code.
|
||||
- The codeset is typically UTF-8.
|
||||
- The supported @modifiers are usually something like
|
||||
@euro
|
||||
a script indicator, such as: @latin, @cyrillic, @devanagari
|
||||
|
||||
* The locale name understood by setlocale().
|
||||
On glibc and many other Unix-like systems, this is the XPG syntax.
|
||||
On native Windows, it is similar to XPG syntax, with English names
|
||||
(instead of ISO codes) for the language and territory and with a
|
||||
number for the codeset (e.g. 65001 for UTF-8).
|
||||
|
||||
* The BCP 47 syntax
|
||||
language[-script][-region]{-variant}*{-extension}*
|
||||
defined in
|
||||
<https://www.ietf.org/rfc/bcp/bcp47.html>
|
||||
= <https://www.rfc-editor.org/rfc/bcp/bcp47.txt>
|
||||
which consists of RFC 5646 and RFC 4647.
|
||||
See also <https://en.wikipedia.org/wiki/IETF_language_tag>.
|
||||
Note: The BCP 47 syntax does not include a codeset.
|
||||
|
||||
This file provides conversions between the XPG syntax and the BCP 47
|
||||
syntax. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Required size of buffer for a locale name. */
|
||||
#define BCP47_MAX 100
|
||||
|
||||
/* Converts a locale name in XPG syntax to a locale name in BCP 47 syntax.
|
||||
Returns the result in bcp47, which must be at least BCP47_MAX bytes
|
||||
large. */
|
||||
extern void xpg_to_bcp47 (char *bcp47, const char *xpg);
|
||||
|
||||
/* Converts a locale name in BCP 47 syntax (optionally with a codeset)
|
||||
to a locale name in XPG syntax.
|
||||
The specified codeset may be NULL.
|
||||
Returns the result in xpg, which must be at least BCP47_MAX bytes
|
||||
large. */
|
||||
extern void bcp47_to_xpg (char *xpg, const char *bcp47, const char *codeset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BCP47_H */
|
||||
@@ -1,89 +0,0 @@
|
||||
/* Binary mode I/O.
|
||||
Copyright (C) 2001, 2003, 2005, 2008-2024 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
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_UNUSED. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
/* 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>
|
||||
|
||||
_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
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#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))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif /* _BINARY_H */
|
||||
@@ -1,150 +0,0 @@
|
||||
/* bitrotate.h - Rotate bits in integers
|
||||
Copyright (C) 2008-2024 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 Simon Josefsson <simon@josefsson.org>, 2008. */
|
||||
|
||||
#ifndef _GL_BITROTATE_H
|
||||
#define _GL_BITROTATE_H
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef BITROTATE_INLINE
|
||||
# define BITROTATE_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef UINT64_MAX
|
||||
/* Given an unsigned 64-bit argument X, return the value corresponding
|
||||
to rotating the bits N steps to the left. N must be between 1 and
|
||||
63 inclusive. */
|
||||
BITROTATE_INLINE uint64_t
|
||||
rotl64 (uint64_t x, int n)
|
||||
{
|
||||
return ((x << n) | (x >> (64 - n))) & UINT64_MAX;
|
||||
}
|
||||
|
||||
/* Given an unsigned 64-bit argument X, return the value corresponding
|
||||
to rotating the bits N steps to the right. N must be between 1 to
|
||||
63 inclusive.*/
|
||||
BITROTATE_INLINE uint64_t
|
||||
rotr64 (uint64_t x, int n)
|
||||
{
|
||||
return ((x >> n) | (x << (64 - n))) & UINT64_MAX;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Given an unsigned 32-bit argument X, return the value corresponding
|
||||
to rotating the bits N steps to the left. N must be between 1 and
|
||||
31 inclusive. */
|
||||
BITROTATE_INLINE uint32_t
|
||||
rotl32 (uint32_t x, int n)
|
||||
{
|
||||
return ((x << n) | (x >> (32 - n))) & UINT32_MAX;
|
||||
}
|
||||
|
||||
/* Given an unsigned 32-bit argument X, return the value corresponding
|
||||
to rotating the bits N steps to the right. N must be between 1 to
|
||||
31 inclusive.*/
|
||||
BITROTATE_INLINE uint32_t
|
||||
rotr32 (uint32_t x, int n)
|
||||
{
|
||||
return ((x >> n) | (x << (32 - n))) & UINT32_MAX;
|
||||
}
|
||||
|
||||
/* Given a size_t argument X, return the value corresponding
|
||||
to rotating the bits N steps to the left. N must be between 1 and
|
||||
(CHAR_BIT * sizeof (size_t) - 1) inclusive. */
|
||||
BITROTATE_INLINE size_t
|
||||
rotl_sz (size_t x, int n)
|
||||
{
|
||||
return ((x << n) | (x >> ((CHAR_BIT * sizeof x) - n))) & SIZE_MAX;
|
||||
}
|
||||
|
||||
/* Given a size_t argument X, return the value corresponding
|
||||
to rotating the bits N steps to the right. N must be between 1 to
|
||||
(CHAR_BIT * sizeof (size_t) - 1) inclusive. */
|
||||
BITROTATE_INLINE size_t
|
||||
rotr_sz (size_t x, int n)
|
||||
{
|
||||
return ((x >> n) | (x << ((CHAR_BIT * sizeof x) - n))) & SIZE_MAX;
|
||||
}
|
||||
|
||||
/* Given an unsigned 16-bit argument X, return the value corresponding
|
||||
to rotating the bits N steps to the left. N must be between 1 to
|
||||
15 inclusive, but on most relevant targets N can also be 0 and 16
|
||||
because 'int' is at least 32 bits and the arguments must widen
|
||||
before shifting. */
|
||||
BITROTATE_INLINE uint16_t
|
||||
rotl16 (uint16_t x, int n)
|
||||
{
|
||||
return (((unsigned int) x << n) | ((unsigned int) x >> (16 - n)))
|
||||
& UINT16_MAX;
|
||||
}
|
||||
|
||||
/* Given an unsigned 16-bit argument X, return the value corresponding
|
||||
to rotating the bits N steps to the right. N must be in 1 to 15
|
||||
inclusive, but on most relevant targets N can also be 0 and 16
|
||||
because 'int' is at least 32 bits and the arguments must widen
|
||||
before shifting. */
|
||||
BITROTATE_INLINE uint16_t
|
||||
rotr16 (uint16_t x, int n)
|
||||
{
|
||||
return (((unsigned int) x >> n) | ((unsigned int) x << (16 - n)))
|
||||
& UINT16_MAX;
|
||||
}
|
||||
|
||||
/* Given an unsigned 8-bit argument X, return the value corresponding
|
||||
to rotating the bits N steps to the left. N must be between 1 to 7
|
||||
inclusive, but on most relevant targets N can also be 0 and 8
|
||||
because 'int' is at least 32 bits and the arguments must widen
|
||||
before shifting. */
|
||||
BITROTATE_INLINE uint8_t
|
||||
rotl8 (uint8_t x, int n)
|
||||
{
|
||||
return (((unsigned int) x << n) | ((unsigned int) x >> (8 - n))) & UINT8_MAX;
|
||||
}
|
||||
|
||||
/* Given an unsigned 8-bit argument X, return the value corresponding
|
||||
to rotating the bits N steps to the right. N must be in 1 to 7
|
||||
inclusive, but on most relevant targets N can also be 0 and 8
|
||||
because 'int' is at least 32 bits and the arguments must widen
|
||||
before shifting. */
|
||||
BITROTATE_INLINE uint8_t
|
||||
rotr8 (uint8_t x, int n)
|
||||
{
|
||||
return (((unsigned int) x >> n) | ((unsigned int) x << (8 - n))) & UINT8_MAX;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif /* _GL_BITROTATE_H */
|
||||
@@ -1,411 +0,0 @@
|
||||
/* Generic bitsets.
|
||||
|
||||
Copyright (C) 2002-2004, 2009-2015, 2018-2024 Free Software Foundation, Inc.
|
||||
|
||||
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
|
||||
|
||||
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 _GL_BITSET_H
|
||||
#define _GL_BITSET_H
|
||||
|
||||
/* This file is the public interface to the bitset abstract data type.
|
||||
Only use the functions and macros defined in this file. */
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_DEALLOC. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#if USE_UNLOCKED_IO
|
||||
# include "unlocked-io.h"
|
||||
#endif
|
||||
|
||||
#include "bitset/base.h"
|
||||
#include "obstack.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Attributes used to select a bitset implementation. */
|
||||
enum bitset_attr {BITSET_FIXED = 1, /* Bitset size fixed. */
|
||||
BITSET_VARIABLE = 2, /* Bitset size variable. */
|
||||
BITSET_DENSE = 4, /* Bitset dense. */
|
||||
BITSET_SPARSE = 8, /* Bitset sparse. */
|
||||
BITSET_FRUGAL = 16, /* Prefer most compact. */
|
||||
BITSET_GREEDY = 32}; /* Prefer fastest at memory expense. */
|
||||
|
||||
typedef unsigned bitset_attrs;
|
||||
|
||||
/* The contents of the union should be considered to be private.
|
||||
While I would like to make this union opaque, it needs to be
|
||||
visible for the inline bit set/test functions, and for delegation
|
||||
to the proper implementation. */
|
||||
union bitset_union
|
||||
{
|
||||
/* This must be the first member of every other structure that is a
|
||||
member of this union. */
|
||||
struct bbitset_struct b; /* Base bitset data. */
|
||||
|
||||
struct abitset_struct
|
||||
{
|
||||
struct bbitset_struct b;
|
||||
bitset_word words[1]; /* The array of bits. */
|
||||
} a;
|
||||
|
||||
struct tbitset_struct
|
||||
{
|
||||
struct bbitset_struct b;
|
||||
bitset_windex size; /* Number of elements. */
|
||||
struct tbitset_elt_struct **elts; /* Expanding array of ptrs to elts. */
|
||||
} e;
|
||||
|
||||
struct lbitset_struct
|
||||
{
|
||||
struct bbitset_struct b;
|
||||
struct lbitset_elt_struct *head; /* First element in linked list. */
|
||||
struct lbitset_elt_struct *tail; /* Last element in linked list. */
|
||||
} l;
|
||||
|
||||
struct bitset_stats_struct
|
||||
{
|
||||
struct bbitset_struct b;
|
||||
bitset bset;
|
||||
} s;
|
||||
|
||||
struct vbitset_struct
|
||||
{
|
||||
struct bbitset_struct b;
|
||||
bitset_windex size; /* Allocated size of array. */
|
||||
} v;
|
||||
};
|
||||
|
||||
|
||||
/* The contents of this structure should be considered private.
|
||||
It is used for iterating over set bits. */
|
||||
typedef struct
|
||||
{
|
||||
bitset_bindex list[BITSET_LIST_SIZE];
|
||||
bitset_bindex next;
|
||||
bitset_bindex num;
|
||||
bitset_bindex i;
|
||||
} bitset_iterator;
|
||||
|
||||
|
||||
/* Free bitset. Do nothing if NULL. */
|
||||
void bitset_free (bitset);
|
||||
|
||||
/* Return bytes required for bitset of desired type and size. */
|
||||
size_t bitset_bytes (enum bitset_type, bitset_bindex);
|
||||
|
||||
/* Initialise a bitset with desired type and size. */
|
||||
bitset bitset_init (bitset, bitset_bindex, enum bitset_type);
|
||||
|
||||
/* Select an implementation type based on the desired bitset size
|
||||
and attributes. */
|
||||
enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs);
|
||||
|
||||
/* Create a bitset of desired type and size. The bitset is zeroed. */
|
||||
bitset bitset_alloc (bitset_bindex, enum bitset_type)
|
||||
_GL_ATTRIBUTE_DEALLOC (bitset_free, 1);
|
||||
|
||||
/* Free bitset allocated on obstack. Do nothing if NULL. */
|
||||
void bitset_obstack_free (bitset);
|
||||
|
||||
/* Create a bitset of desired type and size using an obstack. The
|
||||
bitset is zeroed. */
|
||||
bitset bitset_obstack_alloc (struct obstack *bobstack,
|
||||
bitset_bindex, enum bitset_type)
|
||||
_GL_ATTRIBUTE_DEALLOC (bitset_obstack_free, 1);
|
||||
|
||||
/* Create a bitset of desired size and attributes. The bitset is zeroed. */
|
||||
bitset bitset_create (bitset_bindex, bitset_attrs)
|
||||
_GL_ATTRIBUTE_DEALLOC (bitset_free, 1);
|
||||
|
||||
/* Return bitset type. */
|
||||
enum bitset_type bitset_type_get (bitset);
|
||||
|
||||
/* Return bitset type name. */
|
||||
const char *bitset_type_name_get (bitset);
|
||||
|
||||
|
||||
/* Set bit BITNO in bitset BSET. */
|
||||
static inline void
|
||||
bitset_set (bitset bset, bitset_bindex bitno)
|
||||
{
|
||||
bitset_windex windex = bitno / BITSET_WORD_BITS;
|
||||
bitset_windex offset = windex - bset->b.cindex;
|
||||
|
||||
if (offset < bset->b.csize)
|
||||
bset->b.cdata[offset] |= ((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
|
||||
else
|
||||
BITSET_SET_ (bset, bitno);
|
||||
}
|
||||
|
||||
|
||||
/* Reset bit BITNO in bitset BSET. */
|
||||
static inline void
|
||||
bitset_reset (bitset bset, bitset_bindex bitno)
|
||||
{
|
||||
bitset_windex windex = bitno / BITSET_WORD_BITS;
|
||||
bitset_windex offset = windex - bset->b.cindex;
|
||||
|
||||
if (offset < bset->b.csize)
|
||||
bset->b.cdata[offset] &= ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
|
||||
else
|
||||
BITSET_RESET_ (bset, bitno);
|
||||
}
|
||||
|
||||
|
||||
/* Test bit BITNO in bitset BSET. */
|
||||
static inline bool
|
||||
bitset_test (bitset bset, bitset_bindex bitno)
|
||||
{
|
||||
bitset_windex windex = bitno / BITSET_WORD_BITS;
|
||||
bitset_windex offset = windex - bset->b.cindex;
|
||||
|
||||
if (offset < bset->b.csize)
|
||||
return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
|
||||
else
|
||||
return BITSET_TEST_ (bset, bitno);
|
||||
}
|
||||
|
||||
|
||||
/* Toggle bit BITNO in bitset BSET and return non-zero if now set. */
|
||||
#define bitset_toggle(bset, bitno) BITSET_TOGGLE_ (bset, bitno)
|
||||
|
||||
/* Return size in bits of bitset SRC. */
|
||||
#define bitset_size(SRC) BITSET_SIZE_ (SRC)
|
||||
|
||||
/* Change size in bits of bitset. New bits are zeroed. Return
|
||||
SIZE. */
|
||||
#define bitset_resize(DST, SIZE) BITSET_RESIZE_ (DST, SIZE)
|
||||
|
||||
/* Return number of bits set in bitset SRC. */
|
||||
#define bitset_count(SRC) BITSET_COUNT_ (SRC)
|
||||
|
||||
|
||||
/* Return SRC == 0. */
|
||||
#define bitset_empty_p(SRC) BITSET_EMPTY_P_ (SRC)
|
||||
|
||||
/* DST = ~0. */
|
||||
#define bitset_ones(DST) BITSET_ONES_ (DST)
|
||||
|
||||
/* DST = 0. */
|
||||
#define bitset_zero(DST) BITSET_ZERO_ (DST)
|
||||
|
||||
|
||||
|
||||
/* DST = SRC. */
|
||||
#define bitset_copy(DST, SRC) BITSET_COPY_ (DST, SRC)
|
||||
|
||||
/* Return DST & SRC == 0. */
|
||||
#define bitset_disjoint_p(DST, SRC) BITSET_DISJOINT_P_ (DST, SRC)
|
||||
|
||||
/* Return DST == SRC. */
|
||||
#define bitset_equal_p(DST, SRC) BITSET_EQUAL_P_ (DST, SRC)
|
||||
|
||||
/* DST = ~SRC. */
|
||||
#define bitset_not(DST, SRC) BITSET_NOT_ (DST, SRC)
|
||||
|
||||
/* Return DST == DST | SRC. */
|
||||
#define bitset_subset_p(DST, SRC) BITSET_SUBSET_P_ (DST, SRC)
|
||||
|
||||
|
||||
|
||||
/* DST = SRC1 & SRC2. */
|
||||
#define bitset_and(DST, SRC1, SRC2) BITSET_AND_ (DST, SRC1, SRC2)
|
||||
|
||||
/* DST = SRC1 & SRC2. Return non-zero if DST != SRC1 & SRC2. */
|
||||
#define bitset_and_cmp(DST, SRC1, SRC2) BITSET_AND_CMP_ (DST, SRC1, SRC2)
|
||||
|
||||
/* DST = SRC1 & ~SRC2. */
|
||||
#define bitset_andn(DST, SRC1, SRC2) BITSET_ANDN_ (DST, SRC1, SRC2)
|
||||
|
||||
/* DST = SRC1 & ~SRC2. Return non-zero if DST != SRC1 & ~SRC2. */
|
||||
#define bitset_andn_cmp(DST, SRC1, SRC2) BITSET_ANDN_CMP_ (DST, SRC1, SRC2)
|
||||
|
||||
/* DST = SRC1 | SRC2. */
|
||||
#define bitset_or(DST, SRC1, SRC2) BITSET_OR_ (DST, SRC1, SRC2)
|
||||
|
||||
/* DST = SRC1 | SRC2. Return non-zero if DST != SRC1 | SRC2. */
|
||||
#define bitset_or_cmp(DST, SRC1, SRC2) BITSET_OR_CMP_ (DST, SRC1, SRC2)
|
||||
|
||||
/* DST = SRC1 ^ SRC2. */
|
||||
#define bitset_xor(DST, SRC1, SRC2) BITSET_XOR_ (DST, SRC1, SRC2)
|
||||
|
||||
/* DST = SRC1 ^ SRC2. Return non-zero if DST != SRC1 ^ SRC2. */
|
||||
#define bitset_xor_cmp(DST, SRC1, SRC2) BITSET_XOR_CMP_ (DST, SRC1, SRC2)
|
||||
|
||||
|
||||
|
||||
/* DST = (SRC1 & SRC2) | SRC3. */
|
||||
#define bitset_and_or(DST, SRC1, SRC2, SRC3) \
|
||||
BITSET_AND_OR_ (DST, SRC1, SRC2, SRC3)
|
||||
|
||||
/* DST = (SRC1 & SRC2) | SRC3. Return non-zero if
|
||||
DST != (SRC1 & SRC2) | SRC3. */
|
||||
#define bitset_and_or_cmp(DST, SRC1, SRC2, SRC3) \
|
||||
BITSET_AND_OR_CMP_ (DST, SRC1, SRC2, SRC3)
|
||||
|
||||
/* DST = (SRC1 & ~SRC2) | SRC3. */
|
||||
#define bitset_andn_or(DST, SRC1, SRC2, SRC3) \
|
||||
BITSET_ANDN_OR_ (DST, SRC1, SRC2, SRC3)
|
||||
|
||||
/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
|
||||
DST != (SRC1 & ~SRC2) | SRC3. */
|
||||
#define bitset_andn_or_cmp(DST, SRC1, SRC2, SRC3) \
|
||||
BITSET_ANDN_OR_CMP_ (DST, SRC1, SRC2, SRC3)
|
||||
|
||||
/* DST = (SRC1 | SRC2) & SRC3. */
|
||||
#define bitset_or_and(DST, SRC1, SRC2, SRC3)\
|
||||
BITSET_OR_AND_ (DST, SRC1, SRC2, SRC3)
|
||||
|
||||
/* DST = (SRC1 | SRC2) & SRC3. Return non-zero if
|
||||
DST != (SRC1 | SRC2) & SRC3. */
|
||||
#define bitset_or_and_cmp(DST, SRC1, SRC2, SRC3)\
|
||||
BITSET_OR_AND_CMP_ (DST, SRC1, SRC2, SRC3)
|
||||
|
||||
/* Find list of up to NUM bits set in BSET starting from and including
|
||||
*NEXT. Return with actual number of bits found and with *NEXT
|
||||
indicating where search stopped. */
|
||||
#define bitset_list(BSET, LIST, NUM, NEXT) \
|
||||
BITSET_LIST_ (BSET, LIST, NUM, NEXT)
|
||||
|
||||
/* Find reverse list of up to NUM bits set in BSET starting from and
|
||||
including NEXT. Return with actual number of bits found and with
|
||||
*NEXT indicating where search stopped. */
|
||||
#define bitset_list_reverse(BSET, LIST, NUM, NEXT) \
|
||||
BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT)
|
||||
|
||||
/* Return true if both bitsets are of the same type and size. */
|
||||
bool bitset_compatible_p (bitset bset1, bitset bset2);
|
||||
|
||||
/* Find next bit set in SRC starting from and including BITNO.
|
||||
Return BITSET_BINDEX_MAX if SRC empty. */
|
||||
bitset_bindex bitset_next (bitset src, bitset_bindex bitno);
|
||||
|
||||
/* Find previous bit set in SRC starting from and including BITNO.
|
||||
Return BITSET_BINDEX_MAX if SRC empty. */
|
||||
bitset_bindex bitset_prev (bitset src, bitset_bindex bitno);
|
||||
|
||||
/* Find first set bit.
|
||||
Return BITSET_BINDEX_MAX if SRC empty. */
|
||||
bitset_bindex bitset_first (bitset src);
|
||||
|
||||
/* Find last set bit.
|
||||
Return BITSET_BINDEX_MAX if SRC empty. */
|
||||
bitset_bindex bitset_last (bitset src);
|
||||
|
||||
/* Return nonzero if this is the only set bit. */
|
||||
bool bitset_only_set_p (bitset, bitset_bindex);
|
||||
|
||||
/* Dump bitset. */
|
||||
void bitset_dump (FILE *, bitset);
|
||||
|
||||
/* Loop over all elements of BSET, starting with MIN, setting INDEX
|
||||
to the index of each set bit. For example, the following will print
|
||||
the bits set in a bitset:
|
||||
|
||||
bitset_bindex i;
|
||||
bitset_iterator iter;
|
||||
|
||||
BITSET_FOR_EACH (iter, src, i, 0)
|
||||
printf ("%lu ", (unsigned long) i);
|
||||
*/
|
||||
#define BITSET_FOR_EACH(ITER, BSET, INDEX, MIN) \
|
||||
for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
|
||||
(ITER.num == BITSET_LIST_SIZE) \
|
||||
&& (ITER.num = bitset_list (BSET, ITER.list, \
|
||||
BITSET_LIST_SIZE, &ITER.next));) \
|
||||
for (ITER.i = 0; \
|
||||
ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1); \
|
||||
ITER.i++)
|
||||
|
||||
|
||||
/* Loop over all elements of BSET, in reverse order starting with
|
||||
MIN, setting INDEX to the index of each set bit. For example, the
|
||||
following will print the bits set in a bitset in reverse order:
|
||||
|
||||
bitset_bindex i;
|
||||
bitset_iterator iter;
|
||||
|
||||
BITSET_FOR_EACH_REVERSE (iter, src, i, 0)
|
||||
printf ("%lu ", (unsigned long) i);
|
||||
*/
|
||||
#define BITSET_FOR_EACH_REVERSE(ITER, BSET, INDEX, MIN) \
|
||||
for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
|
||||
(ITER.num == BITSET_LIST_SIZE) \
|
||||
&& (ITER.num = bitset_list_reverse (BSET, ITER.list, \
|
||||
BITSET_LIST_SIZE, &ITER.next));) \
|
||||
for (ITER.i = 0; \
|
||||
ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1); \
|
||||
ITER.i++)
|
||||
|
||||
|
||||
/* Define set operations in terms of logical operations. */
|
||||
|
||||
#define bitset_diff(DST, SRC1, SRC2) bitset_andn (DST, SRC1, SRC2)
|
||||
#define bitset_diff_cmp(DST, SRC1, SRC2) bitset_andn_cmp (DST, SRC1, SRC2)
|
||||
|
||||
#define bitset_intersection(DST, SRC1, SRC2) bitset_and (DST, SRC1, SRC2)
|
||||
#define bitset_intersection_cmp(DST, SRC1, SRC2) bitset_and_cmp (DST, SRC1, SRC2)
|
||||
|
||||
#define bitset_union(DST, SRC1, SRC2) bitset_or (DST, SRC1, SRC2)
|
||||
#define bitset_union_cmp(DST, SRC1, SRC2) bitset_or_cmp (DST, SRC1, SRC2)
|
||||
|
||||
/* Symmetrical difference. */
|
||||
#define bitset_symdiff(DST, SRC1, SRC2) bitset_xor (DST, SRC1, SRC2)
|
||||
#define bitset_symdiff_cmp(DST, SRC1, SRC2) bitset_xor_cmp (DST, SRC1, SRC2)
|
||||
|
||||
/* Union of difference. */
|
||||
#define bitset_diff_union(DST, SRC1, SRC2, SRC3) \
|
||||
bitset_andn_or (DST, SRC1, SRC2, SRC3)
|
||||
#define bitset_diff_union_cmp(DST, SRC1, SRC2, SRC3) \
|
||||
bitset_andn_or_cmp (DST, SRC1, SRC2, SRC3)
|
||||
|
||||
|
||||
/* Release any memory tied up with bitsets. */
|
||||
void bitset_release_memory (void);
|
||||
|
||||
/* Enable bitset stats gathering. */
|
||||
void bitset_stats_enable (void);
|
||||
|
||||
/* Disable bitset stats gathering. */
|
||||
void bitset_stats_disable (void);
|
||||
|
||||
/* Read bitset stats file of accumulated stats. */
|
||||
void bitset_stats_read (const char *file_name);
|
||||
|
||||
/* Write bitset stats file of accumulated stats. */
|
||||
void bitset_stats_write (const char *file_name);
|
||||
|
||||
/* Dump bitset stats. */
|
||||
void bitset_stats_dump (FILE *);
|
||||
|
||||
/* Function to debug bitset from debugger. */
|
||||
void debug_bitset (bitset);
|
||||
|
||||
/* Function to debug bitset stats from debugger. */
|
||||
void debug_bitset_stats (void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _GL_BITSET_H */
|
||||
@@ -1,30 +0,0 @@
|
||||
/* Functions to support abitsets.
|
||||
|
||||
Copyright (C) 2002, 2004, 2009-2015, 2018-2024 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
|
||||
|
||||
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 _BITSET_ARRAY_H
|
||||
#define _BITSET_ARRAY_H
|
||||
|
||||
#include "bitset.h"
|
||||
|
||||
size_t abitset_bytes (bitset_bindex);
|
||||
|
||||
bitset abitset_init (bitset, bitset_bindex);
|
||||
|
||||
#endif
|
||||
@@ -1,336 +0,0 @@
|
||||
/* Base bitset stuff.
|
||||
|
||||
Copyright (C) 2002-2004, 2006, 2009-2015, 2018-2024 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
|
||||
|
||||
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 _BITSET_BASE_H
|
||||
#define _BITSET_BASE_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h> /* because Gnulib's <stdlib.h> may '#define free ...' */
|
||||
#include <string.h> /* ffsl */
|
||||
|
||||
#include "attribute.h"
|
||||
#include "integer_length.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
/* Currently we support five flavours of bitsets:
|
||||
BITSET_ARRAY: Array of bits (fixed size, fast for dense bitsets).
|
||||
Memory for bit array and bitset structure allocated
|
||||
contiguously.
|
||||
BITSET_LIST: Linked list of arrays of bits (variable size, least storage
|
||||
for large very sparse sets).
|
||||
BITSET_TABLE: Expandable table of pointers to arrays of bits
|
||||
(variable size, less storage for large sparse sets).
|
||||
Faster than BITSET_LIST for random access.
|
||||
BITSET_VECTOR: Variable array of bits (variable size, fast for
|
||||
dense bitsets).
|
||||
BITSET_STATS: Wrapper bitset for internal use only. Used for gathering
|
||||
statistics and/or better run-time checking.
|
||||
*/
|
||||
enum bitset_type {BITSET_ARRAY, BITSET_LIST, BITSET_TABLE, BITSET_VECTOR,
|
||||
BITSET_TYPE_NUM, BITSET_STATS};
|
||||
#define BITSET_TYPE_NAMES {"abitset", "lbitset", "tbitset", "vbitset"}
|
||||
|
||||
extern const char * const bitset_type_names[];
|
||||
|
||||
/* Data type used to store a word of bits. */
|
||||
typedef unsigned long bitset_word;
|
||||
#define BITSET_WORD_BITS ((unsigned) (CHAR_BIT * sizeof (bitset_word)))
|
||||
|
||||
/* Bit index. In theory we might need a type wider than size_t, but
|
||||
in practice we lose at most a factor of CHAR_BIT by going with
|
||||
size_t, and that is good enough. If this type is changed to be
|
||||
wider than size_t, the code needs to be modified to check for
|
||||
overflow when converting bit counts to byte or word counts.
|
||||
The bit and word index types must be unsigned. */
|
||||
typedef size_t bitset_bindex;
|
||||
|
||||
/* Word index. */
|
||||
typedef size_t bitset_windex;
|
||||
|
||||
/* Maximum values for commonly-used unsigned types. BITSET_SIZE_MAX
|
||||
always equals SIZE_MAX, but some older systems lack SIZE_MAX. */
|
||||
#define BITSET_BINDEX_MAX ((bitset_bindex) -1)
|
||||
|
||||
/* Limit max word index to the maximum value of a signed integer
|
||||
to simplify cache disabling. */
|
||||
#define BITSET_WINDEX_MAX (((bitset_windex) -1) >> 1)
|
||||
#define BITSET_SIZE_MAX ((size_t) -1)
|
||||
|
||||
#define BITSET_MSB ((bitset_word) 1 << (BITSET_WORD_BITS - 1))
|
||||
|
||||
#define BITSET_LIST_SIZE 1024
|
||||
|
||||
enum bitset_ops {BITSET_OP_ZERO, BITSET_OP_ONES,
|
||||
BITSET_OP_COPY, BITSET_OP_NOT,
|
||||
BITSET_OP_EMPTY_P, BITSET_OP_EQUAL_P,
|
||||
BITSET_OP_SUBSET_P, BITSET_OP_DISJOINT_P,
|
||||
BITSET_OP_AND, BITSET_OP_OR, BITSET_OP_XOR, BITSET_OP_ANDN,
|
||||
BITSET_OP_OR_AND, BITSET_OP_AND_OR, BITSET_OP_ANDN_OR};
|
||||
|
||||
struct bbitset_struct
|
||||
{
|
||||
const struct bitset_vtable *vtable;
|
||||
bitset_windex cindex; /* Cache word index. */
|
||||
bitset_windex csize; /* Cache size in words. */
|
||||
bitset_word *cdata; /* Cache data pointer. */
|
||||
bitset_bindex n_bits; /* Number of bits. */
|
||||
/* Perhaps we could sacrifice another word to indicate
|
||||
that the bitset is known to be zero, that a bit has been set
|
||||
in the cache, and that a bit has been cleared in the cache.
|
||||
This would speed up some of the searches but slightly slow down
|
||||
bit set/reset operations of cached bits. */
|
||||
};
|
||||
|
||||
|
||||
typedef union bitset_union *bitset;
|
||||
|
||||
|
||||
/* Private accessor macros to bitset structure. */
|
||||
#define BITSET_VTABLE_(SRC) (SRC)->b.vtable
|
||||
#define BITSET_CINDEX_(SRC) (SRC)->b.cindex
|
||||
#define BITSET_CDATA_(SRC) (SRC)->b.cdata
|
||||
#define BITSET_CSIZE_(SRC) (SRC)->b.csize
|
||||
#define BITSET_NBITS_(SRC) (SRC)->b.n_bits
|
||||
|
||||
|
||||
/* The contents of this structure should be considered private. */
|
||||
struct bitset_vtable
|
||||
{
|
||||
void (*set) (bitset, bitset_bindex);
|
||||
void (*reset) (bitset, bitset_bindex);
|
||||
bool (*toggle) (bitset, bitset_bindex);
|
||||
bool (*test) (bitset, bitset_bindex);
|
||||
bitset_bindex (*resize) (bitset, bitset_bindex);
|
||||
bitset_bindex (*size) (bitset);
|
||||
bitset_bindex (*count) (bitset);
|
||||
|
||||
bool (*empty_p) (bitset);
|
||||
void (*ones) (bitset);
|
||||
void (*zero) (bitset);
|
||||
|
||||
void (*copy) (bitset, bitset);
|
||||
bool (*disjoint_p) (bitset, bitset);
|
||||
bool (*equal_p) (bitset, bitset);
|
||||
void (*not_) (bitset, bitset);
|
||||
bool (*subset_p) (bitset, bitset);
|
||||
|
||||
void (*and_) (bitset, bitset, bitset);
|
||||
bool (*and_cmp) (bitset, bitset, bitset);
|
||||
void (*andn) (bitset, bitset, bitset);
|
||||
bool (*andn_cmp) (bitset, bitset, bitset);
|
||||
void (*or_) (bitset, bitset, bitset);
|
||||
bool (*or_cmp) (bitset, bitset, bitset);
|
||||
void (*xor_) (bitset, bitset, bitset);
|
||||
bool (*xor_cmp) (bitset, bitset, bitset);
|
||||
|
||||
void (*and_or) (bitset, bitset, bitset, bitset);
|
||||
bool (*and_or_cmp) (bitset, bitset, bitset, bitset);
|
||||
void (*andn_or) (bitset, bitset, bitset, bitset);
|
||||
bool (*andn_or_cmp) (bitset, bitset, bitset, bitset);
|
||||
void (*or_and) (bitset, bitset, bitset, bitset);
|
||||
bool (*or_and_cmp) (bitset, bitset, bitset, bitset);
|
||||
|
||||
bitset_bindex (*list) (bitset, bitset_bindex *, bitset_bindex,
|
||||
bitset_bindex *);
|
||||
bitset_bindex (*list_reverse) (bitset, bitset_bindex *, bitset_bindex,
|
||||
bitset_bindex *);
|
||||
void (*free) (bitset);
|
||||
enum bitset_type type;
|
||||
};
|
||||
|
||||
#define BITSET_COMPATIBLE_(BSET1, BSET2) \
|
||||
((BSET1)->b.vtable == (BSET2)->b.vtable)
|
||||
|
||||
#define BITSET_CHECK2_(DST, SRC) \
|
||||
if (!BITSET_COMPATIBLE_ (DST, SRC)) abort ();
|
||||
|
||||
#define BITSET_CHECK3_(DST, SRC1, SRC2) \
|
||||
if (!BITSET_COMPATIBLE_ (DST, SRC1) \
|
||||
|| !BITSET_COMPATIBLE_ (DST, SRC2)) abort ();
|
||||
|
||||
#define BITSET_CHECK4_(DST, SRC1, SRC2, SRC3) \
|
||||
if (!BITSET_COMPATIBLE_ (DST, SRC1) || !BITSET_COMPATIBLE_ (DST, SRC2) \
|
||||
|| !BITSET_COMPATIBLE_ (DST, SRC3)) abort ();
|
||||
|
||||
|
||||
/* Redefine number of bits in bitset DST. */
|
||||
#define BITSET_RESIZE_(DST, SIZE) (DST)->b.vtable->resize (DST, SIZE)
|
||||
|
||||
/* Return size in bits of bitset SRC. */
|
||||
#define BITSET_SIZE_(SRC) (SRC)->b.vtable->size (SRC)
|
||||
|
||||
/* Return number of bits set in bitset SRC. */
|
||||
#define BITSET_COUNT_(SRC) (SRC)->b.vtable->count (SRC)
|
||||
|
||||
/* Return type of bitset SRC. */
|
||||
#define BITSET_TYPE_(DST) (DST)->b.vtable->type
|
||||
|
||||
/* Set bit BITNO in bitset DST. */
|
||||
#define BITSET_SET_(DST, BITNO) (DST)->b.vtable->set (DST, BITNO)
|
||||
|
||||
/* Reset bit BITNO in bitset DST. */
|
||||
#define BITSET_RESET_(DST, BITNO) (DST)->b.vtable->reset (DST, BITNO)
|
||||
|
||||
/* Toggle bit BITNO in bitset DST. */
|
||||
#define BITSET_TOGGLE_(DST, BITNO) (DST)->b.vtable->toggle (DST, BITNO)
|
||||
|
||||
/* Return non-zero if bit BITNO in bitset SRC is set. */
|
||||
#define BITSET_TEST_(SRC, BITNO) (SRC)->b.vtable->test (SRC, BITNO)
|
||||
|
||||
/* Free bitset SRC. */
|
||||
#define BITSET_FREE_(SRC)\
|
||||
((SRC)->b.vtable->free ? (SRC)->b.vtable->free (SRC) :(void)0)
|
||||
|
||||
|
||||
/* Return SRC == 0. */
|
||||
#define BITSET_EMPTY_P_(SRC) (SRC)->b.vtable->empty_p (SRC)
|
||||
|
||||
/* DST = ~0. */
|
||||
#define BITSET_ONES_(DST) (DST)->b.vtable->ones (DST)
|
||||
|
||||
/* DST = 0. */
|
||||
#define BITSET_ZERO_(DST) (DST)->b.vtable->zero (DST)
|
||||
|
||||
|
||||
|
||||
/* DST = SRC. */
|
||||
#define BITSET_COPY_(DST, SRC) (SRC)->b.vtable->copy (DST, SRC)
|
||||
|
||||
/* Return DST & SRC == 0. */
|
||||
#define BITSET_DISJOINT_P_(DST, SRC) (SRC)->b.vtable->disjoint_p (DST, SRC)
|
||||
|
||||
/* Return DST == SRC. */
|
||||
#define BITSET_EQUAL_P_(DST, SRC) (SRC)->b.vtable->equal_p (DST, SRC)
|
||||
|
||||
/* DST = ~SRC. */
|
||||
#define BITSET_NOT_(DST, SRC) (SRC)->b.vtable->not_ (DST, SRC)
|
||||
|
||||
/* Return DST == DST | SRC. */
|
||||
#define BITSET_SUBSET_P_(DST, SRC) (SRC)->b.vtable->subset_p (DST, SRC)
|
||||
|
||||
|
||||
/* DST = SRC1 & SRC2. */
|
||||
#define BITSET_AND_(DST, SRC1, SRC2) (SRC1)->b.vtable->and_ (DST, SRC1, SRC2)
|
||||
#define BITSET_AND_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->and_cmp (DST, SRC1, SRC2)
|
||||
|
||||
/* DST = SRC1 & ~SRC2. */
|
||||
#define BITSET_ANDN_(DST, SRC1, SRC2) (SRC1)->b.vtable->andn (DST, SRC1, SRC2)
|
||||
#define BITSET_ANDN_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->andn_cmp (DST, SRC1, SRC2)
|
||||
|
||||
/* DST = SRC1 | SRC2. */
|
||||
#define BITSET_OR_(DST, SRC1, SRC2) (SRC1)->b.vtable->or_ (DST, SRC1, SRC2)
|
||||
#define BITSET_OR_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->or_cmp (DST, SRC1, SRC2)
|
||||
|
||||
/* DST = SRC1 ^ SRC2. */
|
||||
#define BITSET_XOR_(DST, SRC1, SRC2) (SRC1)->b.vtable->xor_ (DST, SRC1, SRC2)
|
||||
#define BITSET_XOR_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->xor_cmp (DST, SRC1, SRC2)
|
||||
|
||||
|
||||
|
||||
/* DST = (SRC1 & SRC2) | SRC3. Return non-zero if
|
||||
DST != (SRC1 & SRC2) | SRC3. */
|
||||
#define BITSET_AND_OR_(DST, SRC1, SRC2, SRC3) \
|
||||
(SRC1)->b.vtable->and_or (DST, SRC1, SRC2, SRC3)
|
||||
#define BITSET_AND_OR_CMP_(DST, SRC1, SRC2, SRC3) \
|
||||
(SRC1)->b.vtable->and_or_cmp (DST, SRC1, SRC2, SRC3)
|
||||
|
||||
/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
|
||||
DST != (SRC1 & ~SRC2) | SRC3. */
|
||||
#define BITSET_ANDN_OR_(DST, SRC1, SRC2, SRC3) \
|
||||
(SRC1)->b.vtable->andn_or (DST, SRC1, SRC2, SRC3)
|
||||
#define BITSET_ANDN_OR_CMP_(DST, SRC1, SRC2, SRC3) \
|
||||
(SRC1)->b.vtable->andn_or_cmp (DST, SRC1, SRC2, SRC3)
|
||||
|
||||
/* DST = (SRC1 | SRC2) & SRC3. Return non-zero if
|
||||
DST != (SRC1 | SRC2) & SRC3. */
|
||||
#define BITSET_OR_AND_(DST, SRC1, SRC2, SRC3) \
|
||||
(SRC1)->b.vtable->or_and (DST, SRC1, SRC2, SRC3)
|
||||
#define BITSET_OR_AND_CMP_(DST, SRC1, SRC2, SRC3) \
|
||||
(SRC1)->b.vtable->or_and_cmp (DST, SRC1, SRC2, SRC3)
|
||||
|
||||
|
||||
/* Find list of up to NUM bits set in BSET starting from and including
|
||||
*NEXT. Return with actual number of bits found and with *NEXT
|
||||
indicating where search stopped. */
|
||||
#define BITSET_LIST_(BSET, LIST, NUM, NEXT) \
|
||||
(BSET)->b.vtable->list (BSET, LIST, NUM, NEXT)
|
||||
|
||||
/* Find reverse list of up to NUM bits set in BSET starting from and
|
||||
including NEXT. Return with actual number of bits found and with
|
||||
*NEXT indicating where search stopped. */
|
||||
#define BITSET_LIST_REVERSE_(BSET, LIST, NUM, NEXT) \
|
||||
(BSET)->b.vtable->list_reverse (BSET, LIST, NUM, NEXT)
|
||||
|
||||
/* Iterate left to right over each set bit of WORD.
|
||||
Each iteration sets POS to the 0-based index of the next set bit in WORD.
|
||||
Repeatedly resets bits in WORD in place until it's null. */
|
||||
#define BITSET_FOR_EACH_BIT(Pos, Word) \
|
||||
for (int Pos = bitset_ffs_ (Word); \
|
||||
0 <= Pos; \
|
||||
Word ^= 1UL << Pos, Pos = bitset_ffs_ (Word))
|
||||
|
||||
/* Iterate right to left over each set bit of WORD.
|
||||
Each iteration sets POS to the 0-based index of the next set bit in WORD.
|
||||
Repeatedly resets bits in WORD in place until it's null. */
|
||||
#define BITSET_FOR_EACH_BIT_REVERSE(Pos, Word) \
|
||||
for (int Pos = bitset_fls_ (Word); \
|
||||
0 <= Pos; \
|
||||
Word ^= 1UL << Pos, Pos = bitset_fls_ (Word))
|
||||
|
||||
/* Private functions for bitset implementations. */
|
||||
|
||||
bool bitset_toggle_ (bitset, bitset_bindex);
|
||||
|
||||
bitset_bindex bitset_count_ (bitset);
|
||||
|
||||
bitset_bindex bitset_size_ (bitset);
|
||||
|
||||
bool bitset_copy_ (bitset, bitset);
|
||||
|
||||
void bitset_and_or_ (bitset, bitset, bitset, bitset);
|
||||
|
||||
bool bitset_and_or_cmp_ (bitset, bitset, bitset, bitset);
|
||||
|
||||
void bitset_andn_or_ (bitset, bitset, bitset, bitset);
|
||||
|
||||
bool bitset_andn_or_cmp_ (bitset, bitset, bitset, bitset);
|
||||
|
||||
void bitset_or_and_ (bitset, bitset, bitset, bitset);
|
||||
|
||||
bool bitset_or_and_cmp_ (bitset, bitset, bitset, bitset);
|
||||
|
||||
/* First set bit in WORD.
|
||||
Indexes start at 0, return -1 if WORD is null. */
|
||||
static inline
|
||||
int bitset_ffs_ (bitset_word word)
|
||||
{
|
||||
return ffsl ((long) word) - 1;
|
||||
}
|
||||
|
||||
/* Last set bit in WORD.
|
||||
Indexes start at 0, return -1 if WORD is null. */
|
||||
static inline
|
||||
int bitset_fls_ (bitset_word word)
|
||||
{
|
||||
return integer_length_l (word) - 1;
|
||||
}
|
||||
|
||||
#endif /* _BBITSET_H */
|
||||
@@ -1,32 +0,0 @@
|
||||
/* Functions to support lbitsets.
|
||||
|
||||
Copyright (C) 2002, 2004, 2009-2015, 2018-2024 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
|
||||
|
||||
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 _BITSET_LIST_H
|
||||
#define _BITSET_LIST_H
|
||||
|
||||
#include "bitset.h"
|
||||
|
||||
size_t lbitset_bytes (bitset_bindex);
|
||||
|
||||
bitset lbitset_init (bitset, bitset_bindex);
|
||||
|
||||
void lbitset_release_memory (void);
|
||||
|
||||
#endif
|
||||
@@ -1,33 +0,0 @@
|
||||
/* Functions to support bitset statistics.
|
||||
|
||||
Copyright (C) 2002-2004, 2009-2015, 2018-2024 Free Software Foundation, Inc.
|
||||
|
||||
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
|
||||
|
||||
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 _BITSET_STATS_H
|
||||
#define _BITSET_STATS_H
|
||||
|
||||
#include "bitset/base.h"
|
||||
|
||||
extern bool bitset_stats_enabled;
|
||||
|
||||
enum bitset_type bitset_stats_type_get (bitset);
|
||||
|
||||
size_t bitset_stats_bytes (void);
|
||||
|
||||
bitset bitset_stats_init (bitset, bitset_bindex, enum bitset_type);
|
||||
|
||||
#endif
|
||||
@@ -1,32 +0,0 @@
|
||||
/* Functions to support tbitsets.
|
||||
|
||||
Copyright (C) 2002, 2004, 2009-2015, 2018-2024 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
|
||||
|
||||
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 _BITSET_TABLE_H
|
||||
#define _BITSET_TABLE_H
|
||||
|
||||
#include "bitset.h"
|
||||
|
||||
size_t tbitset_bytes (bitset_bindex);
|
||||
|
||||
bitset tbitset_init (bitset, bitset_bindex);
|
||||
|
||||
void tbitset_release_memory (void);
|
||||
|
||||
#endif
|
||||
@@ -1,30 +0,0 @@
|
||||
/* Functions to support vbitsets.
|
||||
|
||||
Copyright (C) 2002, 2004, 2009-2015, 2018-2024 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
|
||||
|
||||
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 _BITSET_VECTOR_H
|
||||
#define _BITSET_VECTOR_H
|
||||
|
||||
#include "bitset.h"
|
||||
|
||||
size_t vbitset_bytes (bitset_bindex);
|
||||
|
||||
bitset vbitset_init (bitset, bitset_bindex);
|
||||
|
||||
#endif
|
||||
@@ -1,81 +0,0 @@
|
||||
/* Bitset vectors.
|
||||
|
||||
Copyright (C) 2002, 2004, 2009-2015, 2018-2024 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
|
||||
|
||||
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 _BITSETV_H
|
||||
#define _BITSETV_H
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_DEALLOC. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include "bitset.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef bitset * bitsetv;
|
||||
|
||||
/* Free vector of bitsets. Do nothing if NULL. */
|
||||
void bitsetv_free (bitsetv);
|
||||
|
||||
/* Create a vector of N_VECS bitsets, each of N_BITS, and of
|
||||
type TYPE. */
|
||||
bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type)
|
||||
_GL_ATTRIBUTE_DEALLOC (bitsetv_free, 1);
|
||||
|
||||
/* Create a vector of N_VECS bitsets, each of N_BITS, and with
|
||||
attribute hints specified by ATTR. */
|
||||
bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned)
|
||||
_GL_ATTRIBUTE_DEALLOC (bitsetv_free, 1);
|
||||
|
||||
/* Zero vector of bitsets. */
|
||||
void bitsetv_zero (bitsetv);
|
||||
|
||||
/* Set vector of bitsets. */
|
||||
void bitsetv_ones (bitsetv);
|
||||
|
||||
/* Given a vector BSETV of N bitsets of size N, modify its contents to
|
||||
be the transitive closure of what was given. */
|
||||
void bitsetv_transitive_closure (bitsetv);
|
||||
|
||||
/* Given a vector BSETV of N bitsets of size N, modify its contents to
|
||||
be the reflexive transitive closure of what was given. This is
|
||||
the same as transitive closure but with all bits on the diagonal
|
||||
of the bit matrix set. */
|
||||
void bitsetv_reflexive_transitive_closure (bitsetv);
|
||||
|
||||
/* Dump vector of bitsets. */
|
||||
void bitsetv_dump (FILE *, const char *, const char *, bitsetv);
|
||||
|
||||
/* Function to debug vector of bitsets from debugger. */
|
||||
void debug_bitsetv (bitsetv);
|
||||
|
||||
/* Dump vector of bitsets as a matrix. */
|
||||
void bitsetv_matrix_dump (FILE *, const char *, bitsetv);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BITSETV_H */
|
||||
@@ -1,422 +0,0 @@
|
||||
/* Auxiliary functions for determining the time when the machine last booted.
|
||||
Copyright (C) 2023-2024 Free Software Foundation, Inc.
|
||||
|
||||
This file 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 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 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 Bruno Haible <bruno@clisp.org>. */
|
||||
|
||||
#define SIZEOF(a) (sizeof(a)/sizeof(a[0]))
|
||||
|
||||
#if defined __linux__ || defined __ANDROID__
|
||||
|
||||
/* Store the uptime counter, as managed by the Linux kernel, in *P_UPTIME.
|
||||
Return 0 upon success, -1 upon failure. */
|
||||
_GL_ATTRIBUTE_MAYBE_UNUSED
|
||||
static int
|
||||
get_linux_uptime (struct timespec *p_uptime)
|
||||
{
|
||||
/* The clock_gettime facility returns the uptime with a resolution of 1 µsec.
|
||||
It is available with glibc >= 2.14, Android, or musl libc.
|
||||
In glibc < 2.17 it required linking with librt. */
|
||||
# if !defined __GLIBC__ || 2 < __GLIBC__ + (17 <= __GLIBC_MINOR__)
|
||||
if (clock_gettime (CLOCK_BOOTTIME, p_uptime) >= 0)
|
||||
return 0;
|
||||
# endif
|
||||
|
||||
/* /proc/uptime contains the uptime with a resolution of 0.01 sec.
|
||||
But it does not have read permissions on Android. */
|
||||
# if !defined __ANDROID__
|
||||
FILE *fp = fopen ("/proc/uptime", "re");
|
||||
if (fp != NULL)
|
||||
{
|
||||
char buf[32 + 1];
|
||||
size_t n = fread (buf, 1, sizeof (buf) - 1, fp);
|
||||
fclose (fp);
|
||||
if (n > 0)
|
||||
{
|
||||
buf[n] = '\0';
|
||||
/* buf now contains two values: the uptime and the idle time. */
|
||||
time_t s = 0;
|
||||
char *p;
|
||||
for (p = buf; '0' <= *p && *p <= '9'; p++)
|
||||
s = 10 * s + (*p - '0');
|
||||
if (buf < p)
|
||||
{
|
||||
long ns = 0;
|
||||
if (*p++ == '.')
|
||||
for (int i = 0; i < 9; i++)
|
||||
ns = 10 * ns + ('0' <= *p && *p <= '9' ? *p++ - '0' : 0);
|
||||
p_uptime->tv_sec = s;
|
||||
p_uptime->tv_nsec = ns;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if HAVE_DECL_SYSINFO /* not available in Android API < 9 */
|
||||
/* The sysinfo call returns the uptime with a resolution of 1 sec only. */
|
||||
struct sysinfo info;
|
||||
if (sysinfo (&info) >= 0)
|
||||
{
|
||||
p_uptime->tv_sec = info.uptime;
|
||||
p_uptime->tv_nsec = 0;
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined __linux__ && !defined __ANDROID__
|
||||
|
||||
static int
|
||||
get_linux_boot_time_fallback (struct timespec *p_boot_time)
|
||||
{
|
||||
/* On Devuan with the 'runit' init system and on Artix with the 's6' init
|
||||
system, UTMP_FILE contains USER_PROCESS and other entries, but no
|
||||
BOOT_TIME entry.
|
||||
On Alpine Linux, UTMP_FILE is not filled. It is always empty.
|
||||
So, in both cases, get the time stamp of a file that gets touched only
|
||||
during the boot process. */
|
||||
|
||||
const char * const boot_touched_files[] =
|
||||
{
|
||||
"/var/lib/systemd/random-seed", /* seen on distros with systemd */
|
||||
"/var/lib/urandom/random-seed", /* seen on Devuan with runit */
|
||||
"/var/lib/random-seed", /* seen on Artix with s6 */
|
||||
/* This must come last, since on several distros /var/run/utmp is
|
||||
modified when a user logs in, i.e. long after boot. */
|
||||
"/var/run/utmp" /* seen on Alpine Linux with OpenRC */
|
||||
};
|
||||
for (idx_t i = 0; i < SIZEOF (boot_touched_files); i++)
|
||||
{
|
||||
const char *filename = boot_touched_files[i];
|
||||
struct stat statbuf;
|
||||
if (stat (filename, &statbuf) >= 0)
|
||||
{
|
||||
struct timespec boot_time = get_stat_mtime (&statbuf);
|
||||
/* On Alpine 3.20.0_rc2 /var/run/utmp was observed with bogus
|
||||
timestamps of ~10 s. Reject timestamps before
|
||||
2005-07-25 23:34:15 UTC (1122334455), as neither Alpine
|
||||
nor Devuan existed then. */
|
||||
if (boot_time.tv_sec >= 1122334455)
|
||||
{
|
||||
*p_boot_time = boot_time;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* The following approach is only usable as a fallback, because it is of
|
||||
the form
|
||||
boot_time = (time now) - (kernel's ktime_get_boottime[_ts64] ())
|
||||
and therefore produces wrong values after the date has been bumped in the
|
||||
running system, which happens frequently if the system is running in a
|
||||
virtual machine and this VM has been put into "saved" or "sleep" state
|
||||
and then resumed. */
|
||||
static int
|
||||
get_linux_boot_time_final_fallback (struct timespec *p_boot_time)
|
||||
{
|
||||
struct timespec uptime;
|
||||
if (get_linux_uptime (&uptime) >= 0)
|
||||
{
|
||||
struct timespec result;
|
||||
# if !defined __GLIBC__ || 2 < __GLIBC__ + (16 <= __GLIBC_MINOR__)
|
||||
/* Better than:
|
||||
if (0 <= clock_gettime (CLOCK_REALTIME, &result))
|
||||
because timespec_get does not need -lrt in glibc 2.16.
|
||||
*/
|
||||
if (! timespec_get (&result, TIME_UTC))
|
||||
return -1;
|
||||
# else
|
||||
/* Fall back on lower-res approach that does not need -lrt.
|
||||
This is good enough; on these hosts UPTIME is even lower-res. */
|
||||
struct timeval tv;
|
||||
int r = gettimeofday (&tv, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
result.tv_sec = tv.tv_sec;
|
||||
result.tv_nsec = tv.tv_usec * 1000;
|
||||
# endif
|
||||
|
||||
if (result.tv_nsec < uptime.tv_nsec)
|
||||
{
|
||||
result.tv_nsec += 1000000000;
|
||||
result.tv_sec -= 1;
|
||||
}
|
||||
result.tv_sec -= uptime.tv_sec;
|
||||
result.tv_nsec -= uptime.tv_nsec;
|
||||
*p_boot_time = result;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined __ANDROID__
|
||||
|
||||
static int
|
||||
get_android_boot_time (struct timespec *p_boot_time)
|
||||
{
|
||||
/* On Android, there is no /var, and normal processes don't have access
|
||||
to system files. Therefore use the kernel's uptime counter, although
|
||||
it produces wrong values after the date has been bumped in the running
|
||||
system. */
|
||||
struct timespec uptime;
|
||||
if (get_linux_uptime (&uptime) >= 0)
|
||||
{
|
||||
struct timespec result;
|
||||
if (clock_gettime (CLOCK_REALTIME, &result) >= 0)
|
||||
{
|
||||
if (result.tv_nsec < uptime.tv_nsec)
|
||||
{
|
||||
result.tv_nsec += 1000000000;
|
||||
result.tv_sec -= 1;
|
||||
}
|
||||
result.tv_sec -= uptime.tv_sec;
|
||||
result.tv_nsec -= uptime.tv_nsec;
|
||||
*p_boot_time = result;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined __OpenBSD__
|
||||
|
||||
static int
|
||||
get_openbsd_boot_time (struct timespec *p_boot_time)
|
||||
{
|
||||
/* On OpenBSD, UTMP_FILE is not filled. It contains only dummy entries.
|
||||
So, get the time stamp of a file that gets touched only during the
|
||||
boot process. */
|
||||
const char * const boot_touched_files[] =
|
||||
{
|
||||
"/var/db/host.random",
|
||||
"/var/run/utmp"
|
||||
};
|
||||
for (idx_t i = 0; i < SIZEOF (boot_touched_files); i++)
|
||||
{
|
||||
const char *filename = boot_touched_files[i];
|
||||
struct stat statbuf;
|
||||
if (stat (filename, &statbuf) >= 0)
|
||||
{
|
||||
*p_boot_time = get_stat_mtime (&statbuf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_SYSCTL_H && HAVE_SYSCTL \
|
||||
&& defined CTL_KERN && defined KERN_BOOTTIME \
|
||||
&& !defined __minix
|
||||
/* macOS, FreeBSD, GNU/kFreeBSD, NetBSD, OpenBSD */
|
||||
/* On Minix 3.3 this sysctl produces garbage results. Therefore avoid it. */
|
||||
|
||||
/* The following approach is only usable as a fallback, because it produces
|
||||
wrong values after the date has been bumped in the running system, which
|
||||
happens frequently if the system is running in a virtual machine and this
|
||||
VM has been put into "saved" or "sleep" state and then resumed. */
|
||||
static int
|
||||
get_bsd_boot_time_final_fallback (struct timespec *p_boot_time)
|
||||
{
|
||||
static int request[2] = { CTL_KERN, KERN_BOOTTIME };
|
||||
struct timeval result;
|
||||
size_t result_len = sizeof result;
|
||||
|
||||
if (sysctl (request, 2, &result, &result_len, NULL, 0) >= 0)
|
||||
{
|
||||
p_boot_time->tv_sec = result.tv_sec;
|
||||
p_boot_time->tv_nsec = result.tv_usec * 1000;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined __HAIKU__
|
||||
|
||||
static int
|
||||
get_haiku_boot_time (struct timespec *p_boot_time)
|
||||
{
|
||||
/* On Haiku, /etc/utmp does not exist. During boot,
|
||||
1. the current time is restored, but possibly with a wrong time zone,
|
||||
that is, with an offset of a few hours,
|
||||
2. some symlinks and files get created,
|
||||
3. the various devices are brought up, in particular the network device,
|
||||
4. the correct date and time is set,
|
||||
5. some more device nodes get created.
|
||||
The boot time can be retrieved by looking at a directory created during
|
||||
phase 5, such as /dev/input. */
|
||||
const char * const boot_touched_file = "/dev/input";
|
||||
struct stat statbuf;
|
||||
if (stat (boot_touched_file, &statbuf) >= 0)
|
||||
{
|
||||
*p_boot_time = get_stat_mtime (&statbuf);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if HAVE_OS_H /* BeOS, Haiku */
|
||||
|
||||
/* The following approach is only usable as a fallback, because it produces
|
||||
wrong values after the date has been bumped in the running system, which
|
||||
happens frequently if the system is running in a virtual machine and this
|
||||
VM has been put into "saved" or "sleep" state and then resumed. */
|
||||
static int
|
||||
get_haiku_boot_time_final_fallback (struct timespec *p_boot_time)
|
||||
{
|
||||
system_info si;
|
||||
|
||||
get_system_info (&si);
|
||||
p_boot_time->tv_sec = si.boot_time / 1000000;
|
||||
p_boot_time->tv_nsec = (si.boot_time % 1000000) * 1000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined __CYGWIN__ || defined _WIN32
|
||||
|
||||
static int
|
||||
get_windows_boot_time (struct timespec *p_boot_time)
|
||||
{
|
||||
/* On Cygwin, /var/run/utmp is empty.
|
||||
On native Windows, <utmpx.h> and <utmp.h> don't exist.
|
||||
Instead, on Windows, the boot time can be retrieved by looking at the
|
||||
time stamp of a file that (normally) gets touched only during the boot
|
||||
process, namely C:\pagefile.sys. */
|
||||
const char * const boot_touched_files[] =
|
||||
{
|
||||
#if defined __CYGWIN__ && !defined _WIN32
|
||||
/* It is more portable to use /proc/cygdrive/c than /cygdrive/c. */
|
||||
"/proc/cygdrive/c/pagefile.sys",
|
||||
/* A fallback, working around a Cygwin 3.5.3 bug. It has a modification
|
||||
time about 1.5 minutes after the last boot; but that's better than
|
||||
nothing. */
|
||||
"/proc/cygdrive/c/ProgramData/Microsoft/Windows/DeviceMetadataCache/dmrc.idx"
|
||||
#else
|
||||
"C:\\pagefile.sys"
|
||||
#endif
|
||||
};
|
||||
for (idx_t i = 0; i < SIZEOF (boot_touched_files); i++)
|
||||
{
|
||||
const char *filename = boot_touched_files[i];
|
||||
struct stat statbuf;
|
||||
if (stat (filename, &statbuf) >= 0)
|
||||
{
|
||||
# if defined __CYGWIN__ && !defined _WIN32
|
||||
/* Work around a Cygwin 3.5.3 bug.
|
||||
<https://cygwin.com/pipermail/cygwin/2024-May/255931.html> */
|
||||
if (!S_ISDIR (statbuf.st_mode))
|
||||
# endif
|
||||
{
|
||||
*p_boot_time = get_stat_mtime (&statbuf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
# ifndef __CYGWIN__
|
||||
# if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
|
||||
|
||||
/* Don't assume that UNICODE is not defined. */
|
||||
# undef LoadLibrary
|
||||
# define LoadLibrary LoadLibraryA
|
||||
|
||||
/* Avoid warnings from gcc -Wcast-function-type. */
|
||||
# define GetProcAddress \
|
||||
(void *) GetProcAddress
|
||||
|
||||
/* GetTickCount64 is only available on Windows Vista and later. */
|
||||
typedef ULONGLONG (WINAPI * GetTickCount64FuncType) (void);
|
||||
|
||||
static GetTickCount64FuncType GetTickCount64Func = NULL;
|
||||
static BOOL initialized = FALSE;
|
||||
|
||||
static void
|
||||
initialize (void)
|
||||
{
|
||||
HMODULE kernel32 = LoadLibrary ("kernel32.dll");
|
||||
if (kernel32 != NULL)
|
||||
{
|
||||
GetTickCount64Func =
|
||||
(GetTickCount64FuncType) GetProcAddress (kernel32, "GetTickCount64");
|
||||
}
|
||||
initialized = TRUE;
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
# define GetTickCount64Func GetTickCount64
|
||||
|
||||
# endif
|
||||
|
||||
/* Fallback for Windows in the form:
|
||||
boot time = current time - uptime
|
||||
This uses the GetTickCount64 function which is only available on Windows
|
||||
Vista and later. See:
|
||||
<https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount64>. */
|
||||
static int
|
||||
get_windows_boot_time_fallback (struct timespec *p_boot_time)
|
||||
{
|
||||
# if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
|
||||
if (! initialized)
|
||||
initialize ();
|
||||
# endif
|
||||
if (GetTickCount64Func != NULL)
|
||||
{
|
||||
ULONGLONG uptime_ms = GetTickCount64Func ();
|
||||
struct timespec uptime;
|
||||
struct timespec result;
|
||||
struct timeval tv;
|
||||
if (gettimeofday (&tv, NULL) >= 0)
|
||||
{
|
||||
uptime.tv_sec = uptime_ms / 1000;
|
||||
uptime.tv_nsec = (uptime_ms % 1000) * 1000000;
|
||||
result.tv_sec = tv.tv_sec;
|
||||
result.tv_nsec = tv.tv_usec * 1000;
|
||||
if (result.tv_nsec < uptime.tv_nsec)
|
||||
{
|
||||
result.tv_nsec += 1000000000;
|
||||
result.tv_sec -= 1;
|
||||
}
|
||||
result.tv_sec -= uptime.tv_sec;
|
||||
result.tv_nsec -= uptime.tv_nsec;
|
||||
*p_boot_time = result;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,44 +0,0 @@
|
||||
/* Determine the time when the machine last booted.
|
||||
Copyright (C) 2023-2024 Free Software Foundation, Inc.
|
||||
|
||||
This file 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 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 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 Bruno Haible <bruno@clisp.org>. */
|
||||
|
||||
#ifndef _BOOT_TIME_H
|
||||
#define _BOOT_TIME_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Store the approximate time when the machine last booted in *P_BOOT_TIME,
|
||||
and return 0. If it cannot be determined, return -1.
|
||||
|
||||
This function is not multithread-safe, since on many platforms it
|
||||
invokes the functions setutxent, getutxent, endutxent. These
|
||||
functions are needed because they may lock FILE (so that we don't
|
||||
read garbage when a concurrent process writes to FILE), but their
|
||||
drawback is that they have a common global state. */
|
||||
extern int get_boot_time (struct timespec *p_boot_time);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BOOT_TIME_H */
|
||||
@@ -1,357 +0,0 @@
|
||||
/* C++ compatible function declaration macros.
|
||||
Copyright (C) 2010-2024 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_EXTERN_C_FUNC declaration;
|
||||
performs the declaration of a function with C linkage. */
|
||||
#if defined __cplusplus
|
||||
# define _GL_EXTERN_C_FUNC extern "C"
|
||||
#else
|
||||
/* In C mode, omit the 'extern' keyword, because attributes in bracket syntax
|
||||
are not allowed between 'extern' and the return type (see gnulib-common.m4).
|
||||
*/
|
||||
# define _GL_EXTERN_C_FUNC
|
||||
#endif
|
||||
|
||||
/* _GL_FUNCDECL_RPL (func, rettype, parameters, [attributes]);
|
||||
declares a replacement function, named rpl_func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Although attributes are optional, the comma before them is required
|
||||
for portability to C17 and earlier. The attribute _GL_ATTRIBUTE_NOTHROW,
|
||||
if needed, must be placed after the _GL_FUNCDECL_RPL invocation,
|
||||
at the end of the declaration.
|
||||
Examples:
|
||||
_GL_FUNCDECL_RPL (free, void, (void *ptr), ) _GL_ATTRIBUTE_NOTHROW;
|
||||
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...),
|
||||
_GL_ARG_NONNULL ((1)));
|
||||
|
||||
Note: Attributes, such as _GL_ATTRIBUTE_DEPRECATED, are supported in front
|
||||
of a _GL_FUNCDECL_RPL invocation only in C mode, not in C++ mode. (That's
|
||||
because
|
||||
[[...]] extern "C" <declaration>;
|
||||
is invalid syntax in C++.)
|
||||
*/
|
||||
#define _GL_FUNCDECL_RPL(func,rettype,parameters,...) \
|
||||
_GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters, __VA_ARGS__)
|
||||
#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters,...) \
|
||||
_GL_EXTERN_C_FUNC __VA_ARGS__ rettype rpl_func parameters
|
||||
|
||||
/* _GL_FUNCDECL_SYS (func, rettype, parameters, [attributes]);
|
||||
declares the system function, named func, with the given prototype,
|
||||
consisting of return type, parameters, and attributes.
|
||||
Although attributes are optional, the comma before them is required
|
||||
for portability to C17 and earlier. The attribute _GL_ATTRIBUTE_NOTHROW,
|
||||
if needed, must be placed after the _GL_FUNCDECL_RPL invocation,
|
||||
at the end of the declaration.
|
||||
Examples:
|
||||
_GL_FUNCDECL_SYS (getumask, mode_t, (void), ) _GL_ATTRIBUTE_NOTHROW;
|
||||
_GL_FUNCDECL_SYS (posix_openpt, int, (int flags), _GL_ATTRIBUTE_NODISCARD);
|
||||
*/
|
||||
#define _GL_FUNCDECL_SYS(func,rettype,parameters,...) \
|
||||
_GL_EXTERN_C_FUNC __VA_ARGS__ rettype func parameters
|
||||
|
||||
/* _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 || defined __clang__) && 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,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-2024 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
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#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 @@
|
||||
/* snprintf in C locale.
|
||||
Copyright (C) 2012-2024 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_SNPRINTF_H
|
||||
#define _C_SNPRINTF_H
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_FORMAT. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
/* Get size_t, ptrdiff_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Prints formatted output to string STR. Similar to sprintf, but the
|
||||
additional parameter SIZE limits how much is written into STR.
|
||||
STR may be NULL, in which case nothing will be written.
|
||||
Returns the string length of the formatted string (which may be larger
|
||||
than SIZE). Upon failure, returns -1 with errno set.
|
||||
|
||||
Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
|
||||
Therefore, if the format string is valid and does not use %ls/%lc
|
||||
directives nor widths, the only possible failure code is ENOMEM.
|
||||
|
||||
Formatting takes place in the C locale, that is, the decimal point
|
||||
used in floating-point formatting directives is always '.'. */
|
||||
extern ptrdiff_t c_snzprintf (char *restrict str, size_t size,
|
||||
const char *format, ...)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 4));
|
||||
|
||||
/* Prints formatted output to string STR. Similar to sprintf, but the
|
||||
additional parameter SIZE limits how much is written into STR.
|
||||
STR may be NULL, in which case nothing will be written.
|
||||
Returns the string length of the formatted string (which may be larger
|
||||
than SIZE). Upon failure, returns -1 with errno set.
|
||||
|
||||
Formatting takes place in the C locale, that is, the decimal point
|
||||
used in floating-point formatting directives is always '.'. */
|
||||
extern int c_snprintf (char *restrict str, size_t size,
|
||||
const char *format, ...)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 4));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _C_SNPRINTF_H */
|
||||
@@ -1,62 +0,0 @@
|
||||
/* Stack overflow handling.
|
||||
|
||||
Copyright (C) 2002, 2004, 2008-2024 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/>. */
|
||||
|
||||
/* This file uses _GL_ASYNC_SAFE. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Set up ACTION so that it is invoked on C stack overflow and on other,
|
||||
stack-unrelated, segmentation violation.
|
||||
Return -1 (setting errno) if this cannot be done.
|
||||
|
||||
When a stack overflow or segmentation violation occurs:
|
||||
1) ACTION is called. It is passed an argument equal to
|
||||
- 0, for a stack overflow,
|
||||
- SIGSEGV, for a segmentation violation that does not appear related
|
||||
to stack overflow.
|
||||
On many platforms the two cases are hard to distinguish; when in doubt,
|
||||
zero is passed.
|
||||
2) If ACTION returns, a message is written to standard error, and the
|
||||
program is terminated: in the case of stack overflow, with exit code
|
||||
exit_failure (see "exitfail.h"), otherwise through a signal SIGSEGV.
|
||||
|
||||
A null ACTION acts like an action that does nothing.
|
||||
|
||||
Restrictions:
|
||||
- ACTION must be async-signal-safe.
|
||||
- ACTION together with its callees must not require more than 64 KiB of
|
||||
stack space.
|
||||
- ACTION must not create and then invoke nested functions
|
||||
<https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>, because
|
||||
this implementation does not guarantee an executable stack.
|
||||
- ACTION should not call longjmp, because this implementation does not
|
||||
guarantee that it is safe to return to the original stack.
|
||||
|
||||
This function may install a handler for the SIGSEGV signal or for the SIGBUS
|
||||
signal or exercise other system dependent exception handling APIs. */
|
||||
|
||||
extern int c_stack_action (_GL_ASYNC_SAFE void (* /*action*/) (int));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,61 +0,0 @@
|
||||
/* Case-insensitive string comparison functions in C locale.
|
||||
Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2024 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_STRCASE_H
|
||||
#define C_STRCASE_H
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_PURE. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
/* 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. More precisely, one of the string arguments must be an ASCII
|
||||
string; the other one can also contain non-ASCII characters (but then
|
||||
the comparison result will be nonzero). */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
|
||||
greater than zero if S1 is lexicographically less than, equal to or greater
|
||||
than S2. */
|
||||
extern int c_strcasecmp (const char *s1, const char *s2) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* Compare no more than N characters of strings S1 and S2, ignoring case,
|
||||
returning less than, equal to or greater than zero if S1 is
|
||||
lexicographically less than, equal to or greater than S2. */
|
||||
extern int c_strncasecmp (const char *s1, const char *s2, size_t n)
|
||||
_GL_ATTRIBUTE_PURE;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* C_STRCASE_H */
|
||||
@@ -1,191 +0,0 @@
|
||||
/* Optimized case-insensitive string comparison in C locale.
|
||||
Copyright (C) 2001-2002, 2007, 2009-2024 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>. */
|
||||
|
||||
#include "c-strcase.h"
|
||||
#include "c-ctype.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* STRCASEEQ allows to optimize string comparison with a small literal string.
|
||||
STRCASEEQ (s, "UTF-8", 'U','T','F','-','8',0,0,0,0)
|
||||
is semantically equivalent to
|
||||
c_strcasecmp (s, "UTF-8") == 0
|
||||
just faster. */
|
||||
|
||||
/* Help GCC to generate good code for string comparisons with
|
||||
immediate strings. */
|
||||
#if (defined __GNUC__ || defined __clang__) && defined __OPTIMIZE__
|
||||
|
||||
/* Case insensitive comparison of ASCII characters. */
|
||||
# if C_CTYPE_ASCII
|
||||
# define CASEEQ(other,upper) \
|
||||
(c_isupper (upper) ? ((other) & ~0x20) == (upper) : (other) == (upper))
|
||||
# else
|
||||
# define CASEEQ(other,upper) \
|
||||
(c_toupper (other) == (upper))
|
||||
# endif
|
||||
|
||||
static inline int
|
||||
strcaseeq9 (const char *s1, const char *s2)
|
||||
{
|
||||
return c_strcasecmp (s1 + 9, s2 + 9) == 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
strcaseeq8 (const char *s1, const char *s2, char s28)
|
||||
{
|
||||
if (CASEEQ (s1[8], s28))
|
||||
{
|
||||
if (s28 == 0)
|
||||
return 1;
|
||||
else
|
||||
return strcaseeq9 (s1, s2);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
strcaseeq7 (const char *s1, const char *s2, char s27, char s28)
|
||||
{
|
||||
if (CASEEQ (s1[7], s27))
|
||||
{
|
||||
if (s27 == 0)
|
||||
return 1;
|
||||
else
|
||||
return strcaseeq8 (s1, s2, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
strcaseeq6 (const char *s1, const char *s2, char s26, char s27, char s28)
|
||||
{
|
||||
if (CASEEQ (s1[6], s26))
|
||||
{
|
||||
if (s26 == 0)
|
||||
return 1;
|
||||
else
|
||||
return strcaseeq7 (s1, s2, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
strcaseeq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (CASEEQ (s1[5], s25))
|
||||
{
|
||||
if (s25 == 0)
|
||||
return 1;
|
||||
else
|
||||
return strcaseeq6 (s1, s2, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
strcaseeq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (CASEEQ (s1[4], s24))
|
||||
{
|
||||
if (s24 == 0)
|
||||
return 1;
|
||||
else
|
||||
return strcaseeq5 (s1, s2, s25, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
strcaseeq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (CASEEQ (s1[3], s23))
|
||||
{
|
||||
if (s23 == 0)
|
||||
return 1;
|
||||
else
|
||||
return strcaseeq4 (s1, s2, s24, s25, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
strcaseeq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (CASEEQ (s1[2], s22))
|
||||
{
|
||||
if (s22 == 0)
|
||||
return 1;
|
||||
else
|
||||
return strcaseeq3 (s1, s2, s23, s24, s25, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
strcaseeq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
|
||||
{
|
||||
if (CASEEQ (s1[1], s21))
|
||||
{
|
||||
if (s21 == 0)
|
||||
return 1;
|
||||
else
|
||||
return strcaseeq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
strcaseeq0 (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 (CASEEQ (s1[0], s20))
|
||||
{
|
||||
if (s20 == 0)
|
||||
return 1;
|
||||
else
|
||||
return strcaseeq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define STRCASEEQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
|
||||
strcaseeq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
|
||||
|
||||
#else
|
||||
|
||||
#define STRCASEEQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
|
||||
(c_strcasecmp (s1, s2) == 0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,36 +0,0 @@
|
||||
/* Case-insensitive searching in a string in C locale.
|
||||
Copyright (C) 2005, 2009-2024 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_STRCASESTR_H
|
||||
#define C_STRCASESTR_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
|
||||
comparison. */
|
||||
extern char *c_strcasestr (const char *haystack, const char *needle);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* C_STRCASESTR_H */
|
||||
@@ -1,44 +0,0 @@
|
||||
/* Searching in a string.
|
||||
Copyright (C) 2001-2003, 2006, 2009-2024 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 3 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/>. */
|
||||
|
||||
|
||||
/* The functions defined in this file assume a nearly ASCII compatible
|
||||
character set. */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Find the first occurrence of NEEDLE in HAYSTACK.
|
||||
This function is safe to be called, even in a multibyte locale, if NEEDLE
|
||||
1. consists solely of printable ASCII characters excluding '\\' and '~'
|
||||
[this restriction is needed because of Shift_JIS and JOHAB]
|
||||
or of the control ASCII characters '\a' '\b' '\f' '\n' '\r' '\t' '\v'
|
||||
[this restriction is needed because of VISCII], and
|
||||
2. has at least length 2
|
||||
[this restriction is needed because of BIG5, BIG5-HKSCS, GBK, GB18030,
|
||||
Shift_JIS, JOHAB], and
|
||||
3. does not consist entirely of decimal digits, or has at least length 4
|
||||
[this restriction is needed because of GB18030].
|
||||
This function is also safe to be called, even in a multibyte locale, if
|
||||
HAYSTACK and NEEDLE are known to both consist solely of printable ASCII
|
||||
characters excluding '\\' and '~'. */
|
||||
extern char *c_strstr (const char *haystack, const char *needle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,53 +0,0 @@
|
||||
/* Convert string to floating-point number, using the C locale.
|
||||
|
||||
Copyright (C) 2003-2004, 2009-2024 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/>. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Parse the initial portion of the string pointed to by NPTR as a floating-
|
||||
point number (in decimal or hexadecimal notation), like in the C locale:
|
||||
accepting only the ASCII digits '0'..'9', and only '.' as decimal point
|
||||
character.
|
||||
If ENDPTR is not NULL, set *ENDPTR to point to the first byte beyond the
|
||||
parsed number or to NPTR if the string does not start with a parsable
|
||||
number.
|
||||
Return value:
|
||||
- If successful, return the value as a float, double, or 'long double',
|
||||
respectively, and don't modify errno.
|
||||
- In case of overflow, return ±HUGE_VAL or ±HUGE_VALL, respectively, and
|
||||
set errno to ERANGE.
|
||||
- In case of underflow, return a value very near to 0 and set errno to
|
||||
ERANGE.
|
||||
- If the string does not start with a number at all, return 0 (and recall
|
||||
that if ENDPTR != NULL, *ENDPTR is set to NPTR), and maybe set errno to
|
||||
EINVAL.
|
||||
- In case of other error, return 0 and set errno, for example to ENOMEM. */
|
||||
extern float c_strtof (char const *nptr, char **endptr);
|
||||
extern double c_strtod (char const *nptr, char **endptr);
|
||||
extern long double c_strtold (char const *nptr, char **endptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hey Emacs!
|
||||
* Local Variables:
|
||||
* coding: utf-8
|
||||
* End:
|
||||
*/
|
||||
@@ -1,73 +0,0 @@
|
||||
/* vsprintf with automatic memory allocation in C locale.
|
||||
Copyright (C) 2002-2004, 2007-2024 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_VASNPRINTF_H
|
||||
#define _C_VASNPRINTF_H
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_FORMAT. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
/* Get va_list. */
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Get size_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Write formatted output to a string dynamically allocated with malloc().
|
||||
You can pass a preallocated buffer for the result in RESULTBUF and its
|
||||
size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
|
||||
If successful, return the address of the string (this may be = RESULTBUF
|
||||
if no dynamic memory allocation was necessary) and set *LENGTHP to the
|
||||
number of resulting bytes, excluding the trailing NUL. Upon error, set
|
||||
errno and return NULL.
|
||||
|
||||
When dynamic memory allocation occurs, the preallocated buffer is left
|
||||
alone (with possibly modified contents). This makes it possible to use
|
||||
a statically allocated or stack-allocated buffer, like this:
|
||||
|
||||
char buf[100];
|
||||
size_t len = sizeof (buf);
|
||||
char *output = vasnprintf (buf, &len, format, args);
|
||||
if (output == NULL)
|
||||
... error handling ...;
|
||||
else
|
||||
{
|
||||
... use the output string ...;
|
||||
if (output != buf)
|
||||
free (output);
|
||||
}
|
||||
|
||||
Formatting takes place in the C locale, that is, the decimal point used in
|
||||
floating-point formatting directives is always '.'.
|
||||
*/
|
||||
extern char *c_vasnprintf (char *restrict resultbuf, size_t *lengthp,
|
||||
const char *format, va_list args)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _C_VASNPRINTF_H */
|
||||
@@ -1,75 +0,0 @@
|
||||
/* vasprintf and asprintf, in C locale.
|
||||
Copyright (C) 2002-2004, 2006-2024 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_VASPRINTF_H
|
||||
#define _C_VASPRINTF_H
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_FORMAT, _GL_ATTRIBUTE_NODISCARD. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
/* Get va_list. */
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Get ptrdiff_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Prints formatted output to a string dynamically allocated with malloc().
|
||||
If the memory allocation succeeds, it stores the address of the string in
|
||||
*RESULT and returns the number of resulting bytes, excluding the trailing
|
||||
NUL. Upon memory allocation error, or some other error, it returns -1
|
||||
with errno set.
|
||||
|
||||
Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
|
||||
Therefore, if the format string is valid and does not use %ls/%lc
|
||||
directives nor widths, the only possible failure code is ENOMEM.
|
||||
|
||||
Formatting takes place in the C locale, that is, the decimal point
|
||||
used in floating-point formatting directives is always '.'. */
|
||||
_GL_ATTRIBUTE_NODISCARD
|
||||
ptrdiff_t c_aszprintf (char **resultp, const char *format, ...)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3));
|
||||
_GL_ATTRIBUTE_NODISCARD
|
||||
ptrdiff_t c_vaszprintf (char **resultp, const char *format, va_list args)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 0));
|
||||
|
||||
/* Prints formatted output to a string dynamically allocated with malloc().
|
||||
If the memory allocation succeeds, it stores the address of the string in
|
||||
*RESULT and returns the number of resulting bytes, excluding the trailing
|
||||
NUL. Upon memory allocation error, or some other error, it returns -1.
|
||||
|
||||
Formatting takes place in the C locale, that is, the decimal point
|
||||
used in floating-point formatting directives is always '.'. */
|
||||
_GL_ATTRIBUTE_NODISCARD
|
||||
int c_asprintf (char **resultp, const char *format, ...)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3));
|
||||
_GL_ATTRIBUTE_NODISCARD
|
||||
int c_vasprintf (char **resultp, const char *format, va_list args)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 0));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _C_VASPRINTF_H */
|
||||
@@ -1,70 +0,0 @@
|
||||
/* vsnprintf in C locale.
|
||||
Copyright (C) 2012-2024 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_VSNPRINTF_H
|
||||
#define _C_VSNPRINTF_H
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_FORMAT. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
/* Get size_t, ptrdiff_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Get va_list. */
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Prints formatted output to string STR. Similar to vsprintf, but the
|
||||
additional parameter SIZE limits how much is written into STR.
|
||||
STR may be NULL, in which case nothing will be written.
|
||||
Returns the string length of the formatted string (which may be larger
|
||||
than SIZE). Upon failure, returns -1 with errno set.
|
||||
|
||||
Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
|
||||
Therefore, if the format string is valid and does not use %ls/%lc
|
||||
directives nor widths, the only possible failure code is ENOMEM.
|
||||
|
||||
Formatting takes place in the C locale, that is, the decimal point
|
||||
used in floating-point formatting directives is always '.'. */
|
||||
extern ptrdiff_t c_vsnzprintf (char *restrict str, size_t size,
|
||||
const char *format, va_list args)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0));
|
||||
|
||||
/* Prints formatted output to string STR. Similar to sprintf, but the
|
||||
additional parameter SIZE limits how much is written into STR.
|
||||
STR may be NULL, in which case nothing will be written.
|
||||
Returns the string length of the formatted string (which may be larger
|
||||
than SIZE). Upon failure, returns -1 with errno set.
|
||||
|
||||
Formatting takes place in the C locale, that is, the decimal point
|
||||
used in floating-point formatting directives is always '.'. */
|
||||
extern int c_vsnprintf (char *restrict str, size_t size,
|
||||
const char *format, va_list args)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _C_VSNPRINTF_H */
|
||||
@@ -1,67 +0,0 @@
|
||||
/* vasprintf and asprintf, with out-of-memory checking, in C locale.
|
||||
Copyright (C) 2002-2004, 2006-2024 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/>. */
|
||||
|
||||
#ifndef _C_XVASPRINTF_H
|
||||
#define _C_XVASPRINTF_H
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_FORMAT, _GL_ATTRIBUTE_MALLOC,
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
/* Get va_list. */
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Prints formatted output to a string dynamically allocated with malloc(),
|
||||
and returns it. Upon [ENOMEM] memory allocation error, it calls xalloc_die.
|
||||
|
||||
It is the responsibility of the programmer to ensure that
|
||||
- the format string is valid,
|
||||
- the format string does not use %ls or %lc directives, and
|
||||
- all widths in the format string and passed as arguments are >= -INT_MAX
|
||||
and <= INT_MAX,
|
||||
so that other errors
|
||||
- [EINVAL] invalid format string,
|
||||
- [EILSEQ] error during conversion between wide and multibyte characters,
|
||||
- [EOVERFLOW] some specified width is > INT_MAX,
|
||||
cannot occur.
|
||||
|
||||
Formatting takes place in the C locale, that is, the decimal point
|
||||
used in floating-point formatting directives is always '.'. */
|
||||
extern char *c_xasprintf (const char *format, ...)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 1, 2))
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL;
|
||||
extern char *c_xvasprintf (const char *format, va_list args)
|
||||
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 1, 0))
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _C_XVASPRINTF_H */
|
||||
@@ -1,105 +0,0 @@
|
||||
/* Test whether a 32-bit wide character belongs to a specific character class.
|
||||
Copyright (C) 2020-2024 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>, 2020. */
|
||||
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
# include <cygwin/version.h>
|
||||
#endif
|
||||
|
||||
#if GNULIB_defined_mbstate_t
|
||||
# include "localcharset.h"
|
||||
# include "streq.h"
|
||||
#endif
|
||||
|
||||
#if GL_CHAR32_T_IS_UNICODE
|
||||
# include "lc-charset-unicode.h"
|
||||
#endif
|
||||
|
||||
#include "unictype.h"
|
||||
|
||||
#if _GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t
|
||||
_GL_EXTERN_INLINE
|
||||
#endif
|
||||
int
|
||||
FUNC (wint_t wc)
|
||||
{
|
||||
/* The char32_t encoding of a multibyte character is defined by the way
|
||||
mbrtoc32() is defined. */
|
||||
|
||||
#if GNULIB_defined_mbstate_t /* AIX, IRIX */
|
||||
/* mbrtoc32() is defined on top of mbtowc() for the non-UTF-8 locales
|
||||
and directly for the UTF-8 locales. */
|
||||
if (wc != WEOF)
|
||||
{
|
||||
const char *encoding = locale_charset ();
|
||||
if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
|
||||
return UCS_FUNC (wc);
|
||||
else
|
||||
return WCHAR_FUNC (wc);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
#elif HAVE_WORKING_MBRTOC32 && HAVE_WORKING_C32RTOMB /* glibc, Android */
|
||||
/* mbrtoc32() is essentially defined by the system libc. */
|
||||
|
||||
# if _GL_WCHAR_T_IS_UCS4
|
||||
/* The char32_t encoding of a multibyte character is known to be the same as
|
||||
the wchar_t encoding. */
|
||||
return WCHAR_FUNC (wc);
|
||||
# else
|
||||
/* The char32_t encoding of a multibyte character is known to be UCS-4,
|
||||
different from the wchar_t encoding. */
|
||||
if (wc != WEOF)
|
||||
return UCS_FUNC (wc);
|
||||
else
|
||||
return 0;
|
||||
# endif
|
||||
|
||||
#elif _GL_SMALL_WCHAR_T /* Cygwin, mingw, MSVC */
|
||||
/* The wchar_t encoding is UTF-16.
|
||||
The char32_t encoding is UCS-4. */
|
||||
|
||||
# if defined __CYGWIN__ && CYGWIN_VERSION_DLL_MAJOR >= 1007
|
||||
/* As an extension to POSIX, the iswalnum() function of Cygwin >= 1.7
|
||||
supports also wc arguments outside the Unicode BMP, that is, outside
|
||||
the 'wchar_t' range. See
|
||||
<https://lists.gnu.org/archive/html/bug-gnulib/2011-02/msg00019.html>
|
||||
= <https://cygwin.com/ml/cygwin/2011-02/msg00044.html>. */
|
||||
return WCHAR_FUNC (wc);
|
||||
# else
|
||||
if (wc == WEOF || wc == (wchar_t) wc)
|
||||
/* wc is in the range for the isw* functions. */
|
||||
return WCHAR_FUNC (wc);
|
||||
else
|
||||
return UCS_FUNC (wc);
|
||||
# endif
|
||||
|
||||
#else /* macOS, FreeBSD, NetBSD, OpenBSD, HP-UX, Solaris, Minix, Android */
|
||||
/* char32_t and wchar_t are equivalent. */
|
||||
static_assert (sizeof (char32_t) == sizeof (wchar_t));
|
||||
|
||||
# if GL_CHAR32_T_IS_UNICODE && GL_CHAR32_T_VS_WCHAR_T_NEEDS_CONVERSION
|
||||
return UCS_FUNC (wc);
|
||||
# else
|
||||
return WCHAR_FUNC (wc);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/* Case mapping of a 32-bit wide character.
|
||||
Copyright (C) 2020-2024 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>, 2023. */
|
||||
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#if GNULIB_defined_mbstate_t
|
||||
# include "localcharset.h"
|
||||
# include "streq.h"
|
||||
#endif
|
||||
|
||||
#if GL_CHAR32_T_IS_UNICODE
|
||||
# include "lc-charset-unicode.h"
|
||||
#endif
|
||||
|
||||
#include "unicase.h"
|
||||
|
||||
#if _GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t
|
||||
_GL_EXTERN_INLINE
|
||||
#endif
|
||||
wint_t
|
||||
FUNC (wint_t wc)
|
||||
{
|
||||
/* The char32_t encoding of a multibyte character is defined by the way
|
||||
mbrtoc32() is defined. */
|
||||
|
||||
#if GNULIB_defined_mbstate_t /* AIX, IRIX */
|
||||
/* mbrtoc32() is defined on top of mbtowc() for the non-UTF-8 locales
|
||||
and directly for the UTF-8 locales. */
|
||||
if (wc != WEOF)
|
||||
{
|
||||
const char *encoding = locale_charset ();
|
||||
if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
|
||||
return UCS_FUNC (wc);
|
||||
else
|
||||
return WCHAR_FUNC (wc);
|
||||
}
|
||||
else
|
||||
return wc;
|
||||
|
||||
#elif HAVE_WORKING_MBRTOC32 && HAVE_WORKING_C32RTOMB /* glibc, Android */
|
||||
/* mbrtoc32() is essentially defined by the system libc. */
|
||||
|
||||
# if _GL_WCHAR_T_IS_UCS4
|
||||
/* The char32_t encoding of a multibyte character is known to be the same as
|
||||
the wchar_t encoding. */
|
||||
return WCHAR_FUNC (wc);
|
||||
# else
|
||||
/* The char32_t encoding of a multibyte character is known to be UCS-4,
|
||||
different from the wchar_t encoding. */
|
||||
if (wc != WEOF)
|
||||
return UCS_FUNC (wc);
|
||||
else
|
||||
return wc;
|
||||
# endif
|
||||
|
||||
#elif _GL_SMALL_WCHAR_T /* Cygwin, mingw, MSVC */
|
||||
/* The wchar_t encoding is UTF-16.
|
||||
The char32_t encoding is UCS-4. */
|
||||
|
||||
# if defined _WIN32 && !defined __CYGWIN__
|
||||
/* On native Windows, in the UTF-8 locale, towlower and towupper are
|
||||
lacking (at least) the mappings for ISO-8859-1 characters, such as
|
||||
0x00C9 <-> 0x00E9. Since it is expensive to test whether the locale
|
||||
encoding is UTF-8, ignore the system's WCHAR_FUNC altogether. */
|
||||
if (wc != WEOF)
|
||||
return UCS_FUNC (wc);
|
||||
else
|
||||
return wc;
|
||||
# else
|
||||
if (wc == WEOF || wc == (wchar_t) wc)
|
||||
/* wc is in the range for the tow* functions. */
|
||||
return WCHAR_FUNC (wc);
|
||||
else
|
||||
return UCS_FUNC (wc);
|
||||
# endif
|
||||
|
||||
#else /* macOS, FreeBSD, NetBSD, OpenBSD, HP-UX, Solaris, Minix, Android */
|
||||
/* char32_t and wchar_t are equivalent. */
|
||||
static_assert (sizeof (char32_t) == sizeof (wchar_t));
|
||||
|
||||
# if GL_CHAR32_T_IS_UNICODE && GL_CHAR32_T_VS_WCHAR_T_NEEDS_CONVERSION
|
||||
return UCS_FUNC (wc);
|
||||
# else
|
||||
return WCHAR_FUNC (wc);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/* Host name canonicalization
|
||||
|
||||
Copyright (C) 2005, 2009-2024 Free Software Foundation, Inc.
|
||||
|
||||
Written by Derek Price <derek@ximbiot.com>
|
||||
|
||||
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 3 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 CANON_HOST_H
|
||||
#define CANON_HOST_H 1
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_MALLOC. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
# error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
char *canon_host (char const *host)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
char *canon_host_r (char const *host, int *cherror)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
|
||||
const char *ch_strerror (void);
|
||||
#define ch_strerror_r(cherror) gai_strerror (cherror);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !CANON_HOST_H */
|
||||
@@ -1,63 +0,0 @@
|
||||
/* Return the canonical absolute name of a given file.
|
||||
Copyright (C) 1996-2007, 2009-2024 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/>. */
|
||||
|
||||
#ifndef CANONICALIZE_H_
|
||||
# define CANONICALIZE_H_
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_MALLOC. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* for canonicalize_file_name */
|
||||
|
||||
#define CAN_MODE_MASK (CAN_EXISTING | CAN_ALL_BUT_LAST | CAN_MISSING)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum canonicalize_mode_t
|
||||
{
|
||||
/* All components must exist. */
|
||||
CAN_EXISTING = 0,
|
||||
|
||||
/* All components excluding last one must exist. */
|
||||
CAN_ALL_BUT_LAST = 1,
|
||||
|
||||
/* No requirements on components existence. */
|
||||
CAN_MISSING = 2,
|
||||
|
||||
/* Don't expand symlinks. */
|
||||
CAN_NOLINKS = 4
|
||||
};
|
||||
typedef enum canonicalize_mode_t canonicalize_mode_t;
|
||||
|
||||
/* Return the canonical absolute name of file NAME, while treating
|
||||
missing elements according to CAN_MODE. A canonical name
|
||||
does not contain any `.', `..' components nor any repeated file name
|
||||
separators ('/') or, depending on other CAN_MODE flags, symlinks.
|
||||
Whether components must exist or not depends on canonicalize mode.
|
||||
The result is malloc'd.
|
||||
Upon failure, return NULL with errno set. */
|
||||
char *canonicalize_filename_mode (const char *, canonicalize_mode_t)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !CANONICALIZE_H_ */
|
||||
@@ -1,82 +0,0 @@
|
||||
/* Read symbolic links into a buffer without size limitation, relative to fd.
|
||||
|
||||
Copyright (C) 2011-2024 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
|
||||
|
||||
/* This file uses HAVE_READLINKAT. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _GL_CAREADLINKAT_H */
|
||||
@@ -1,715 +0,0 @@
|
||||
/* Copyright (C) 1992-2024 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__ \
|
||||
? 7000000 <= __apple_build_version__ \
|
||||
: 5 <= __clang_major__)))
|
||||
# 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
|
||||
|
||||
|
||||
/* Gnulib avoids these definitions, as they don't work on non-glibc platforms.
|
||||
In particular, __bos and __bos0 are defined differently in the Android libc.
|
||||
*/
|
||||
#ifndef __GNULIB_CDEFS
|
||||
|
||||
/* 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)))) \
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#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,40 +0,0 @@
|
||||
/* provide a chdir function that tries not to fail due to ENAMETOOLONG
|
||||
Copyright (C) 2004-2005, 2009-2024 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. */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "pathmax.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* On systems without PATH_MAX, presume that chdir accepts
|
||||
arbitrarily long directory names. */
|
||||
#ifndef PATH_MAX
|
||||
# define chdir_long(Dir) chdir (Dir)
|
||||
#else
|
||||
int chdir_long (char *dir);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,35 +0,0 @@
|
||||
/* check-version.h --- Check version string compatibility.
|
||||
Copyright (C) 2005, 2009-2024 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 Simon Josefsson. */
|
||||
|
||||
#ifndef CHECK_VERSION_H
|
||||
# define CHECK_VERSION_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
extern const char *
|
||||
check_version (const char *req_version);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CHECK_VERSION_H */
|
||||
@@ -1,47 +0,0 @@
|
||||
/* Java CLASSPATH handling.
|
||||
Copyright (C) 2003, 2009-2024 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <haible@clisp.cons.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/>. */
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_MALLOC. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Return the new CLASSPATH value. The given classpaths are prepended to
|
||||
the current CLASSPATH value. If use_minimal_classpath, the current
|
||||
CLASSPATH is ignored. */
|
||||
extern char * new_classpath (const char * const *classpaths,
|
||||
unsigned int classpaths_count,
|
||||
bool use_minimal_classpath);
|
||||
|
||||
/* Set CLASSPATH and returns a safe copy of its old value. */
|
||||
extern char * set_classpath (const char * const *classpaths,
|
||||
unsigned int classpaths_count,
|
||||
bool use_minimal_classpath, bool verbose)
|
||||
_GL_ATTRIBUTE_MALLOC;
|
||||
|
||||
/* Restore CLASSPATH to its previous value. */
|
||||
extern void reset_classpath (char *old_classpath);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,81 +0,0 @@
|
||||
/* Private interface between modules 'clean-temp-simple' and 'clean-temp'.
|
||||
Copyright (C) 2006-2024 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 _CLEAN_TEMP_PRIVATE_H
|
||||
#define _CLEAN_TEMP_PRIVATE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "gl_list.h"
|
||||
#include "asyncsafe-spin.h"
|
||||
|
||||
/* The use of 'volatile' in the types below (and ISO C 99 section 5.1.2.3.(5))
|
||||
ensure that while constructing or modifying the data structures, the field
|
||||
values are written to memory in the order of the C statements. So the
|
||||
signal handler can rely on these field values to be up to date. */
|
||||
|
||||
/* Registry for a single temporary directory.
|
||||
'struct temp_dir' from the public header file overlaps with this. */
|
||||
struct tempdir
|
||||
{
|
||||
/* The absolute pathname of the directory. */
|
||||
char * volatile dirname;
|
||||
/* Whether errors during explicit cleanup are reported to standard error. */
|
||||
bool cleanup_verbose;
|
||||
/* Absolute pathnames of subdirectories. */
|
||||
gl_list_t /* <char *> */ volatile subdirs;
|
||||
/* Absolute pathnames of files. */
|
||||
gl_list_t /* <char *> */ volatile files;
|
||||
};
|
||||
|
||||
/* List of all temporary directories. */
|
||||
struct all_tempdirs
|
||||
{
|
||||
struct tempdir * volatile * volatile tempdir_list;
|
||||
size_t volatile tempdir_count;
|
||||
size_t tempdir_allocated;
|
||||
};
|
||||
#define dir_cleanup_list clean_temp_dir_cleanup_list
|
||||
extern struct all_tempdirs dir_cleanup_list;
|
||||
|
||||
/* A file descriptor to be closed.
|
||||
In multithreaded programs, it is forbidden to close the same fd twice,
|
||||
because you never know what unrelated open() calls are being executed in
|
||||
other threads. So, the 'close (fd)' must be guarded by a once-only guard. */
|
||||
struct closeable_fd
|
||||
{
|
||||
/* The file descriptor to close. */
|
||||
int volatile fd;
|
||||
/* Set to true when it has been closed. */
|
||||
bool volatile closed;
|
||||
/* Lock that protects the fd from being closed twice. */
|
||||
asyncsafe_spinlock_t lock;
|
||||
/* Tells whether this list element has been done and can be freed. */
|
||||
bool volatile done;
|
||||
};
|
||||
#define descriptors clean_temp_descriptors
|
||||
extern gl_list_t /* <closeable_fd *> */ volatile descriptors;
|
||||
|
||||
extern bool clean_temp_string_equals (const void *x1, const void *x2);
|
||||
extern size_t clean_temp_string_hash (const void *x);
|
||||
|
||||
extern _GL_ASYNC_SAFE int clean_temp_asyncsafe_close (struct closeable_fd *element);
|
||||
extern void clean_temp_init_asyncsafe_close (void);
|
||||
|
||||
extern int clean_temp_init (void);
|
||||
|
||||
extern int clean_temp_unlink (const char *absolute_file_name, bool cleanup_verbose);
|
||||
|
||||
#endif /* _CLEAN_TEMP_PRIVATE_H */
|
||||
@@ -1,50 +0,0 @@
|
||||
/* Temporary files with automatic cleanup.
|
||||
Copyright (C) 2006-2024 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/>. */
|
||||
|
||||
#ifndef _CLEAN_TEMP_SIMPLE_H
|
||||
#define _CLEAN_TEMP_SIMPLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* See clean-temp.h for a general discussion of this module. */
|
||||
|
||||
/* Register the given ABSOLUTE_FILE_NAME as being a file that needs to be
|
||||
removed.
|
||||
Should be called before the file ABSOLUTE_FILE_NAME is created.
|
||||
Return 0 upon success, or -1 if there was a memory allocation problem. */
|
||||
extern int register_temporary_file (const char *absolute_file_name);
|
||||
|
||||
/* Unregister the given ABSOLUTE_FILE_NAME as being a file that needs to be
|
||||
removed.
|
||||
Should be called when the file ABSOLUTE_FILE_NAME could not be created. */
|
||||
extern void unregister_temporary_file (const char *absolute_file_name);
|
||||
|
||||
/* Remove the given ABSOLUTE_FILE_NAME and unregister it.
|
||||
CLEANUP_VERBOSE determines whether errors are reported to standard error.
|
||||
Return 0 upon success, or -1 if there was some problem. */
|
||||
extern int cleanup_temporary_file (const char *absolute_file_name,
|
||||
bool cleanup_verbose);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CLEAN_TEMP_SIMPLE_H */
|
||||
@@ -1,194 +0,0 @@
|
||||
/* Temporary directories and temporary files with automatic cleanup.
|
||||
Copyright (C) 2006, 2011-2024 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2006.
|
||||
|
||||
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 _CLEAN_TEMP_H
|
||||
#define _CLEAN_TEMP_H
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_DEALLOC. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Temporary directories and temporary files should be automatically removed
|
||||
when the program exits either normally or through a fatal signal. We can't
|
||||
rely on the "unlink before close" idiom, because it works only on Unix and
|
||||
also - if no signal blocking is used - leaves a time window where a fatal
|
||||
signal would not clean up the temporary file.
|
||||
|
||||
Also, open file descriptors need to be closed before the temporary files
|
||||
and the temporary directories can be removed, because only on Unix
|
||||
(excluding Cygwin) can one remove directories containing open files.
|
||||
|
||||
There are two modules:
|
||||
- 'clean-temp' provides support for temporary directories and temporary
|
||||
files inside these temporary directories,
|
||||
- 'clean-temp-simple' provides support for temporary files without
|
||||
temporary directories.
|
||||
The temporary directories and files are automatically cleaned up (at the
|
||||
latest) when the program exits or dies from a fatal signal such as SIGINT,
|
||||
SIGTERM, SIGHUP, but not if it dies from a fatal signal such as SIGQUIT,
|
||||
SIGKILL, or SIGABRT, SIGSEGV, SIGBUS, SIGILL, SIGFPE.
|
||||
|
||||
For the cleanup in the normal case, programs that use this module need to
|
||||
call 'cleanup_temp_dir' for each successful return of 'create_temp_dir'.
|
||||
The cleanup in the case of a fatal signal such as SIGINT, SIGTERM, SIGHUP,
|
||||
is done entirely automatically by the functions of this module.
|
||||
|
||||
Limitations: Files or directories can still be left over if
|
||||
- the program is dies from a fatal signal such as SIGQUIT, SIGKILL, or
|
||||
SIGABRT, SIGSEGV, SIGBUS, SIGILL, SIGFPE, or
|
||||
- in a multithreaded program, the fatal signal handler is already running
|
||||
while another thread of the program creates a new temporary directory
|
||||
or temporary file, or
|
||||
- on native Windows, some temporary files are used by a subprocess while
|
||||
the fatal signal interrupts the program.
|
||||
*/
|
||||
|
||||
|
||||
/* ============= Temporary files without temporary directories ============= */
|
||||
|
||||
#include "clean-temp-simple.h"
|
||||
|
||||
/* ========= Temporary directories and temporary files inside them ========= */
|
||||
|
||||
struct temp_dir
|
||||
{
|
||||
/* The absolute pathname of the directory. */
|
||||
const char * const dir_name;
|
||||
/* Whether errors during explicit cleanup are reported to standard error. */
|
||||
bool cleanup_verbose;
|
||||
/* More fields are present here, but not public. */
|
||||
};
|
||||
|
||||
/* Remove all registered files and subdirectories inside DIR and DIR itself.
|
||||
DIR cannot be used any more after this call.
|
||||
Return 0 upon success, or -1 if there was some problem. */
|
||||
extern int cleanup_temp_dir (struct temp_dir *dir);
|
||||
|
||||
/* Create a temporary directory.
|
||||
PREFIX is used as a prefix for the name of the temporary directory. It
|
||||
should be short and still give an indication about the program.
|
||||
PARENTDIR can be used to specify the parent directory; if NULL, a default
|
||||
parent directory is used (either $TMPDIR or /tmp or similar).
|
||||
CLEANUP_VERBOSE determines whether errors during explicit cleanup are
|
||||
reported to standard error.
|
||||
Return a fresh 'struct temp_dir' on success. Upon error, an error message
|
||||
is shown and NULL is returned. */
|
||||
extern struct temp_dir * create_temp_dir (const char *prefix,
|
||||
const char *parentdir,
|
||||
bool cleanup_verbose)
|
||||
_GL_ATTRIBUTE_DEALLOC (cleanup_temp_dir, 1);
|
||||
|
||||
/* Register the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
|
||||
needs to be removed before DIR can be removed.
|
||||
Should be called before the file ABSOLUTE_FILE_NAME is created. */
|
||||
extern void register_temp_file (struct temp_dir *dir,
|
||||
const char *absolute_file_name);
|
||||
|
||||
/* Unregister the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
|
||||
needs to be removed before DIR can be removed.
|
||||
Should be called when the file ABSOLUTE_FILE_NAME could not be created. */
|
||||
extern void unregister_temp_file (struct temp_dir *dir,
|
||||
const char *absolute_file_name);
|
||||
|
||||
/* Register the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
|
||||
that needs to be removed before DIR can be removed.
|
||||
Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */
|
||||
extern void register_temp_subdir (struct temp_dir *dir,
|
||||
const char *absolute_dir_name);
|
||||
|
||||
/* Unregister the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
|
||||
that needs to be removed before DIR can be removed.
|
||||
Should be called when the subdirectory ABSOLUTE_DIR_NAME could not be
|
||||
created. */
|
||||
extern void unregister_temp_subdir (struct temp_dir *dir,
|
||||
const char *absolute_dir_name);
|
||||
|
||||
/* Remove the given ABSOLUTE_FILE_NAME and unregister it.
|
||||
Return 0 upon success, or -1 if there was some problem. */
|
||||
extern int cleanup_temp_file (struct temp_dir *dir,
|
||||
const char *absolute_file_name);
|
||||
|
||||
/* Remove the given ABSOLUTE_DIR_NAME and unregister it.
|
||||
Return 0 upon success, or -1 if there was some problem. */
|
||||
extern int cleanup_temp_subdir (struct temp_dir *dir,
|
||||
const char *absolute_dir_name);
|
||||
|
||||
/* Remove all registered files and subdirectories inside DIR.
|
||||
Return 0 upon success, or -1 if there was some problem. */
|
||||
extern int cleanup_temp_dir_contents (struct temp_dir *dir);
|
||||
|
||||
/* ================== Opening and closing temporary files ================== */
|
||||
|
||||
/* Open a temporary file in a temporary directory.
|
||||
FILE_NAME must already have been passed to register_temp_file.
|
||||
Registers the resulting file descriptor to be closed.
|
||||
DELETE_ON_CLOSE indicates whether the file can be deleted when the resulting
|
||||
file descriptor or stream is closed. */
|
||||
extern int open_temp (const char *file_name, int flags, mode_t mode,
|
||||
bool delete_on_close);
|
||||
extern FILE * fopen_temp (const char *file_name, const char *mode,
|
||||
bool delete_on_close);
|
||||
|
||||
/* Open a temporary file, generating its name based on FILE_NAME_TMPL.
|
||||
FILE_NAME_TMPL must match the rules for mk[s]temp (i.e. end in "XXXXXX",
|
||||
possibly with a suffix). The name constructed does not exist at the time
|
||||
of the call. FILE_NAME_TMPL is overwritten with the result.
|
||||
A safe choice for MODE is S_IRUSR | S_IWUSR, a.k.a. 0600.
|
||||
Registers the file for deletion.
|
||||
Opens the file, with the given FLAGS and mode MODE.
|
||||
Registers the resulting file descriptor to be closed. */
|
||||
extern int gen_register_open_temp (char *file_name_tmpl, int suffixlen,
|
||||
int flags, mode_t mode);
|
||||
|
||||
/* Close a temporary file.
|
||||
FD must have been returned by open_temp or gen_register_open_temp.
|
||||
Unregisters the previously registered file descriptor. */
|
||||
extern int close_temp (int fd);
|
||||
|
||||
/* Close a temporary file.
|
||||
FP must have been returned by fopen_temp, or by fdopen on a file descriptor
|
||||
returned by open_temp or gen_register_open_temp.
|
||||
Unregisters the previously registered file descriptor. */
|
||||
extern int fclose_temp (FILE *fp);
|
||||
|
||||
/* Like fwriteerror.
|
||||
FP must have been returned by fopen_temp, or by fdopen on a file descriptor
|
||||
returned by open_temp or gen_register_open_temp.
|
||||
Unregisters the previously registered file descriptor. */
|
||||
extern int fwriteerror_temp (FILE *fp);
|
||||
|
||||
/* Like close_stream.
|
||||
FP must have been returned by fopen_temp, or by fdopen on a file descriptor
|
||||
returned by open_temp or gen_register_open_temp.
|
||||
Unregisters the previously registered file descriptor. */
|
||||
extern int close_stream_temp (FILE *fp);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CLEAN_TEMP_H */
|
||||
@@ -1,44 +0,0 @@
|
||||
/* cloexec.c - set or clear the close-on-exec descriptor flag
|
||||
|
||||
Copyright (C) 2004, 2009-2024 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/>. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,30 +0,0 @@
|
||||
/* Close a stream, with nicer error checking than fclose's.
|
||||
|
||||
Copyright (C) 2006-2024 Free Software Foundation, Inc.
|
||||
|
||||
This file 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 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 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/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
int close_stream (FILE *stream);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,32 +0,0 @@
|
||||
/* Close standard input, rewinding seekable stdin if necessary.
|
||||
|
||||
Copyright (C) 2007, 2009-2024 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/>. */
|
||||
|
||||
#ifndef _GL_CLOSEIN_H
|
||||
# define _GL_CLOSEIN_H 1
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
void close_stdin_set_file_name (const char *file);
|
||||
void close_stdin (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@@ -1,34 +0,0 @@
|
||||
/* Close standard output and standard error.
|
||||
|
||||
Copyright (C) 1998, 2000, 2003-2004, 2006, 2008-2024 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/>. */
|
||||
|
||||
#ifndef CLOSEOUT_H
|
||||
# define CLOSEOUT_H 1
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
void close_stdout_set_file_name (const char *file);
|
||||
void close_stdout_set_ignore_EPIPE (bool ignore);
|
||||
void close_stdout (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@@ -1,51 +0,0 @@
|
||||
/* Construct a full filename from a directory and a relative filename.
|
||||
Copyright (C) 2001-2004, 2007-2024 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 _CONCAT_FILENAME_H
|
||||
#define _CONCAT_FILENAME_H
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_RETURNS_NONNULL. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Concatenate a directory filename, a relative filename and an optional
|
||||
suffix. Return a freshly allocated filename. Return NULL and set errno
|
||||
upon memory allocation failure. */
|
||||
extern char *concatenated_filename (const char *directory,
|
||||
const char *filename, const char *suffix)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
|
||||
/* Concatenate a directory filename, a relative filename and an optional
|
||||
suffix. Return a freshly allocated filename. */
|
||||
extern char *xconcatenated_filename (const char *directory,
|
||||
const char *filename, const char *suffix)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CONCAT_FILENAME_H */
|
||||
@@ -1,83 +0,0 @@
|
||||
/* Copying of files.
|
||||
Copyright (C) 2001-2003, 2009-2024 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/>. */
|
||||
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_DEPRECATED. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Error codes returned by qcopy_file_preserving or copy_file_to. */
|
||||
enum
|
||||
{
|
||||
GL_COPY_ERR_OPEN_READ = -1,
|
||||
GL_COPY_ERR_OPEN_BACKUP_WRITE = -2,
|
||||
GL_COPY_ERR_READ = -3,
|
||||
GL_COPY_ERR_WRITE = -4,
|
||||
GL_COPY_ERR_AFTER_READ = -5,
|
||||
GL_COPY_ERR_GET_ACL = -6,
|
||||
GL_COPY_ERR_SET_ACL = -7
|
||||
};
|
||||
|
||||
|
||||
/* Copy a regular file: from src_filename to dest_filename.
|
||||
The destination file is assumed to be a backup file.
|
||||
Modification times, owner, group and access permissions are preserved as
|
||||
far as possible (similarly to what 'cp -p SRC DEST' would do).
|
||||
Return 0 if successful, otherwise set errno and return one of the error
|
||||
codes above. */
|
||||
extern int qcopy_file_preserving (const char *src_filename, const char *dest_filename);
|
||||
|
||||
/* Copy a regular file: from src_filename to dest_filename.
|
||||
The destination file is assumed to be a backup file.
|
||||
Modification times, owner, group and access permissions are preserved as
|
||||
far as possible (similarly to what 'cp -p SRC DEST' would do).
|
||||
Exit upon failure. */
|
||||
extern void xcopy_file_preserving (const char *src_filename, const char *dest_filename);
|
||||
|
||||
/* Old name of xcopy_file_preserving. */
|
||||
_GL_ATTRIBUTE_DEPRECATED void copy_file_preserving (const char *src_filename, const char *dest_filename);
|
||||
|
||||
|
||||
/* Copy a regular file: from src_filename to dest_filename.
|
||||
The source file is assumed to be not confidential.
|
||||
Modification times, owner, group and access permissions of src_filename
|
||||
are *not* copied over to dest_filename (similarly to what 'cat SRC > DEST'
|
||||
would do; if DEST already exists, this is the same as what 'cp SRC DEST'
|
||||
would do.)
|
||||
Return 0 if successful, otherwise set errno and return one of the error
|
||||
codes above. */
|
||||
extern int copy_file_to (const char *src_filename, const char *dest_filename);
|
||||
|
||||
/* Copy a regular file: from src_filename to dest_filename.
|
||||
The source file is assumed to be not confidential.
|
||||
Modification times, owner, group and access permissions of src_filename
|
||||
are *not* copied over to dest_filename (similarly to what 'cat SRC > DEST'
|
||||
would do; if DEST already exists, this is the same as what 'cp SRC DEST'
|
||||
would do.)
|
||||
Exit upon failure. */
|
||||
extern void xcopy_file_to (const char *src_filename, const char *dest_filename);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,140 +0,0 @@
|
||||
/* count-leading-zeros.h -- counts the number of leading 0 bits in a word.
|
||||
Copyright (C) 2012-2024 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. */
|
||||
|
||||
#ifndef COUNT_LEADING_ZEROS_H
|
||||
#define COUNT_LEADING_ZEROS_H 1
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef COUNT_LEADING_ZEROS_INLINE
|
||||
# define COUNT_LEADING_ZEROS_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Assuming the GCC builtin is BUILTIN and the MSC builtin is MSC_BUILTIN,
|
||||
expand to code that computes the number of leading zeros of the local
|
||||
variable 'x' of type TYPE (an unsigned integer type) and return it
|
||||
from the current function. */
|
||||
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) \
|
||||
|| (__clang_major__ >= 4)
|
||||
# define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
|
||||
return x ? BUILTIN (x) : CHAR_BIT * sizeof x;
|
||||
#elif _MSC_VER
|
||||
extern unsigned char _BitScanReverse (unsigned long *, unsigned long);
|
||||
# pragma intrinsic (_BitScanReverse)
|
||||
# if defined _M_X64
|
||||
extern unsigned char _BitScanReverse64 (unsigned long *, unsigned long long);
|
||||
# pragma intrinsic (_BitScanReverse64)
|
||||
# endif
|
||||
# define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
|
||||
do \
|
||||
{ \
|
||||
unsigned long result; \
|
||||
if (MSC_BUILTIN (&result, x)) \
|
||||
return CHAR_BIT * sizeof x - 1 - result; \
|
||||
return CHAR_BIT * sizeof x; \
|
||||
} \
|
||||
while (0)
|
||||
#else
|
||||
# define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
|
||||
do \
|
||||
{ \
|
||||
int count; \
|
||||
unsigned int leading_32; \
|
||||
if (! x) \
|
||||
return CHAR_BIT * sizeof x; \
|
||||
for (count = 0; \
|
||||
(leading_32 = ((x >> (sizeof (TYPE) * CHAR_BIT - 32)) \
|
||||
& 0xffffffffU), \
|
||||
count < CHAR_BIT * sizeof x - 32 && !leading_32); \
|
||||
count += 32) \
|
||||
x = x << 31 << 1; \
|
||||
return count + count_leading_zeros_32 (leading_32); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* Compute and return the number of leading zeros in X,
|
||||
where 0 < X < 2**32. */
|
||||
COUNT_LEADING_ZEROS_INLINE int
|
||||
count_leading_zeros_32 (unsigned int x)
|
||||
{
|
||||
/* <https://github.com/gibsjose/BitHacks>
|
||||
<https://www.fit.vutbr.cz/~ibarina/pub/bithacks.pdf> */
|
||||
static const char de_Bruijn_lookup[32] = {
|
||||
31, 22, 30, 21, 18, 10, 29, 2, 20, 17, 15, 13, 9, 6, 28, 1,
|
||||
23, 19, 11, 3, 16, 14, 7, 24, 12, 4, 8, 25, 5, 26, 27, 0
|
||||
};
|
||||
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
return de_Bruijn_lookup[((x * 0x07c4acddU) & 0xffffffffU) >> 27];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Compute and return the number of leading zeros in X. */
|
||||
COUNT_LEADING_ZEROS_INLINE int
|
||||
count_leading_zeros (unsigned int x)
|
||||
{
|
||||
COUNT_LEADING_ZEROS (__builtin_clz, _BitScanReverse, unsigned int);
|
||||
}
|
||||
|
||||
/* Compute and return the number of leading zeros in X. */
|
||||
COUNT_LEADING_ZEROS_INLINE int
|
||||
count_leading_zeros_l (unsigned long int x)
|
||||
{
|
||||
COUNT_LEADING_ZEROS (__builtin_clzl, _BitScanReverse, unsigned long int);
|
||||
}
|
||||
|
||||
/* Compute and return the number of leading zeros in X. */
|
||||
COUNT_LEADING_ZEROS_INLINE int
|
||||
count_leading_zeros_ll (unsigned long long int x)
|
||||
{
|
||||
#if (defined _MSC_VER && !defined __clang__) && !defined _M_X64
|
||||
/* 32-bit MSVC does not have _BitScanReverse64, only _BitScanReverse. */
|
||||
unsigned long result;
|
||||
if (_BitScanReverse (&result, (unsigned long) (x >> 32)))
|
||||
return CHAR_BIT * sizeof x - 1 - 32 - result;
|
||||
if (_BitScanReverse (&result, (unsigned long) x))
|
||||
return CHAR_BIT * sizeof x - 1 - result;
|
||||
return CHAR_BIT * sizeof x;
|
||||
#else
|
||||
COUNT_LEADING_ZEROS (__builtin_clzll, _BitScanReverse64,
|
||||
unsigned long long int);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif /* COUNT_LEADING_ZEROS_H */
|
||||
@@ -1,169 +0,0 @@
|
||||
/* count-one-bits.h -- counts the number of 1-bits in a word.
|
||||
Copyright (C) 2007-2024 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 Ben Pfaff. */
|
||||
|
||||
#ifndef COUNT_ONE_BITS_H
|
||||
#define COUNT_ONE_BITS_H 1
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef COUNT_ONE_BITS_INLINE
|
||||
# define COUNT_ONE_BITS_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Assuming the GCC builtin is GCC_BUILTIN and the MSC builtin is MSC_BUILTIN,
|
||||
expand to code that computes the number of 1-bits of the local
|
||||
variable 'x' of type TYPE (an unsigned integer type) and return it
|
||||
from the current function. */
|
||||
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \
|
||||
|| (__clang_major__ >= 4)
|
||||
# define COUNT_ONE_BITS(GCC_BUILTIN, MSC_BUILTIN, TYPE) \
|
||||
return GCC_BUILTIN (x)
|
||||
#else
|
||||
|
||||
/* Compute and return the number of 1-bits set in the least
|
||||
significant 32 bits of X. */
|
||||
COUNT_ONE_BITS_INLINE int
|
||||
count_one_bits_32 (unsigned int x)
|
||||
{
|
||||
x = ((x & 0xaaaaaaaaU) >> 1) + (x & 0x55555555U);
|
||||
x = ((x & 0xccccccccU) >> 2) + (x & 0x33333333U);
|
||||
x = (x >> 16) + (x & 0xffff);
|
||||
x = ((x & 0xf0f0) >> 4) + (x & 0x0f0f);
|
||||
return (x >> 8) + (x & 0x00ff);
|
||||
}
|
||||
|
||||
/* Expand to code that computes the number of 1-bits of the local
|
||||
variable 'x' of type TYPE (an unsigned integer type) and return it
|
||||
from the current function. */
|
||||
# define COUNT_ONE_BITS_GENERIC(TYPE) \
|
||||
do \
|
||||
{ \
|
||||
int count = 0; \
|
||||
int bits; \
|
||||
for (bits = 0; bits < sizeof (TYPE) * CHAR_BIT; bits += 32) \
|
||||
{ \
|
||||
count += count_one_bits_32 (x); \
|
||||
x = x >> 31 >> 1; \
|
||||
} \
|
||||
return count; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# if 1500 <= _MSC_VER && (defined _M_IX86 || defined _M_X64)
|
||||
|
||||
/* While gcc falls back to its own generic code if the machine
|
||||
on which it's running doesn't support popcount, with Microsoft's
|
||||
compiler we need to detect and fallback ourselves. */
|
||||
|
||||
# if 0
|
||||
# include <intrin.h>
|
||||
# else
|
||||
/* Don't pollute the namespace with too many MSVC intrinsics. */
|
||||
extern void __cpuid (int[4], int);
|
||||
# pragma intrinsic (__cpuid)
|
||||
extern unsigned int __popcnt (unsigned int);
|
||||
# pragma intrinsic (__popcnt)
|
||||
# if defined _M_X64
|
||||
extern unsigned long long __popcnt64 (unsigned long long);
|
||||
# pragma intrinsic (__popcnt64)
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if !defined _M_X64
|
||||
static inline __popcnt64 (unsigned long long x)
|
||||
{
|
||||
return __popcnt ((unsigned int) (x >> 32)) + __popcnt ((unsigned int) x);
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Return nonzero if popcount is supported. */
|
||||
|
||||
/* 1 if supported, 0 if not supported, -1 if unknown. */
|
||||
extern int popcount_support;
|
||||
|
||||
COUNT_ONE_BITS_INLINE int
|
||||
popcount_supported (void)
|
||||
{
|
||||
if (popcount_support < 0)
|
||||
{
|
||||
/* Do as described in
|
||||
<https://docs.microsoft.com/en-us/cpp/intrinsics/popcnt16-popcnt-popcnt64> */
|
||||
int cpu_info[4];
|
||||
__cpuid (cpu_info, 1);
|
||||
popcount_support = (cpu_info[2] >> 23) & 1;
|
||||
}
|
||||
return popcount_support;
|
||||
}
|
||||
|
||||
# define COUNT_ONE_BITS(GCC_BUILTIN, MSC_BUILTIN, TYPE) \
|
||||
do \
|
||||
{ \
|
||||
if (popcount_supported ()) \
|
||||
return MSC_BUILTIN (x); \
|
||||
else \
|
||||
COUNT_ONE_BITS_GENERIC (TYPE); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# else
|
||||
|
||||
# define COUNT_ONE_BITS(GCC_BUILTIN, MSC_BUILTIN, TYPE) \
|
||||
COUNT_ONE_BITS_GENERIC (TYPE)
|
||||
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Compute and return the number of 1-bits set in X. */
|
||||
COUNT_ONE_BITS_INLINE int
|
||||
count_one_bits (unsigned int x)
|
||||
{
|
||||
COUNT_ONE_BITS (__builtin_popcount, __popcnt, unsigned int);
|
||||
}
|
||||
|
||||
/* Compute and return the number of 1-bits set in X. */
|
||||
COUNT_ONE_BITS_INLINE int
|
||||
count_one_bits_l (unsigned long int x)
|
||||
{
|
||||
COUNT_ONE_BITS (__builtin_popcountl, __popcnt, unsigned long int);
|
||||
}
|
||||
|
||||
/* Compute and return the number of 1-bits set in X. */
|
||||
COUNT_ONE_BITS_INLINE int
|
||||
count_one_bits_ll (unsigned long long int x)
|
||||
{
|
||||
COUNT_ONE_BITS (__builtin_popcountll, __popcnt64, unsigned long long int);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif /* COUNT_ONE_BITS_H */
|
||||
@@ -1,130 +0,0 @@
|
||||
/* count-trailing-zeros.h -- counts the number of trailing 0 bits in a word.
|
||||
Copyright 2013-2024 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 COUNT_TRAILING_ZEROS_H
|
||||
#define COUNT_TRAILING_ZEROS_H 1
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef COUNT_TRAILING_ZEROS_INLINE
|
||||
# define COUNT_TRAILING_ZEROS_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Assuming the GCC builtin is BUILTIN and the MSC builtin is MSC_BUILTIN,
|
||||
expand to code that computes the number of trailing zeros of the local
|
||||
variable 'x' of type TYPE (an unsigned integer type) and return it
|
||||
from the current function. */
|
||||
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) \
|
||||
|| (__clang_major__ >= 4)
|
||||
# define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
|
||||
return x ? BUILTIN (x) : CHAR_BIT * sizeof x;
|
||||
#elif _MSC_VER
|
||||
extern unsigned char _BitScanForward (unsigned long *, unsigned long);
|
||||
# pragma intrinsic (_BitScanForward)
|
||||
# if defined _M_X64
|
||||
extern unsigned char _BitScanForward64 (unsigned long *, unsigned long long);
|
||||
# pragma intrinsic (_BitScanForward64)
|
||||
# endif
|
||||
# define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
|
||||
do \
|
||||
{ \
|
||||
unsigned long result; \
|
||||
return MSC_BUILTIN (&result, x) ? result : CHAR_BIT * sizeof x; \
|
||||
} \
|
||||
while (0)
|
||||
#else
|
||||
# define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
|
||||
do \
|
||||
{ \
|
||||
int count = 0; \
|
||||
if (! x) \
|
||||
return CHAR_BIT * sizeof x; \
|
||||
for (count = 0; \
|
||||
(count < CHAR_BIT * sizeof x - 32 \
|
||||
&& ! (x & 0xffffffffU)); \
|
||||
count += 32) \
|
||||
x = x >> 31 >> 1; \
|
||||
return count + count_trailing_zeros_32 (x); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* Compute and return the number of trailing zeros in the least
|
||||
significant 32 bits of X. One of these bits must be nonzero. */
|
||||
COUNT_TRAILING_ZEROS_INLINE int
|
||||
count_trailing_zeros_32 (unsigned int x)
|
||||
{
|
||||
/* <https://github.com/gibsjose/BitHacks>
|
||||
<https://www.fit.vutbr.cz/~ibarina/pub/bithacks.pdf> */
|
||||
static const char de_Bruijn_lookup[32] = {
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
|
||||
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
|
||||
};
|
||||
return de_Bruijn_lookup[(((x & -x) * 0x077cb531U) & 0xffffffffU) >> 27];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Compute and return the number of trailing zeros in X. */
|
||||
COUNT_TRAILING_ZEROS_INLINE int
|
||||
count_trailing_zeros (unsigned int x)
|
||||
{
|
||||
COUNT_TRAILING_ZEROS (__builtin_ctz, _BitScanForward, unsigned int);
|
||||
}
|
||||
|
||||
/* Compute and return the number of trailing zeros in X. */
|
||||
COUNT_TRAILING_ZEROS_INLINE int
|
||||
count_trailing_zeros_l (unsigned long int x)
|
||||
{
|
||||
COUNT_TRAILING_ZEROS (__builtin_ctzl, _BitScanForward, unsigned long int);
|
||||
}
|
||||
|
||||
/* Compute and return the number of trailing zeros in X. */
|
||||
COUNT_TRAILING_ZEROS_INLINE int
|
||||
count_trailing_zeros_ll (unsigned long long int x)
|
||||
{
|
||||
#if (defined _MSC_VER && !defined __clang__) && !defined _M_X64
|
||||
/* 32-bit MSVC does not have _BitScanForward64, only _BitScanForward. */
|
||||
unsigned long result;
|
||||
if (_BitScanForward (&result, (unsigned long) x))
|
||||
return result;
|
||||
if (_BitScanForward (&result, (unsigned long) (x >> 32)))
|
||||
return result + 32;
|
||||
return CHAR_BIT * sizeof x;
|
||||
#else
|
||||
COUNT_TRAILING_ZEROS (__builtin_ctzll, _BitScanForward64,
|
||||
unsigned long long int);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif
|
||||
@@ -1,60 +0,0 @@
|
||||
/* crc.h -- cyclic redundancy checks
|
||||
Copyright (C) 2005, 2009-2024 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 3 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 Simon Josefsson. */
|
||||
|
||||
#ifndef CRC_H
|
||||
#define CRC_H 1
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Compute CRC-32 value of LEN bytes long BUF, and return it. */
|
||||
extern uint32_t crc32 (const char *buf, size_t len) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* Incrementally update CRC-32 value CRC using LEN bytes long BUF. In
|
||||
the first call, use 0 as the value for CRC. Return the updated
|
||||
CRC-32 value. */
|
||||
extern uint32_t crc32_update (uint32_t crc, const char *buf, size_t len)
|
||||
_GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* Compute modified-CRC-32 value of LEN bytes long BUF, and return it.
|
||||
The "modification" is to avoid the initial and final XOR operation.
|
||||
Due to historic implementation errors, this variant is sometimes
|
||||
used (i.e., in RFC 3961). */
|
||||
extern uint32_t crc32_no_xor (const char *buf, size_t len)
|
||||
_GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* Incrementally update modified-CRC-32 value CRC using LEN bytes long
|
||||
BUF. In the first call, use 0 as the value for CRC. Return the
|
||||
updated modified-CRC-32 value. The "modification" is to avoid the
|
||||
initial and final XOR operation. Due to historic implementation
|
||||
errors, this variant is sometimes used (i.e., in RFC 3961). */
|
||||
extern uint32_t
|
||||
crc32_update_no_xor (uint32_t crc, const char *buf, size_t len)
|
||||
_GL_ATTRIBUTE_PURE;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRC_H */
|
||||
@@ -1,48 +0,0 @@
|
||||
/* Compile a C# program.
|
||||
Copyright (C) 2003, 2009-2024 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/>. */
|
||||
|
||||
#ifndef _CSHARPCOMP_H
|
||||
#define _CSHARPCOMP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Compile a set of C# source files to bytecode.
|
||||
sources is an array of source file names, including resource files.
|
||||
libdirs is a list of directories to be searched for libraries.
|
||||
libraries is a list of libraries on which the program depends.
|
||||
output_file is the name of the output file; it should end in .exe or .dll.
|
||||
If verbose, the command to be executed will be printed.
|
||||
Return false if OK, true on error. */
|
||||
extern bool compile_csharp_class (const char * const *sources,
|
||||
unsigned int sources_count,
|
||||
const char * const *libdirs,
|
||||
unsigned int libdirs_count,
|
||||
const char * const *libraries,
|
||||
unsigned int libraries_count,
|
||||
const char *output_file,
|
||||
bool optimize, bool debug,
|
||||
bool verbose);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CSHARPCOMP_H */
|
||||
@@ -1,51 +0,0 @@
|
||||
/* Execute a C# program.
|
||||
Copyright (C) 2003, 2009-2024 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/>. */
|
||||
|
||||
#ifndef _CSHARPEXEC_H
|
||||
#define _CSHARPEXEC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef bool execute_fn (const char *progname,
|
||||
const char *prog_path, const char * const *prog_argv,
|
||||
void *private_data);
|
||||
|
||||
/* Execute a C# program.
|
||||
assembly_path is the assembly's pathname (= program name with .exe).
|
||||
libdirs is a list of directories to be searched for libraries.
|
||||
args is a NULL terminated list of arguments to be passed to the program.
|
||||
If verbose, the command to be executed will be printed.
|
||||
Then the command is passed to the execute function together with the
|
||||
private_data argument. This function returns false if OK, true on error.
|
||||
Return false if OK, true on error.
|
||||
If quiet, error messages will not be printed. */
|
||||
extern bool execute_csharp_program (const char *assembly_path,
|
||||
const char * const *libdirs,
|
||||
unsigned int libdirs_count,
|
||||
const char * const *args,
|
||||
bool verbose, bool quiet,
|
||||
execute_fn *executer, void *private_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CSHARPEXEC_H */
|
||||
@@ -1,61 +0,0 @@
|
||||
/* help detect directory cycles efficiently
|
||||
|
||||
Copyright (C) 2003-2004, 2006, 2009-2024 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 CYCLE_CHECK_H
|
||||
#define CYCLE_CHECK_H 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include "dev-ino.h"
|
||||
#include "same-inode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct cycle_check_state
|
||||
{
|
||||
struct dev_ino dev_ino;
|
||||
uintmax_t chdir_counter;
|
||||
int magic;
|
||||
};
|
||||
|
||||
void cycle_check_init (struct cycle_check_state *state);
|
||||
bool cycle_check (struct cycle_check_state *state, struct stat const *sb);
|
||||
|
||||
#define CYCLE_CHECK_REFLECT_CHDIR_UP(State, SB_dir, SB_subdir) \
|
||||
do \
|
||||
{ \
|
||||
/* You must call cycle_check at least once before using this macro. */ \
|
||||
if ((State)->chdir_counter == 0) \
|
||||
abort (); \
|
||||
if (SAME_INODE ((State)->dev_ino, SB_subdir)) \
|
||||
{ \
|
||||
(State)->dev_ino.st_dev = (SB_dir).st_dev; \
|
||||
(State)->dev_ino.st_ino = (SB_dir).st_ino; \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,37 +0,0 @@
|
||||
/* Convert file names between Cygwin syntax and Windows syntax.
|
||||
Copyright (C) 2024 Free Software Foundation, Inc.
|
||||
|
||||
This file 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 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 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 Bruno Haible <bruno@clisp.org>, 2024. */
|
||||
|
||||
#ifndef _CYGPATH_H
|
||||
#define _CYGPATH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* On Cygwin, this function converts a file name from Cygwin syntax to
|
||||
native Windows syntax, like 'cygpath -w' does.
|
||||
Returns a freshly allocated file name.
|
||||
On the other platforms, it returns a freshly allocated copy of the
|
||||
argument file name. */
|
||||
extern char *cygpath_w (const char *filename);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CYGPATH_H */
|
||||
@@ -1,128 +0,0 @@
|
||||
/* des.h --- DES cipher implementation.
|
||||
* Copyright (C) 2005, 2007, 2009-2024 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Adapted for gnulib by Simon Josefsson, based on Libgcrypt. */
|
||||
|
||||
#ifndef DES_H
|
||||
#define DES_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Encryption/Decryption context of DES
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t encrypt_subkeys[32];
|
||||
uint32_t decrypt_subkeys[32];
|
||||
} gl_des_ctx;
|
||||
|
||||
/*
|
||||
* Encryption/Decryption context of Triple-DES
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t encrypt_subkeys[96];
|
||||
uint32_t decrypt_subkeys[96];
|
||||
} gl_3des_ctx;
|
||||
|
||||
/* Check whether the 8 byte key is weak. Does not check the parity
|
||||
* bits of the key but simple ignore them. */
|
||||
extern bool
|
||||
gl_des_is_weak_key (const char * key);
|
||||
|
||||
/*
|
||||
* DES
|
||||
* ---
|
||||
*/
|
||||
|
||||
/* Fill a DES context CTX with subkeys calculated from 64bit KEY.
|
||||
* Does not check parity bits, but simply ignore them. Does not check
|
||||
* for weak keys. */
|
||||
extern void
|
||||
gl_des_setkey (gl_des_ctx *ctx, const char * key);
|
||||
|
||||
/* Fill a DES context CTX with subkeys calculated from 64bit KEY, with
|
||||
* weak key checking. Does not check parity bits, but simply ignore
|
||||
* them. */
|
||||
extern bool
|
||||
gl_des_makekey (gl_des_ctx *ctx, const char * key, size_t keylen);
|
||||
|
||||
/* Electronic Codebook Mode DES encryption/decryption of data
|
||||
* according to 'mode'. */
|
||||
extern void
|
||||
gl_des_ecb_crypt (gl_des_ctx *ctx, const char * from, char * to, int mode);
|
||||
|
||||
#define gl_des_ecb_encrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 0)
|
||||
#define gl_des_ecb_decrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 1)
|
||||
|
||||
/* Triple-DES
|
||||
* ----------
|
||||
*/
|
||||
|
||||
/* Fill a Triple-DES context CTX with subkeys calculated from two
|
||||
* 64bit keys in KEY1 and KEY2. Does not check the parity bits of the
|
||||
* keys, but simply ignore them. Does not check for weak keys. */
|
||||
extern void
|
||||
gl_3des_set2keys (gl_3des_ctx *ctx,
|
||||
const char * key1,
|
||||
const char * key2);
|
||||
|
||||
/*
|
||||
* Fill a Triple-DES context CTX with subkeys calculated from three
|
||||
* 64bit keys in KEY1, KEY2 and KEY3. Does not check the parity bits
|
||||
* of the keys, but simply ignore them. Does not check for weak
|
||||
* keys. */
|
||||
extern void
|
||||
gl_3des_set3keys (gl_3des_ctx *ctx,
|
||||
const char * key1,
|
||||
const char * key2,
|
||||
const char * key3);
|
||||
|
||||
/* Fill a Triple-DES context CTX with subkeys calculated from three
|
||||
* concatenated 64bit keys in KEY, with weak key checking. Does not
|
||||
* check the parity bits of the keys, but simply ignore them. */
|
||||
extern bool
|
||||
gl_3des_makekey (gl_3des_ctx *ctx,
|
||||
const char * key,
|
||||
size_t keylen);
|
||||
|
||||
/* Electronic Codebook Mode Triple-DES encryption/decryption of data
|
||||
* according to 'mode'. Sometimes this mode is named 'EDE' mode
|
||||
* (Encryption-Decryption-Encryption). */
|
||||
extern void
|
||||
gl_3des_ecb_crypt (gl_3des_ctx *ctx,
|
||||
const char * from,
|
||||
char * to,
|
||||
int mode);
|
||||
|
||||
#define gl_3des_ecb_encrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,0)
|
||||
#define gl_3des_ecb_decrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,1)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DES_H */
|
||||
@@ -1,41 +0,0 @@
|
||||
/* A simple (device, inode) struct.
|
||||
Copyright (C) 2003-2024 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, 2003. */
|
||||
|
||||
#ifndef DEV_INO_H
|
||||
#define DEV_INO_H 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct dev_ino
|
||||
{
|
||||
ino_t st_ino;
|
||||
dev_t st_dev;
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,178 +0,0 @@
|
||||
/* dfa.h - declarations for GNU deterministic regexp compiler
|
||||
Copyright (C) 1988, 1998, 2007, 2009-2024 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, 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 June, 1988 by Mike Haertel */
|
||||
|
||||
#ifndef DFA_H_
|
||||
#define DFA_H_
|
||||
|
||||
/* This file uses _Noreturn, _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC,
|
||||
_GL_ATTRIBUTE_PURE, _GL_ATTRIBUTE_RETURNS_NONNULL. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include "idx.h"
|
||||
#include <regex.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct localeinfo; /* See localeinfo.h. */
|
||||
|
||||
/* Element of a list of strings, at least one of which is known to
|
||||
appear in any R.E. matching the DFA. */
|
||||
struct dfamust
|
||||
{
|
||||
bool exact;
|
||||
bool begline;
|
||||
bool endline;
|
||||
char must[FLEXIBLE_ARRAY_MEMBER];
|
||||
};
|
||||
|
||||
/* The dfa structure. It is completely opaque. */
|
||||
struct dfa;
|
||||
|
||||
/* Needed when Gnulib is not used. */
|
||||
#ifndef _GL_ATTRIBUTE_MALLOC
|
||||
# define _GL_ATTRIBUTE_MALLOC
|
||||
# define _GL_ATTRIBUTE_DEALLOC(f, i)
|
||||
# define _GL_ATTRIBUTE_DEALLOC_FREE
|
||||
# define _GL_ATTRIBUTE_RETURNS_NONNULL
|
||||
#endif
|
||||
|
||||
/* Entry points. */
|
||||
|
||||
/* Allocate a struct dfa. The struct dfa is completely opaque.
|
||||
It should be initialized via dfasyntax or dfacopysyntax before other use.
|
||||
The returned pointer should be passed directly to free() after
|
||||
calling dfafree() on it. */
|
||||
extern struct dfa *dfaalloc (void)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL;
|
||||
|
||||
/* DFA options that can be ORed together, for dfasyntax's 4th arg. */
|
||||
enum
|
||||
{
|
||||
/* ^ and $ match only the start and end of data, and do not match
|
||||
end-of-line within data. This is always false for grep, but
|
||||
possibly true for other apps. */
|
||||
DFA_ANCHOR = 1 << 0,
|
||||
|
||||
/* '\0' in data is end-of-line, instead of the traditional '\n'. */
|
||||
DFA_EOL_NUL = 1 << 1,
|
||||
|
||||
/* Treat [:alpha:] etc. as an error at the top level, instead of
|
||||
merely a warning. */
|
||||
DFA_CONFUSING_BRACKETS_ERROR = 1 << 2,
|
||||
|
||||
/* Warn about stray backslashes before ordinary characters other
|
||||
than ] and } which are special because even though POSIX
|
||||
says \] and \} have undefined interpretation, platforms
|
||||
reliably ignore those stray backlashes and warning about them
|
||||
would likely cause more trouble than it's worth. */
|
||||
DFA_STRAY_BACKSLASH_WARN = 1 << 3,
|
||||
|
||||
/* Warn about * appearing out of context at the start of an
|
||||
expression or subexpression. */
|
||||
DFA_STAR_WARN = 1 << 4,
|
||||
|
||||
/* Warn about +, ?, {...} appearing out of context at the start of
|
||||
an expression or subexpression. */
|
||||
DFA_PLUS_WARN = 1 << 5,
|
||||
};
|
||||
|
||||
/* Initialize or reinitialize a DFA. The arguments are:
|
||||
1. The DFA to operate on.
|
||||
2. Information about the current locale.
|
||||
3. Syntax bits described in regex.h.
|
||||
4. Additional DFA options described above. */
|
||||
extern void dfasyntax (struct dfa *, struct localeinfo const *,
|
||||
reg_syntax_t, int);
|
||||
|
||||
/* Initialize or reinitialize a DFA from an already-initialized DFA. */
|
||||
extern void dfacopysyntax (struct dfa *, struct dfa const *);
|
||||
|
||||
/* Parse the given string of given length into the given struct dfa. */
|
||||
extern void dfaparse (char const *, idx_t, struct dfa *);
|
||||
|
||||
struct dfamust;
|
||||
|
||||
/* Free the storage held by the components of a struct dfamust. */
|
||||
extern void dfamustfree (struct dfamust *);
|
||||
|
||||
/* Allocate and return a struct dfamust from a struct dfa that was
|
||||
initialized by dfaparse and not yet given to dfacomp. */
|
||||
extern struct dfamust *dfamust (struct dfa const *)
|
||||
_GL_ATTRIBUTE_DEALLOC (dfamustfree, 1);
|
||||
|
||||
/* Compile the given string of the given length into the given struct dfa.
|
||||
The last argument says whether to build a searching or an exact matcher.
|
||||
A null first argument means the struct dfa has already been
|
||||
initialized by dfaparse; the second argument is ignored. */
|
||||
extern void dfacomp (char const *, idx_t, struct dfa *, bool);
|
||||
|
||||
/* Search through a buffer looking for a match to the given struct dfa.
|
||||
Find the first occurrence of a string matching the regexp in the
|
||||
buffer, and the shortest possible version thereof. Return a pointer to
|
||||
the first character after the match, or NULL if none is found. BEGIN
|
||||
points to the beginning of the buffer, and END points to the first byte
|
||||
after its end. Note however that we store a sentinel byte (usually
|
||||
newline) in *END, so the actual buffer must be one byte longer.
|
||||
When ALLOW_NL is true, newlines may appear in the matching string.
|
||||
If COUNT is non-NULL, increment *COUNT once for each newline processed.
|
||||
Finally, if BACKREF is non-NULL set *BACKREF to indicate whether we
|
||||
encountered a back-reference. The caller can use this to decide
|
||||
whether to fall back on a backtracking matcher. */
|
||||
extern char *dfaexec (struct dfa *d, char const *begin, char *end,
|
||||
bool allow_nl, idx_t *count, bool *backref);
|
||||
|
||||
/* Return a superset for D. The superset matches everything that D
|
||||
matches, along with some other strings (though the latter should be
|
||||
rare, for efficiency reasons). Return a null pointer if no useful
|
||||
superset is available. */
|
||||
extern struct dfa *dfasuperset (struct dfa const *d) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* The DFA is likely to be fast. */
|
||||
extern bool dfaisfast (struct dfa const *) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* Return true if every construct in D is supported by this DFA matcher. */
|
||||
extern bool dfasupported (struct dfa const *) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* Free the storage held by the components of a struct dfa. */
|
||||
extern void dfafree (struct dfa *);
|
||||
|
||||
/* Error handling. */
|
||||
|
||||
/* dfawarn() is called by the regexp routines whenever a regex is compiled
|
||||
that likely doesn't do what the user wanted. It takes a single
|
||||
argument, a NUL-terminated string describing the situation. The user
|
||||
must supply a dfawarn. */
|
||||
extern void dfawarn (const char *);
|
||||
|
||||
/* dfaerror() is called by the regexp routines whenever an error occurs. It
|
||||
takes a single argument, a NUL-terminated string describing the error.
|
||||
The user must supply a dfaerror. */
|
||||
extern _Noreturn void dfaerror (const char *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* dfa.h */
|
||||
@@ -1,52 +0,0 @@
|
||||
/* Manipulate sets of device-inode pairs efficiently.
|
||||
Copyright (C) 2010-2024 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, 2010. */
|
||||
|
||||
#ifndef _GL_DI_SET_H
|
||||
#define _GL_DI_SET_H
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC,
|
||||
_GL_ATTRIBUTE_NONNULL. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
# error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct di_set;
|
||||
|
||||
void di_set_free (struct di_set *) _GL_ATTRIBUTE_NONNULL ((1));
|
||||
|
||||
struct di_set *di_set_alloc (void)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (di_set_free, 1);
|
||||
|
||||
int di_set_insert (struct di_set *, dev_t, ino_t) _GL_ATTRIBUTE_NONNULL ((1));
|
||||
|
||||
int di_set_lookup (struct di_set *dis, dev_t dev, ino_t ino)
|
||||
_GL_ATTRIBUTE_NONNULL ((1));
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,574 +0,0 @@
|
||||
/* Analyze differences between two vectors.
|
||||
|
||||
Copyright (C) 1988-1989, 1992-1995, 2001-2004, 2006-2024 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/>. */
|
||||
|
||||
|
||||
/* The basic idea is to consider two vectors as similar if, when
|
||||
transforming the first vector into the second vector through a
|
||||
sequence of edits (inserts and deletes of one element each),
|
||||
this sequence is short - or equivalently, if the ordered list
|
||||
of elements that are untouched by these edits is long. For a
|
||||
good introduction to the subject, read about the "Levenshtein
|
||||
distance" in Wikipedia.
|
||||
|
||||
The basic algorithm is described in:
|
||||
"An O(ND) Difference Algorithm and its Variations", Eugene W. Myers,
|
||||
Algorithmica Vol. 1, 1986, pp. 251-266,
|
||||
<https://doi.org/10.1007/BF01840446>.
|
||||
See especially section 4.2, which describes the variation used below.
|
||||
|
||||
The basic algorithm was independently discovered as described in:
|
||||
"Algorithms for Approximate String Matching", Esko Ukkonen,
|
||||
Information and Control Vol. 64, 1985, pp. 100-118,
|
||||
<https://doi.org/10.1016/S0019-9958(85)80046-2>.
|
||||
|
||||
Unless the 'find_minimal' flag is set, this code uses the TOO_EXPENSIVE
|
||||
heuristic, by Paul Eggert, to limit the cost to O(N**1.5 log N)
|
||||
at the price of producing suboptimal output for large inputs with
|
||||
many differences. */
|
||||
|
||||
/* Before including this file, you need to define:
|
||||
ELEMENT The element type of the vectors being compared.
|
||||
EQUAL A two-argument macro that tests two elements for
|
||||
equality.
|
||||
OFFSET A signed integer type sufficient to hold the
|
||||
difference between two indices. Usually
|
||||
something like ptrdiff_t.
|
||||
OFFSET_MAX (Optional) The maximum value of OFFSET (e.g.,
|
||||
PTRDIFF_MAX). If omitted, it is inferred in a
|
||||
way portable to the vast majority of C platforms,
|
||||
as they lack padding bits.
|
||||
EXTRA_CONTEXT_FIELDS Declarations of fields for 'struct context'.
|
||||
NOTE_DELETE(ctxt, xoff) Record the removal of the object xvec[xoff].
|
||||
NOTE_INSERT(ctxt, yoff) Record the insertion of the object yvec[yoff].
|
||||
NOTE_ORDERED (Optional) A boolean expression saying that
|
||||
NOTE_DELETE and NOTE_INSERT calls must be
|
||||
issued in offset order.
|
||||
EARLY_ABORT(ctxt) (Optional) A boolean expression that triggers an
|
||||
early abort of the computation.
|
||||
USE_HEURISTIC (Optional) Define if you want to support the
|
||||
heuristic for large vectors.
|
||||
|
||||
It is also possible to use this file with abstract arrays. In this case,
|
||||
xvec and yvec are not represented in memory. They only exist conceptually.
|
||||
In this case, the list of defines above is amended as follows:
|
||||
ELEMENT Undefined.
|
||||
EQUAL Undefined.
|
||||
XVECREF_YVECREF_EQUAL(ctxt, xoff, yoff)
|
||||
A three-argument macro: References xvec[xoff] and
|
||||
yvec[yoff] and tests these elements for equality.
|
||||
|
||||
Before including this file, you also need to include:
|
||||
#include <limits.h>
|
||||
#include "minmax.h"
|
||||
*/
|
||||
|
||||
/* Maximum value of type OFFSET. */
|
||||
#ifndef OFFSET_MAX
|
||||
# define OFFSET_MAX \
|
||||
((((OFFSET) 1 << (sizeof (OFFSET) * CHAR_BIT - 2)) - 1) * 2 + 1)
|
||||
#endif
|
||||
|
||||
/* Default to no early abort. */
|
||||
#ifndef EARLY_ABORT
|
||||
# define EARLY_ABORT(ctxt) false
|
||||
#endif
|
||||
|
||||
#ifndef NOTE_ORDERED
|
||||
# define NOTE_ORDERED false
|
||||
#endif
|
||||
|
||||
/* Suppress gcc's "...may be used before initialized" warnings,
|
||||
generated by GCC versions up to at least GCC 14.2.
|
||||
Likewise for gcc -fanalyzer's "use of uninitialized value" warnings. */
|
||||
#if _GL_GNUC_PREREQ (4, 7)
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
# if _GL_GNUC_PREREQ (13, 0)
|
||||
# pragma GCC diagnostic ignored "-Wanalyzer-use-of-uninitialized-value"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Context of comparison operation.
|
||||
*/
|
||||
struct context
|
||||
{
|
||||
#ifdef ELEMENT
|
||||
/* Vectors being compared. */
|
||||
ELEMENT const *xvec;
|
||||
ELEMENT const *yvec;
|
||||
#endif
|
||||
|
||||
/* Extra fields. */
|
||||
EXTRA_CONTEXT_FIELDS
|
||||
|
||||
/* Vector, indexed by diagonal, containing 1 + the X coordinate of the point
|
||||
furthest along the given diagonal in the forward search of the edit
|
||||
matrix. */
|
||||
OFFSET *fdiag;
|
||||
|
||||
/* Vector, indexed by diagonal, containing the X coordinate of the point
|
||||
furthest along the given diagonal in the backward search of the edit
|
||||
matrix. */
|
||||
OFFSET *bdiag;
|
||||
|
||||
#ifdef USE_HEURISTIC
|
||||
/* This corresponds to the diff --speed-large-files flag. With this
|
||||
heuristic, for vectors with a constant small density of changes,
|
||||
the algorithm is linear in the vector size. */
|
||||
bool heuristic;
|
||||
#endif
|
||||
|
||||
/* Edit scripts longer than this are too expensive to compute. */
|
||||
OFFSET too_expensive;
|
||||
|
||||
/* Snakes bigger than this are considered "big". */
|
||||
#define SNAKE_LIMIT 20
|
||||
};
|
||||
|
||||
struct partition
|
||||
{
|
||||
/* Midpoints of this partition. */
|
||||
OFFSET xmid;
|
||||
OFFSET ymid;
|
||||
|
||||
/* True if low half will be analyzed minimally. */
|
||||
bool lo_minimal;
|
||||
|
||||
/* Likewise for high half. */
|
||||
bool hi_minimal;
|
||||
};
|
||||
|
||||
|
||||
/* Find the midpoint of the shortest edit script for a specified portion
|
||||
of the two vectors.
|
||||
|
||||
Scan from the beginnings of the vectors, and simultaneously from the ends,
|
||||
doing a breadth-first search through the space of edit-sequence.
|
||||
When the two searches meet, we have found the midpoint of the shortest
|
||||
edit sequence.
|
||||
|
||||
If FIND_MINIMAL is true, find the minimal edit script regardless of
|
||||
expense. Otherwise, if the search is too expensive, use heuristics to
|
||||
stop the search and report a suboptimal answer.
|
||||
|
||||
Set PART->(xmid,ymid) to the midpoint (XMID,YMID). The diagonal number
|
||||
XMID - YMID equals the number of inserted elements minus the number
|
||||
of deleted elements (counting only elements before the midpoint).
|
||||
|
||||
Set PART->lo_minimal to true iff the minimal edit script for the
|
||||
left half of the partition is known; similarly for PART->hi_minimal.
|
||||
|
||||
This function assumes that the first elements of the specified portions
|
||||
of the two vectors do not match, and likewise that the last elements do not
|
||||
match. The caller must trim matching elements from the beginning and end
|
||||
of the portions it is going to specify.
|
||||
|
||||
If we return the "wrong" partitions, the worst this can do is cause
|
||||
suboptimal diff output. It cannot cause incorrect diff output. */
|
||||
|
||||
static void
|
||||
diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, bool find_minimal,
|
||||
struct partition *part, struct context *ctxt)
|
||||
{
|
||||
OFFSET *const fd = ctxt->fdiag; /* Give the compiler a chance. */
|
||||
OFFSET *const bd = ctxt->bdiag; /* Additional help for the compiler. */
|
||||
#ifdef ELEMENT
|
||||
ELEMENT const *const xv = ctxt->xvec; /* Still more help for the compiler. */
|
||||
ELEMENT const *const yv = ctxt->yvec; /* And more and more . . . */
|
||||
#define XREF_YREF_EQUAL(x,y) EQUAL (xv[x], yv[y])
|
||||
#else
|
||||
#define XREF_YREF_EQUAL(x,y) XVECREF_YVECREF_EQUAL (ctxt, x, y)
|
||||
#endif
|
||||
const OFFSET dmin = xoff - ylim; /* Minimum valid diagonal. */
|
||||
const OFFSET dmax = xlim - yoff; /* Maximum valid diagonal. */
|
||||
const OFFSET fmid = xoff - yoff; /* Center diagonal of top-down search. */
|
||||
const OFFSET bmid = xlim - ylim; /* Center diagonal of bottom-up search. */
|
||||
OFFSET fmin = fmid;
|
||||
OFFSET fmax = fmid; /* Limits of top-down search. */
|
||||
OFFSET bmin = bmid;
|
||||
OFFSET bmax = bmid; /* Limits of bottom-up search. */
|
||||
OFFSET c; /* Cost. */
|
||||
bool odd = (fmid - bmid) & 1; /* True if southeast corner is on an odd
|
||||
diagonal with respect to the northwest. */
|
||||
|
||||
fd[fmid] = xoff;
|
||||
bd[bmid] = xlim;
|
||||
|
||||
for (c = 1;; ++c)
|
||||
{
|
||||
OFFSET d; /* Active diagonal. */
|
||||
bool big_snake = false;
|
||||
|
||||
/* Extend the top-down search by an edit step in each diagonal. */
|
||||
if (fmin > dmin)
|
||||
fd[--fmin - 1] = -1;
|
||||
else
|
||||
++fmin;
|
||||
if (fmax < dmax)
|
||||
fd[++fmax + 1] = -1;
|
||||
else
|
||||
--fmax;
|
||||
for (d = fmax; d >= fmin; d -= 2)
|
||||
{
|
||||
OFFSET x;
|
||||
OFFSET y;
|
||||
OFFSET tlo = fd[d - 1];
|
||||
OFFSET thi = fd[d + 1];
|
||||
OFFSET x0 = tlo < thi ? thi : tlo + 1;
|
||||
|
||||
for (x = x0, y = x0 - d;
|
||||
x < xlim && y < ylim && XREF_YREF_EQUAL (x, y);
|
||||
x++, y++)
|
||||
continue;
|
||||
if (x - x0 > SNAKE_LIMIT)
|
||||
big_snake = true;
|
||||
fd[d] = x;
|
||||
if (odd && bmin <= d && d <= bmax && bd[d] <= x)
|
||||
{
|
||||
part->xmid = x;
|
||||
part->ymid = y;
|
||||
part->lo_minimal = part->hi_minimal = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Similarly extend the bottom-up search. */
|
||||
if (bmin > dmin)
|
||||
bd[--bmin - 1] = OFFSET_MAX;
|
||||
else
|
||||
++bmin;
|
||||
if (bmax < dmax)
|
||||
bd[++bmax + 1] = OFFSET_MAX;
|
||||
else
|
||||
--bmax;
|
||||
for (d = bmax; d >= bmin; d -= 2)
|
||||
{
|
||||
OFFSET x;
|
||||
OFFSET y;
|
||||
OFFSET tlo = bd[d - 1];
|
||||
OFFSET thi = bd[d + 1];
|
||||
OFFSET x0 = tlo < thi ? tlo : thi - 1;
|
||||
|
||||
for (x = x0, y = x0 - d;
|
||||
xoff < x && yoff < y && XREF_YREF_EQUAL (x - 1, y - 1);
|
||||
x--, y--)
|
||||
continue;
|
||||
if (x0 - x > SNAKE_LIMIT)
|
||||
big_snake = true;
|
||||
bd[d] = x;
|
||||
if (!odd && fmin <= d && d <= fmax && x <= fd[d])
|
||||
{
|
||||
part->xmid = x;
|
||||
part->ymid = y;
|
||||
part->lo_minimal = part->hi_minimal = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (find_minimal)
|
||||
continue;
|
||||
|
||||
#ifdef USE_HEURISTIC
|
||||
bool heuristic = ctxt->heuristic;
|
||||
#else
|
||||
bool heuristic = false;
|
||||
#endif
|
||||
|
||||
/* Heuristic: check occasionally for a diagonal that has made lots
|
||||
of progress compared with the edit distance. If we have any
|
||||
such, find the one that has made the most progress and return it
|
||||
as if it had succeeded.
|
||||
|
||||
With this heuristic, for vectors with a constant small density
|
||||
of changes, the algorithm is linear in the vector size. */
|
||||
|
||||
if (200 < c && big_snake && heuristic)
|
||||
{
|
||||
{
|
||||
OFFSET best = 0;
|
||||
|
||||
for (d = fmax; d >= fmin; d -= 2)
|
||||
{
|
||||
OFFSET dd = d - fmid;
|
||||
OFFSET x = fd[d];
|
||||
OFFSET y = x - d;
|
||||
OFFSET v = (x - xoff) * 2 - dd;
|
||||
|
||||
if (v > 12 * (c + (dd < 0 ? -dd : dd)))
|
||||
{
|
||||
if (v > best
|
||||
&& xoff + SNAKE_LIMIT <= x && x < xlim
|
||||
&& yoff + SNAKE_LIMIT <= y && y < ylim)
|
||||
{
|
||||
/* We have a good enough best diagonal; now insist
|
||||
that it end with a significant snake. */
|
||||
int k;
|
||||
|
||||
for (k = 1; XREF_YREF_EQUAL (x - k, y - k); k++)
|
||||
if (k == SNAKE_LIMIT)
|
||||
{
|
||||
best = v;
|
||||
part->xmid = x;
|
||||
part->ymid = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (best > 0)
|
||||
{
|
||||
part->lo_minimal = true;
|
||||
part->hi_minimal = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
OFFSET best = 0;
|
||||
|
||||
for (d = bmax; d >= bmin; d -= 2)
|
||||
{
|
||||
OFFSET dd = d - bmid;
|
||||
OFFSET x = bd[d];
|
||||
OFFSET y = x - d;
|
||||
OFFSET v = (xlim - x) * 2 + dd;
|
||||
|
||||
if (v > 12 * (c + (dd < 0 ? -dd : dd)))
|
||||
{
|
||||
if (v > best
|
||||
&& xoff < x && x <= xlim - SNAKE_LIMIT
|
||||
&& yoff < y && y <= ylim - SNAKE_LIMIT)
|
||||
{
|
||||
/* We have a good enough best diagonal; now insist
|
||||
that it end with a significant snake. */
|
||||
int k;
|
||||
|
||||
for (k = 0; XREF_YREF_EQUAL (x + k, y + k); k++)
|
||||
if (k == SNAKE_LIMIT - 1)
|
||||
{
|
||||
best = v;
|
||||
part->xmid = x;
|
||||
part->ymid = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (best > 0)
|
||||
{
|
||||
part->lo_minimal = false;
|
||||
part->hi_minimal = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Heuristic: if we've gone well beyond the call of duty, give up
|
||||
and report halfway between our best results so far. */
|
||||
if (c >= ctxt->too_expensive)
|
||||
{
|
||||
/* Find forward diagonal that maximizes X + Y. */
|
||||
OFFSET fxybest = -1, fxbest;
|
||||
for (d = fmax; d >= fmin; d -= 2)
|
||||
{
|
||||
OFFSET x = MIN (fd[d], xlim);
|
||||
OFFSET y = x - d;
|
||||
if (ylim < y)
|
||||
{
|
||||
x = ylim + d;
|
||||
y = ylim;
|
||||
}
|
||||
if (fxybest < x + y)
|
||||
{
|
||||
fxybest = x + y;
|
||||
fxbest = x;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find backward diagonal that minimizes X + Y. */
|
||||
OFFSET bxybest = OFFSET_MAX, bxbest;
|
||||
for (d = bmax; d >= bmin; d -= 2)
|
||||
{
|
||||
OFFSET x = MAX (xoff, bd[d]);
|
||||
OFFSET y = x - d;
|
||||
if (y < yoff)
|
||||
{
|
||||
x = yoff + d;
|
||||
y = yoff;
|
||||
}
|
||||
if (x + y < bxybest)
|
||||
{
|
||||
bxybest = x + y;
|
||||
bxbest = x;
|
||||
}
|
||||
}
|
||||
|
||||
/* Use the better of the two diagonals. */
|
||||
if ((xlim + ylim) - bxybest < fxybest - (xoff + yoff))
|
||||
{
|
||||
part->xmid = fxbest;
|
||||
part->ymid = fxybest - fxbest;
|
||||
part->lo_minimal = true;
|
||||
part->hi_minimal = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
part->xmid = bxbest;
|
||||
part->ymid = bxybest - bxbest;
|
||||
part->lo_minimal = false;
|
||||
part->hi_minimal = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
#undef XREF_YREF_EQUAL
|
||||
}
|
||||
|
||||
|
||||
/* Compare in detail contiguous subsequences of the two vectors
|
||||
which are known, as a whole, to match each other.
|
||||
|
||||
The subsequence of vector 0 is [XOFF, XLIM) and likewise for vector 1.
|
||||
|
||||
Note that XLIM, YLIM are exclusive bounds. All indices into the vectors
|
||||
are origin-0.
|
||||
|
||||
If FIND_MINIMAL, find a minimal difference no matter how
|
||||
expensive it is.
|
||||
|
||||
The results are recorded by invoking NOTE_DELETE and NOTE_INSERT.
|
||||
|
||||
Return false if terminated normally, or true if terminated through early
|
||||
abort. */
|
||||
|
||||
static bool
|
||||
compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim,
|
||||
bool find_minimal, struct context *ctxt)
|
||||
{
|
||||
#ifdef ELEMENT
|
||||
ELEMENT const *xv = ctxt->xvec; /* Help the compiler. */
|
||||
ELEMENT const *yv = ctxt->yvec;
|
||||
#define XREF_YREF_EQUAL(x,y) EQUAL (xv[x], yv[y])
|
||||
#else
|
||||
#define XREF_YREF_EQUAL(x,y) XVECREF_YVECREF_EQUAL (ctxt, x, y)
|
||||
#endif
|
||||
|
||||
while (true)
|
||||
{
|
||||
/* Slide down the bottom initial diagonal. */
|
||||
while (xoff < xlim && yoff < ylim && XREF_YREF_EQUAL (xoff, yoff))
|
||||
{
|
||||
xoff++;
|
||||
yoff++;
|
||||
}
|
||||
|
||||
/* Slide up the top initial diagonal. */
|
||||
while (xoff < xlim && yoff < ylim && XREF_YREF_EQUAL (xlim - 1, ylim - 1))
|
||||
{
|
||||
xlim--;
|
||||
ylim--;
|
||||
}
|
||||
|
||||
/* Handle simple cases. */
|
||||
if (xoff == xlim)
|
||||
{
|
||||
while (yoff < ylim)
|
||||
{
|
||||
NOTE_INSERT (ctxt, yoff);
|
||||
if (EARLY_ABORT (ctxt))
|
||||
return true;
|
||||
yoff++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (yoff == ylim)
|
||||
{
|
||||
while (xoff < xlim)
|
||||
{
|
||||
NOTE_DELETE (ctxt, xoff);
|
||||
if (EARLY_ABORT (ctxt))
|
||||
return true;
|
||||
xoff++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
struct partition part;
|
||||
|
||||
/* Find a point of correspondence in the middle of the vectors. */
|
||||
diag (xoff, xlim, yoff, ylim, find_minimal, &part, ctxt);
|
||||
|
||||
/* Use the partitions to split this problem into subproblems. */
|
||||
OFFSET xoff1, xlim1, yoff1, ylim1, xoff2, xlim2, yoff2, ylim2;
|
||||
bool find_minimal1, find_minimal2;
|
||||
if (!NOTE_ORDERED
|
||||
&& ((xlim + ylim) - (part.xmid + part.ymid)
|
||||
< (part.xmid + part.ymid) - (xoff + yoff)))
|
||||
{
|
||||
/* The second problem is smaller and the caller doesn't
|
||||
care about order, so do the second problem first to
|
||||
lessen recursion. */
|
||||
xoff1 = part.xmid; xlim1 = xlim;
|
||||
yoff1 = part.ymid; ylim1 = ylim;
|
||||
find_minimal1 = part.hi_minimal;
|
||||
|
||||
xoff2 = xoff; xlim2 = part.xmid;
|
||||
yoff2 = yoff; ylim2 = part.ymid;
|
||||
find_minimal2 = part.lo_minimal;
|
||||
}
|
||||
else
|
||||
{
|
||||
xoff1 = xoff; xlim1 = part.xmid;
|
||||
yoff1 = yoff; ylim1 = part.ymid;
|
||||
find_minimal1 = part.lo_minimal;
|
||||
|
||||
xoff2 = part.xmid; xlim2 = xlim;
|
||||
yoff2 = part.ymid; ylim2 = ylim;
|
||||
find_minimal2 = part.hi_minimal;
|
||||
}
|
||||
|
||||
/* Recurse to do one subproblem. */
|
||||
bool early = compareseq (xoff1, xlim1, yoff1, ylim1, find_minimal1, ctxt);
|
||||
if (early)
|
||||
return early;
|
||||
|
||||
/* Iterate to do the other subproblem. */
|
||||
xoff = xoff2; xlim = xlim2;
|
||||
yoff = yoff2; ylim = ylim2;
|
||||
find_minimal = find_minimal2;
|
||||
}
|
||||
|
||||
return false;
|
||||
#undef XREF_YREF_EQUAL
|
||||
}
|
||||
|
||||
#if _GL_GNUC_PREREQ (4, 7)
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#undef ELEMENT
|
||||
#undef EQUAL
|
||||
#undef OFFSET
|
||||
#undef EXTRA_CONTEXT_FIELDS
|
||||
#undef NOTE_DELETE
|
||||
#undef NOTE_INSERT
|
||||
#undef EARLY_ABORT
|
||||
#undef USE_HEURISTIC
|
||||
#undef XVECREF_YVECREF_EQUAL
|
||||
#undef OFFSET_MAX
|
||||
@@ -1,20 +0,0 @@
|
||||
/* Change the ownership and mode bits of a directory.
|
||||
|
||||
Copyright (C) 2006-2024 Free Software Foundation, Inc.
|
||||
|
||||
This file 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 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 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/>. */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
int dirchownmod (int, char const *, mode_t, uid_t, gid_t, mode_t, mode_t);
|
||||
@@ -1,24 +0,0 @@
|
||||
/* Like dirent.h, but redefine some names to avoid glitches.
|
||||
|
||||
Copyright (C) 2009-2024 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 Eric Blake. */
|
||||
|
||||
#include "dirent-safer.h"
|
||||
|
||||
#undef opendir
|
||||
#define opendir opendir_safer
|
||||
#define GNULIB_defined_opendir 1
|
||||
@@ -1,67 +0,0 @@
|
||||
/* Private details of the DIR type.
|
||||
Copyright (C) 2011-2024 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 _DIRENT_PRIVATE_H
|
||||
#define _DIRENT_PRIVATE_H 1
|
||||
|
||||
#if HAVE_DIRENT_H /* mingw */
|
||||
|
||||
# undef DIR
|
||||
|
||||
struct gl_directory
|
||||
{
|
||||
/* File descriptor to close during closedir().
|
||||
Needed for implementing fdopendir(). */
|
||||
int fd_to_close;
|
||||
/* Pointer to the real DIR. */
|
||||
DIR *real_dirp;
|
||||
};
|
||||
|
||||
/* Restore definition from dirent.h. */
|
||||
# define DIR struct gl_directory
|
||||
|
||||
#else /* MSVC */
|
||||
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
|
||||
/* Don't assume that UNICODE is not defined. */
|
||||
# undef WIN32_FIND_DATA
|
||||
# define WIN32_FIND_DATA WIN32_FIND_DATAA
|
||||
|
||||
struct gl_directory
|
||||
{
|
||||
/* File descriptor to close during closedir().
|
||||
Needed for implementing fdopendir(). */
|
||||
int fd_to_close;
|
||||
/* Status, or error code to produce in next readdir() call.
|
||||
-2 means the end of the directory is already reached,
|
||||
-1 means the entry was already filled by FindFirstFile,
|
||||
0 means the entry needs to be filled using FindNextFile.
|
||||
A positive value is an error code. */
|
||||
int status;
|
||||
/* Handle, reading the directory, at current position. */
|
||||
HANDLE current;
|
||||
/* Found directory entry. */
|
||||
WIN32_FIND_DATA entry;
|
||||
/* Argument to pass to FindFirstFile. It consists of the absolutized
|
||||
directory name, followed by a directory separator and the wildcards. */
|
||||
char dir_name_mask[1];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _DIRENT_PRIVATE_H */
|
||||
@@ -1,36 +0,0 @@
|
||||
/* Invoke dirent-like functions, but avoid some glitches.
|
||||
|
||||
Copyright (C) 2009-2024 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 Eric Blake. */
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_DEALLOC. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DIR *opendir_safer (const char *name)
|
||||
_GL_ATTRIBUTE_DEALLOC (closedir, 1);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,59 +0,0 @@
|
||||
/* Take file names apart into directory and base names.
|
||||
|
||||
Copyright (C) 1998, 2001, 2003-2006, 2009-2024 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 DIRNAME_H_
|
||||
# define DIRNAME_H_ 1
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_PURE,
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
# include <stdlib.h>
|
||||
# include "filename.h"
|
||||
# include "basename-lgpl.h"
|
||||
|
||||
# ifndef DIRECTORY_SEPARATOR
|
||||
# define DIRECTORY_SEPARATOR '/'
|
||||
# endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
# if GNULIB_DIRNAME
|
||||
char *base_name (char const *file)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL;
|
||||
char *dir_name (char const *file)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
|
||||
_GL_ATTRIBUTE_RETURNS_NONNULL;
|
||||
# endif
|
||||
|
||||
char *mdir_name (char const *file)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
size_t dir_len (char const *file) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
bool strip_trailing_slashes (char *file);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* not DIRNAME_H_ */
|
||||
@@ -1,18 +0,0 @@
|
||||
/* File names on MS-DOS/Windows systems.
|
||||
|
||||
Copyright (C) 2000-2001, 2004-2006, 2009-2024 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 "filename.h"
|
||||
@@ -1,284 +0,0 @@
|
||||
/* Type-safe arrays which grow dynamically.
|
||||
Copyright 2021-2024 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 and Bruno Haible, 2021. */
|
||||
|
||||
#ifndef _GL_DYNARRAY_H
|
||||
#define _GL_DYNARRAY_H
|
||||
|
||||
/* Before including this file, you need to define:
|
||||
|
||||
DYNARRAY_STRUCT
|
||||
The struct tag of dynamic array to be defined.
|
||||
|
||||
DYNARRAY_ELEMENT
|
||||
The type name of the element type. Elements are copied
|
||||
as if by memcpy, and can change address as the dynamic
|
||||
array grows.
|
||||
|
||||
DYNARRAY_PREFIX
|
||||
The prefix of the functions which are defined.
|
||||
|
||||
The following parameters are optional:
|
||||
|
||||
DYNARRAY_ELEMENT_FREE
|
||||
DYNARRAY_ELEMENT_FREE (E) is evaluated to deallocate the
|
||||
contents of elements. E is of type DYNARRAY_ELEMENT *.
|
||||
|
||||
DYNARRAY_ELEMENT_INIT
|
||||
DYNARRAY_ELEMENT_INIT (E) is evaluated to initialize a new
|
||||
element. E is of type DYNARRAY_ELEMENT *.
|
||||
If DYNARRAY_ELEMENT_FREE but not DYNARRAY_ELEMENT_INIT is
|
||||
defined, new elements are automatically zero-initialized.
|
||||
Otherwise, new elements have undefined contents.
|
||||
|
||||
DYNARRAY_INITIAL_SIZE
|
||||
The size of the statically allocated array (default:
|
||||
at least 2, more elements if they fit into 128 bytes).
|
||||
Must be a preprocessor constant. If DYNARRAY_INITIAL_SIZE is 0,
|
||||
there is no statically allocated array at, and all non-empty
|
||||
arrays are heap-allocated.
|
||||
|
||||
DYNARRAY_FINAL_TYPE
|
||||
The name of the type which holds the final array. If not
|
||||
defined, is PREFIX##finalize not provided. DYNARRAY_FINAL_TYPE
|
||||
must be a struct type, with members of type DYNARRAY_ELEMENT and
|
||||
size_t at the start (in this order).
|
||||
|
||||
These macros are undefined after this header file has been
|
||||
included.
|
||||
|
||||
The following types are provided (their members are private to the
|
||||
dynarray implementation):
|
||||
|
||||
struct DYNARRAY_STRUCT
|
||||
|
||||
The following functions are provided:
|
||||
*/
|
||||
|
||||
/* Initialize a dynamic array object. This must be called before any
|
||||
use of the object. */
|
||||
#if 0
|
||||
static void
|
||||
DYNARRAY_PREFIX##init (struct DYNARRAY_STRUCT *list);
|
||||
#endif
|
||||
|
||||
/* Deallocate the dynamic array and its elements. */
|
||||
#if 0
|
||||
static void
|
||||
DYNARRAY_PREFIX##free (struct DYNARRAY_STRUCT *list);
|
||||
#endif
|
||||
|
||||
/* Return true if the dynamic array is in an error state. */
|
||||
#if 0
|
||||
static bool
|
||||
DYNARRAY_PREFIX##has_failed (const struct DYNARRAY_STRUCT *list);
|
||||
#endif
|
||||
|
||||
/* Mark the dynamic array as failed. All elements are deallocated as
|
||||
a side effect. */
|
||||
#if 0
|
||||
static void
|
||||
DYNARRAY_PREFIX##mark_failed (struct DYNARRAY_STRUCT *list);
|
||||
#endif
|
||||
|
||||
/* Return the number of elements which have been added to the dynamic
|
||||
array. */
|
||||
#if 0
|
||||
static size_t
|
||||
DYNARRAY_PREFIX##size (const struct DYNARRAY_STRUCT *list);
|
||||
#endif
|
||||
|
||||
/* Return a pointer to the first array element, if any. For a
|
||||
zero-length array, the pointer can be NULL even though the dynamic
|
||||
array has not entered the failure state. */
|
||||
#if 0
|
||||
static DYNARRAY_ELEMENT *
|
||||
DYNARRAY_PREFIX##begin (const struct DYNARRAY_STRUCT *list);
|
||||
#endif
|
||||
|
||||
/* Return a pointer one element past the last array element. For a
|
||||
zero-length array, the pointer can be NULL even though the dynamic
|
||||
array has not entered the failure state. */
|
||||
#if 0
|
||||
static DYNARRAY_ELEMENT *
|
||||
DYNARRAY_PREFIX##end (const struct DYNARRAY_STRUCT *list);
|
||||
#endif
|
||||
|
||||
/* Return a pointer to the array element at INDEX. Terminate the
|
||||
process if INDEX is out of bounds. */
|
||||
#if 0
|
||||
static DYNARRAY_ELEMENT *
|
||||
DYNARRAY_PREFIX##at (struct DYNARRAY_STRUCT *list, size_t index);
|
||||
#endif
|
||||
|
||||
/* Add ITEM at the end of the array, enlarging it by one element.
|
||||
Mark *LIST as failed if the dynamic array allocation size cannot be
|
||||
increased. */
|
||||
#if 0
|
||||
static void
|
||||
DYNARRAY_PREFIX##add (struct DYNARRAY_STRUCT *list,
|
||||
DYNARRAY_ELEMENT item);
|
||||
#endif
|
||||
|
||||
/* Allocate a place for a new element in *LIST and return a pointer to
|
||||
it. The pointer can be NULL if the dynamic array cannot be
|
||||
enlarged due to a memory allocation failure. */
|
||||
#if 0
|
||||
static DYNARRAY_ELEMENT *
|
||||
DYNARRAY_PREFIX##emplace (struct DYNARRAY_STRUCT *list);
|
||||
#endif
|
||||
|
||||
/* Change the size of *LIST to SIZE. If SIZE is larger than the
|
||||
existing size, new elements are added (which can be initialized).
|
||||
Otherwise, the list is truncated, and elements are freed. Return
|
||||
false on memory allocation failure (and mark *LIST as failed). */
|
||||
#if 0
|
||||
static bool
|
||||
DYNARRAY_PREFIX##resize (struct DYNARRAY_STRUCT *list, size_t size);
|
||||
#endif
|
||||
|
||||
/* Remove the last element of LIST if it is present. */
|
||||
#if 0
|
||||
static void
|
||||
DYNARRAY_PREFIX##remove_last (struct DYNARRAY_STRUCT *list);
|
||||
#endif
|
||||
|
||||
/* Remove all elements from the list. The elements are freed, but the
|
||||
list itself is not. */
|
||||
#if 0
|
||||
static void
|
||||
DYNARRAY_PREFIX##clear (struct DYNARRAY_STRUCT *list);
|
||||
#endif
|
||||
|
||||
#if defined DYNARRAY_FINAL_TYPE
|
||||
/* Transfer the dynamic array to a permanent location at *RESULT.
|
||||
Returns true on success on false on allocation failure. In either
|
||||
case, *LIST is re-initialized and can be reused. A NULL pointer is
|
||||
stored in *RESULT if LIST refers to an empty list. On success, the
|
||||
pointer in *RESULT is heap-allocated and must be deallocated using
|
||||
free. */
|
||||
#if 0
|
||||
static bool
|
||||
DYNARRAY_PREFIX##finalize (struct DYNARRAY_STRUCT *list,
|
||||
DYNARRAY_FINAL_TYPE *result);
|
||||
#endif
|
||||
#else /* !defined DYNARRAY_FINAL_TYPE */
|
||||
/* Transfer the dynamic array to a heap-allocated array and return a
|
||||
pointer to it. The pointer is NULL if memory allocation fails, or
|
||||
if the array is empty, so this function should be used only for
|
||||
arrays which are known not be empty (usually because they always
|
||||
have a sentinel at the end). If LENGTHP is not NULL, the array
|
||||
length is written to *LENGTHP. *LIST is re-initialized and can be
|
||||
reused. */
|
||||
#if 0
|
||||
static DYNARRAY_ELEMENT *
|
||||
DYNARRAY_PREFIX##finalize (struct DYNARRAY_STRUCT *list,
|
||||
size_t *lengthp);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* A minimal example which provides a growing list of integers can be
|
||||
defined like this:
|
||||
|
||||
struct int_array
|
||||
{
|
||||
// Pointer to result array followed by its length,
|
||||
// as required by DYNARRAY_FINAL_TYPE.
|
||||
int *array;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
#define DYNARRAY_STRUCT dynarray_int
|
||||
#define DYNARRAY_ELEMENT int
|
||||
#define DYNARRAY_PREFIX dynarray_int_
|
||||
#define DYNARRAY_FINAL_TYPE struct int_array
|
||||
#include <malloc/dynarray-skeleton.c>
|
||||
|
||||
To create a three-element array with elements 1, 2, 3, use this
|
||||
code:
|
||||
|
||||
struct dynarray_int dyn;
|
||||
dynarray_int_init (&dyn);
|
||||
for (int i = 1; i <= 3; ++i)
|
||||
{
|
||||
int *place = dynarray_int_emplace (&dyn);
|
||||
assert (place != NULL);
|
||||
*place = i;
|
||||
}
|
||||
struct int_array result;
|
||||
bool ok = dynarray_int_finalize (&dyn, &result);
|
||||
assert (ok);
|
||||
assert (result.length == 3);
|
||||
assert (result.array[0] == 1);
|
||||
assert (result.array[1] == 2);
|
||||
assert (result.array[2] == 3);
|
||||
free (result.array);
|
||||
|
||||
If the elements contain resources which must be freed, define
|
||||
DYNARRAY_ELEMENT_FREE appropriately, like this:
|
||||
|
||||
struct str_array
|
||||
{
|
||||
char **array;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
#define DYNARRAY_STRUCT dynarray_str
|
||||
#define DYNARRAY_ELEMENT char *
|
||||
#define DYNARRAY_ELEMENT_FREE(ptr) free (*ptr)
|
||||
#define DYNARRAY_PREFIX dynarray_str_
|
||||
#define DYNARRAY_FINAL_TYPE struct str_array
|
||||
#include <malloc/dynarray-skeleton.c>
|
||||
*/
|
||||
|
||||
|
||||
/* The implementation is imported from glibc. */
|
||||
|
||||
/* Avoid possible conflicts with symbols exported by the GNU libc. */
|
||||
#define __libc_dynarray_at_failure gl_dynarray_at_failure
|
||||
#define __libc_dynarray_emplace_enlarge gl_dynarray_emplace_enlarge
|
||||
#define __libc_dynarray_finalize gl_dynarray_finalize
|
||||
#define __libc_dynarray_resize_clear gl_dynarray_resize_clear
|
||||
#define __libc_dynarray_resize gl_dynarray_resize
|
||||
|
||||
#if defined DYNARRAY_STRUCT || defined DYNARRAY_ELEMENT || defined DYNARRAY_PREFIX
|
||||
|
||||
# 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
|
||||
|
||||
/* Define auxiliary structs and declare auxiliary functions, common to all
|
||||
instantiations of dynarray. */
|
||||
# include <malloc/dynarray.gl.h>
|
||||
|
||||
/* Define the instantiation, specified through
|
||||
DYNARRAY_STRUCT
|
||||
DYNARRAY_ELEMENT
|
||||
DYNARRAY_PREFIX
|
||||
etc. */
|
||||
# include <malloc/dynarray-skeleton.gl.h>
|
||||
|
||||
#else
|
||||
|
||||
/* This file is being included from one of the malloc/dynarray_*.c files. */
|
||||
# include <malloc/dynarray.h>
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _GL_DYNARRAY_H */
|
||||
@@ -1,110 +0,0 @@
|
||||
/* Memory allocation with expensive empty allocations.
|
||||
Copyright (C) 2003, 2008, 2010-2024 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2003,
|
||||
based on prior work by Jim Meyering.
|
||||
|
||||
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 _EEALLOC_H
|
||||
#define _EEALLOC_H
|
||||
|
||||
/* malloc() and realloc() are allowed to return NULL when asked to allocate
|
||||
a memory block of 0 bytes; this is not an out-of-memory condition.
|
||||
(See ISO C 99 section 7.20.3.) In some places, this is not welcome,
|
||||
because it requires extra checking (so as not to confuse a zero-sized
|
||||
allocation with an out-of-memory condition). This file provides
|
||||
malloc()/realloc() workalikes which return non-NULL pointers for
|
||||
succeeding zero-sized allocations. GNU libc already defines malloc()
|
||||
and realloc() this way; on such platforms the workalikes are aliased
|
||||
to the original malloc()/realloc() functions. */
|
||||
|
||||
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_ATTRIBUTE_ALLOC_SIZE,
|
||||
_GL_ATTRIBUTE_MALLOC. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#if defined __CHERI_PURE_CAPABILITY__
|
||||
# include <cheri.h>
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
#ifndef EEALLOC_INLINE
|
||||
# define EEALLOC_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if MALLOC_0_IS_NONNULL
|
||||
# define eemalloc malloc
|
||||
#else
|
||||
EEALLOC_INLINE void *eemalloc (size_t n)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1))
|
||||
_GL_ATTRIBUTE_DEALLOC_FREE;
|
||||
EEALLOC_INLINE void *
|
||||
eemalloc (size_t n)
|
||||
{
|
||||
/* If n is zero, allocate a 1-byte block. */
|
||||
size_t nx = n;
|
||||
if (n == 0)
|
||||
nx = 1;
|
||||
void *ptr = malloc (nx);
|
||||
# if defined __CHERI_PURE_CAPABILITY__
|
||||
if (ptr != NULL)
|
||||
ptr = cheri_bounds_set (ptr, n);
|
||||
# endif
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if REALLOC_0_IS_NONNULL
|
||||
# define eerealloc realloc
|
||||
#else
|
||||
EEALLOC_INLINE void *eerealloc (void *p, size_t n)
|
||||
_GL_ATTRIBUTE_ALLOC_SIZE ((2));
|
||||
EEALLOC_INLINE void *
|
||||
eerealloc (void *p, size_t n)
|
||||
{
|
||||
/* If n is zero, allocate or keep a 1-byte block. */
|
||||
size_t nx = n;
|
||||
if (n == 0)
|
||||
nx = 1;
|
||||
void *ptr = realloc (p, nx);
|
||||
# if defined __CHERI_PURE_CAPABILITY__
|
||||
if (ptr != NULL)
|
||||
ptr = cheri_bounds_set (ptr, n);
|
||||
# endif
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Maybe we should also define variants
|
||||
eenmalloc (size_t n, size_t s) - behaves like eemalloc (n * s)
|
||||
eezalloc (size_t n) - like eemalloc followed by memset 0
|
||||
eecalloc (size_t n, size_t s) - like eemalloc (n * s) followed by memset 0
|
||||
eenrealloc (void *p, size_t n, size_t s) - like eerealloc (p, n * s)
|
||||
If this would be useful in your application. please speak up. */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
_GL_INLINE_HEADER_END
|
||||
|
||||
#endif /* _EEALLOC_H */
|
||||
@@ -1,88 +0,0 @@
|
||||
/* Threshold at which to diagnose ELOOP. Generic version.
|
||||
Copyright (C) 2012-2024 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
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_CONST. */
|
||||
#if !_LIBC && !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#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,80 +0,0 @@
|
||||
/* exclude.h -- declarations for excluding file names
|
||||
|
||||
Copyright (C) 1992-1994, 1997, 1999, 2001-2003, 2005-2006, 2009-2024 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 Paul Eggert <eggert@twinsun.com>
|
||||
and Sergey Poznyakoff <gray@gnu.org> */
|
||||
|
||||
#ifndef _GL_EXCLUDE_H
|
||||
#define _GL_EXCLUDE_H 1
|
||||
|
||||
/* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC,
|
||||
_GL_ATTRIBUTE_NONNULL, _GL_ATTRIBUTE_PURE, _GL_ATTRIBUTE_RETURNS_NONNULL. */
|
||||
#if !_GL_CONFIG_H_INCLUDED
|
||||
#error "Please include config.h first."
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Exclude options, which can be ORed with fnmatch options. */
|
||||
|
||||
/* Patterns must match the start of file names, instead of matching
|
||||
anywhere after a '/'. */
|
||||
#define EXCLUDE_ANCHORED (1 << 30)
|
||||
|
||||
/* Include instead of exclude. */
|
||||
#define EXCLUDE_INCLUDE (1 << 29)
|
||||
|
||||
/* '?', '*', '[', and '\\' are special in patterns. Without this
|
||||
option, these characters are ordinary and fnmatch is not used. */
|
||||
#define EXCLUDE_WILDCARDS (1 << 28)
|
||||
|
||||
/* Patterns are POSIX extended regular expressions */
|
||||
#define EXCLUDE_REGEX (1 << 27)
|
||||
|
||||
/* Allocate storage for the pattern */
|
||||
#define EXCLUDE_ALLOC (1 << 26)
|
||||
|
||||
struct exclude;
|
||||
|
||||
bool fnmatch_pattern_has_wildcards (const char *, int) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
void free_exclude (struct exclude *)
|
||||
_GL_ATTRIBUTE_NONNULL ((1));
|
||||
struct exclude *new_exclude (void)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_RETURNS_NONNULL
|
||||
_GL_ATTRIBUTE_DEALLOC (free_exclude, 1);
|
||||
void add_exclude (struct exclude *, char const *, int);
|
||||
int add_exclude_file (void (*) (struct exclude *, char const *, int),
|
||||
struct exclude *, char const *, int, char);
|
||||
int add_exclude_fp (void (*) (struct exclude *, char const *, int, void *),
|
||||
struct exclude *, FILE *, int, char, void *);
|
||||
bool excluded_file_name (struct exclude const *, char const *);
|
||||
void exclude_add_pattern_buffer (struct exclude *ex, char *buf);
|
||||
bool exclude_fnmatch (char const *, char const *, int);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _GL_EXCLUDE_H */
|
||||
@@ -1,75 +0,0 @@
|
||||
/* Creation of autonomous subprocesses.
|
||||
Copyright (C) 2001-2003, 2008-2024 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 _EXECUTE_H
|
||||
#define _EXECUTE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Execute a command, optionally redirecting any of the three standard file
|
||||
descriptors to /dev/null. Return its exit code.
|
||||
If it didn't terminate correctly, exit if exit_on_error is true, otherwise
|
||||
return 127.
|
||||
|
||||
progname is the name of the program to be executed by the subprocess, used
|
||||
for error messages.
|
||||
prog_path is the file name of the program to be executed by the subprocess.
|
||||
If it contains no slashes, a search is conducted in $PATH. An operating
|
||||
system dependent suffix is added, if necessary.
|
||||
prog_argv is the array of strings that the subprocess shall receive in
|
||||
argv[]. It is a NULL-terminated array. prog_argv[0] should normally be
|
||||
identical to prog_path.
|
||||
|
||||
dll_dirs is, on Windows platforms, a NULL-terminated list of directories
|
||||
that contain DLLs needed to execute the program, or NULL if none is needed.
|
||||
On other platforms, always pass NULL.
|
||||
|
||||
If directory is not NULL, the command is executed in that directory. If
|
||||
prog_path is a relative file name, it resolved before changing to that
|
||||
directory. The current directory of the current process remains unchanged.
|
||||
|
||||
If ignore_sigpipe is true, consider a subprocess termination due to SIGPIPE
|
||||
as equivalent to a success. This is suitable for processes whose only
|
||||
purpose is to write to standard output.
|
||||
|
||||
If slave_process is true, the child process will be terminated when its
|
||||
creator receives a catchable fatal signal.
|
||||
|
||||
If termsigp is not NULL, *termsig will be set to the signal that terminated
|
||||
the subprocess (if supported by the platform: not on native Windows
|
||||
platforms), otherwise 0.
|
||||
|
||||
It is recommended that no signal is blocked or ignored while execute()
|
||||
is called. See spawn-pipe.h for the reason. */
|
||||
extern int execute (const char *progname,
|
||||
const char *prog_path, const char * const *prog_argv,
|
||||
const char * const *dll_dirs,
|
||||
const char *directory,
|
||||
bool ignore_sigpipe,
|
||||
bool null_stdin, bool null_stdout, bool null_stderr,
|
||||
bool slave_process, bool exit_on_error,
|
||||
int *termsigp);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _EXECUTE_H */
|
||||
@@ -1,28 +0,0 @@
|
||||
/* Failure exit status
|
||||
|
||||
Copyright (C) 2002, 2009-2024 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/>. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
extern int volatile exit_failure;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user