Path: blob/master/Utilities/cmliblzma/common/tuklib_common.h
3153 views
// SPDX-License-Identifier: 0BSD12///////////////////////////////////////////////////////////////////////////////3//4/// \file tuklib_common.h5/// \brief Common definitions for tuklib modules6//7// Author: Lasse Collin8//9///////////////////////////////////////////////////////////////////////////////1011#ifndef TUKLIB_COMMON_H12#define TUKLIB_COMMON_H1314// The config file may be replaced by a package-specific file.15// It should include at least stddef.h, stdbool.h, inttypes.h, and limits.h.16#include "tuklib_config.h"1718// TUKLIB_SYMBOL_PREFIX is prefixed to all symbols exported by19// the tuklib modules. If you use a tuklib module in a library,20// you should use TUKLIB_SYMBOL_PREFIX to make sure that there21// are no symbol conflicts in case someone links your library22// into application that also uses the same tuklib module.23#ifndef TUKLIB_SYMBOL_PREFIX24# define TUKLIB_SYMBOL_PREFIX25#endif2627#define TUKLIB_CAT_X(a, b) a ## b28#define TUKLIB_CAT(a, b) TUKLIB_CAT_X(a, b)2930#ifndef TUKLIB_SYMBOL31# define TUKLIB_SYMBOL(sym) TUKLIB_CAT(TUKLIB_SYMBOL_PREFIX, sym)32#endif3334#ifndef TUKLIB_DECLS_BEGIN35# ifdef __cplusplus36# define TUKLIB_DECLS_BEGIN extern "C" {37# else38# define TUKLIB_DECLS_BEGIN39# endif40#endif4142#ifndef TUKLIB_DECLS_END43# ifdef __cplusplus44# define TUKLIB_DECLS_END }45# else46# define TUKLIB_DECLS_END47# endif48#endif4950#if defined(__GNUC__) && defined(__GNUC_MINOR__)51# define TUKLIB_GNUC_REQ(major, minor) \52((__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)) \53|| __GNUC__ > (major))54#else55# define TUKLIB_GNUC_REQ(major, minor) 056#endif5758// tuklib_attr_noreturn attribute is used to mark functions as non-returning.59// We cannot use "noreturn" as the macro name because then C23 code that60// uses [[noreturn]] would break as it would expand to [[ [[noreturn]] ]].61//62// tuklib_attr_noreturn must be used at the beginning of function declaration63// to work in all cases. The [[noreturn]] syntax is the most limiting, it64// must be even before any GNU C's __attribute__ keywords:65//66// tuklib_attr_noreturn67// __attribute__((nonnull(1)))68// extern void foo(const char *s);69//70// FIXME: Update __STDC_VERSION__ for the final C23 version. 202000 is used71// by GCC 13 and Clang 15 with -std=c2x.72#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 20200073# define tuklib_attr_noreturn [[noreturn]]74#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 20111275# define tuklib_attr_noreturn _Noreturn76#elif TUKLIB_GNUC_REQ(2, 5)77# define tuklib_attr_noreturn __attribute__((__noreturn__))78#elif defined(_MSC_VER)79# define tuklib_attr_noreturn __declspec(noreturn)80#else81# define tuklib_attr_noreturn82#endif8384#if (defined(_WIN32) && !defined(__CYGWIN__)) \85|| defined(__OS2__) || defined(__MSDOS__)86# define TUKLIB_DOSLIKE 187#endif8889#endif909192