Files
ci2/include/platform/ci2_platform.h
T

95 lines
2.9 KiB
C
Raw Normal View History

2026-06-06 18:15:42 -05:00
/* - | Copyright | ------------------------------------------------------------
Copyright (c) 2026 Randy Jordan
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
* --------------------------------------------------------------------------*/
#ifndef CI2_PLATFORM_H
#define CI2_PLATFORM_H
#include "./base/ci2_base.h"
/* No name mangling for declarations---------------------------------------- */
#ifdef __cplusplus
extern "C"
{
#endif
/* CI2_EXTERN: plain extern with C++ aware linkage token for macros if needed */
#if defined(__cplusplus)
#define CI2_EXTERN extern "C"
#else
#define CI2_EXTERN extern
#endif
/* CI2_API: platform/compiler-aware import/export/visibility */
#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(CI2_BUILD_DLL)
#define CI2_API CI2_EXTERN __declspec(dllexport)
#elif defined(CI2_USE_DLL)
#define CI2_API CI2_EXTERN __declspec(dllimport)
#else
#define CI2_API CI2_EXTERN
#endif
#else
/* Non-Windows: use visibility if supported */
#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_LLVM_COMPILER)
#if defined(CI2_BUILD_DLL)
#define CI2_API CI2_EXTERN __attribute__((visibility("default")))
#else
#define CI2_API CI2_EXTERN
#endif
#else
#define CI2_API CI2_EXTERN
#endif
#endif
/* CI2_DEF: internal vs external linkage */
#ifndef CI2_DEF
#ifdef CI2_STATIC
#define CI2_DEF static
#else
#define CI2_DEF CI2_API
#endif
#endif
#define CI2_SUCCESS 0
#define CI2_FAILURE -1
#define CI2_TRUE 1
#define CI2_FALSE 0
#define CI2_SIZE(x) (ptrdiff_t)sizeof(x)
#define CI2_COUNT(a) (sizeof(a) / sizeof(*(a)))
#define CI2_LEN(s) (countof(s) - 1)
#define CI2_KB(x) ((x) * (size_t)(1024))
#define CI2_MB(x) (CI2_KB(x) * (size_t)(1024))
#define CI2_GB(x) (CI2_MB(x) * (size_t)(1024))
#define CI2_TB(x) (CI2_GB(x) * (size_t)(1024))
CI2_API ci2_thread_local int ci2_errno;
CI2_API int* ci2_errno_location(void);
/*---------------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif // c++
#endif // ci2_platform.h