cake
/
libp7
Archived
1
0
Fork 1
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.
libp7/include/libp7/cdefs.h

121 lines
4.3 KiB
C

/* *****************************************************************************
* libp7/cdefs.h -- libp7 C definitions.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.
* libp7 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.
*
* libp7 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 libp7; if not, see <http://www.gnu.org/licenses/>.
*
* The libp7 buffer interface is an abstraction layer between libp7 and files
* or data on disk in general.
* ************************************************************************** */
#ifndef LIBP7_CDEFS_H
# define LIBP7_CDEFS_H
/* ************************************************************************** */
/* Important things */
/* ************************************************************************** */
/* Declare any function. */
# ifdef p7_declare_func
# undef p7_declare_func
# endif
# ifdef __STDC_VERSION__
# define p7_declare_func(P7_ARG_NAME, P7_ARG_RET, P7_ARG_ATTRS, ...) \
extern P7_ARG_RET P7_ARG_NAME (__VA_ARGS__) P7_ARG_ATTRS;
# else
# define p7_declare_func(P7_ARG_NAME, P7_ARG_RET, P7_ARG_ATTRS, ...) \
extern P7_ARG_RET P7_ARG_NAME () P7_ARG_ATTRS;
# endif
/* Define any function (head). */
# ifdef p7_define_func
# undef p7_define_func
# endif
# if defined(_MSC_VER)
# define p7_define_func(P7_ARG_NAME, P7_ARG_RET, P7_ARG_ATTRS, ...) \
P7_ARG_ATTRS P7_ARG_RET P7_ARG_NAME (__VA_ARGS__)
# else
# define p7_define_func(P7_ARG_NAME, P7_ARG_RET, P7_ARG_ATTRS, ...) \
P7_ARG_RET P7_ARG_NAME (__VA_ARGS__)
# endif
/* Declare an usage function.
* TODO: add the handle here? */
# ifdef p7_declare_ufunc
# undef p7_declare_ufunc
# endif
# define p7_declare_ufunc(P7_ARG_NAME, P7_ARG_ATTRS, ...) \
p7_declare_func(P7_ARG_NAME, int, P7_ARG_ATTRS p7_attribute_err, \
__VA_ARGS__)
# define p7_define_ufunc(P7_ARG_NAME, P7_ARG_ATTRS, ...) \
p7_define_func(P7_ARG_NAME, int, P7_ARG_ATTRS p7_attribute_err, \
__VA_ARGS__)
/* ************************************************************************** */
/* Attributes */
/* ************************************************************************** */
/* p7_attribute_THROW: optimize function calls for C++
* TODO: explain more */
# ifdef p7_attribute_THROW
# undef p7_attribute_THROW
# endif
# if defined(__cplusplus)
# define p7_attribute_THROW throw()
# elif defined(__GNUC__)
# define p7_attribute_THROW __attribute__((nothrow))
# elif defined(_MSC_VER)
# define p7_attribute_THROW __declspec(nothrow)
# else
# define p7_attribute_THROW
# endif
/* p7_attribute_nonnull: require a pointer argument not to be NULL
* A warning shall be issued when a NULL value is passed as an argument that
* shouldn't be. The macro argument is the argument index, starting from 1. */
# ifdef p7_attribute_nonnull
# undef p7_attribute_nonnull
# endif
# if defined(__GNUC__)
# define p7_attribute_nonnull(P7_ARG_N) __attribute__((nonnull(P7_ARG_N)))
# else
# define p7_attribute_nonnull(P7_ARG_N)
# endif
/* p7_attribute_wur: warn unused result
* A warning shall be issued if the result of the function isn't used.
* Note that __pure implies __wur, you don't need to put the two. */
# ifdef p7_attribute_wur
# undef p7_attribute_wur
# endif
# if defined(__GNUC__) && (__GNUC__ >= 4)
# define p7_attribute_wur __attribute__((warn_unused_result))
# elif defined(_MSC_VER) && (_MSC_VER >= 1700)
# include <sal.h>
# define p7_attribute_wur _Check_return_
# else
# define p7_attribute_wur
# endif
/* p7_attribute_err: return a libp7 error
* This is so the `wur` on functions returning an error is more easily
* tweakable. */
# ifdef p7_attribute_err
# undef p7_attribute_err
# endif
# define p7_attribute_err /* p7_attribute_wur */
#endif /* LIBP7_CDEFS_H */