cake
/
libcasio
Archived
1
1
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libcasio/include/libcasio/cdefs.h

157 lines
4.2 KiB
C

/* ****************************************************************************
* libcasio/cdefs.h -- C helpers.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.0 of the License,
* or (at your option) any later version.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
/* Pre-ANSI C compilers don't support arguments (and argument types) in
* function declarations. This macro is inspired from zlib.
*
* It is defined outside of the include guard because it is not in
* the libcasio defined namespace, so we want it to be redefined, in case. */
#if defined(OF)
#elif defined(__STDC__) && __STDC__
# define OF(CASIO__ARGS) CASIO__ARGS
#else
# define OF(CASIO__ARGS) ()
#endif
/* "Normal start" of the file is here. */
#ifndef LIBCASIO_CDEFS_H
# define LIBCASIO_CDEFS_H
# include "config.h"
# include <stddef.h>
# include <time.h>
/* Check the library version. */
# define LIBCASIO_PREREQ(CASIO__MAJ, CASIO__MIN) \
((CASIO__MAJ) > (LIBCASIO_MAJOR) || \
((CASIO__MAJ) == (LIBCASIO_MAJOR) && (CASIO__MIN) >= (LIBCASIO_MINOR)))
/* ---
* Check for compilers.
* --- */
/* First, GCC. */
# if defined(CASIO_GNUC_PREREQ)
# elif defined(__GNUC__) && defined(__GNUC_MINOR__)
# define CASIO_GNUC_PREREQ(CASIO__MAJ, CASIO__MIN) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((CASIO__MAJ) << 16) + (CASIO__MIN))
# else
# define CASIO_GNUC_PREREQ(CASIO__MAJ, CASIO__MIN) 0
# endif
/* Then, Microsoft's Compiler. */
# if defined(CASIO_MSC_PREREQ) || defined(_MSC_VER)
# define CASIO_MSC_PREREQ(CASIO__MAJ, CASIO__MIN) \
(_MSC_VER >= (CASIO__MAJ) * 1000 + (CASIO__MIN))
# else
# define CASIO_MSC_PREREQ(CASIO__MAJ, CASIO__MIN) 0
# endif
/* ---
* Extern functions.
* --- */
/* Warn if the function is deprecated. */
# if CASIO_GNUC_PREREQ(3, 0)
# define CASIO_DEPRECATED __attribute__((deprecated))
# else
# define CASIO_DEPRECATED
# endif
/* Warn if the result is unused.
* To do that, we'll use the `CASIO_WUR` attribute. */
# if CASIO_GNUC_PREREQ(4, 0)
# define CASIO_WUR __attribute__((warn_unused_result))
# elif CASIO_MSC_PREREQ(17, 0)
# include <sal.h>
# define CASIO_WUR _Check_return_
# else
# define CASIO_WUR
# endif
/* Some platforms require more than simply 'extern'.
* Here are macros to control this. */
# define CASIO_EXTERN(TYPE) \
extern TYPE
# define CASIO_NORETURN \
__attribute__((noreturn)) extern void
# define CASIO_LOCAL(TYPE) \
static TYPE
# define CASIO_HOOK(TYPE) \
static TYPE
# define CASIO_EXTERN_TYPE(TYPE) \
TYPE
# define CASIO_HOOK_TYPE(TYPE) \
TYPE
# define CASIO_LOCAL_DATA(TYPE) \
static TYPE
/* ---
* C++ declarations and namespaces management.
* --- */
/* libcasio is made in C. */
# ifdef __cplusplus
# define CASIO_BEGIN_NAMESPACE namespace "libcasio" {
# define CASIO_BEGIN_DECLS extern "C" {
# define CASIO_END_DECLS }
# define CASIO_END_NAMESPACE }
# else
# define CASIO_BEGIN_NAMESPACE
# define CASIO_BEGIN_DECLS
# define CASIO_END_DECLS
# define CASIO_END_NAMESPACE
# endif
/* Forward declare a structure. */
# define CASIO_STRUCT(CASIO__STRUCT_NAME, CASIO__STRUCT_TYPEDEF) \
struct CASIO__STRUCT_NAME; \
typedef struct CASIO__STRUCT_NAME CASIO__STRUCT_TYPEDEF;
/* ---
* Utilities.
* --- */
CASIO_BEGIN_NAMESPACE
CASIO_BEGIN_DECLS
/* Cross-platform allocation functions. They are defined just in case. */
CASIO_EXTERN(void *) casio_alloc
OF((size_t casio__num_elements, size_t casio__element_size));
CASIO_EXTERN(void) casio_free
OF((void *casio__ptr));
CASIO_END_DECLS
CASIO_END_NAMESPACE
# include "cdefs/integers.h"
# include "cdefs/endian.h"
#endif /* LIBCASIO_CDEFS_H */