DrangPlatform/Source/DrangPlatform/Include/drang/platform.h
2025-09-05 04:05:47 +02:00

51 lines
1.6 KiB
C

#pragma once
#if !DRANG_PLATFORM_STATIC
# if DRANG_PLATFORM_EXPORT
# ifdef _WIN32
# define DRANG_API __declspec(dllexport)
# elif defined(__linux__)
# define DRANG_API __attribute__((visibility("default")))
# else
# error \
"Unknown platform, please implement shared library export macros"
# endif
# else
# ifdef _WIN32
# define DRANG_API __declspec(dllimport)
# elif defined(__linux__)
# define DRANG_API __attribute__((visibility("default")))
# else
# error \
"Unknown platform, please implement shared library import macros"
# endif
# endif
#else
# define DRANG_API
#endif
#ifdef __cplusplus
# define DRANG_BEGIN_DECLS extern "C" {
# define DRANG_END_DECLS }
#else
# define DRANG_BEGIN_DECLS
# define DRANG_END_DECLS
#endif
#if defined(__GNUC__) || defined(__clang__)
#define DRANG_PRINTF_ATTR(fmt_idx, arg_idx) __attribute__((format(printf, fmt_idx, arg_idx)))
#define DRANG_VPRINTF_ATTR(fmt_idx) __attribute__((format(printf, fmt_idx, 0)))
#define DRANG_ALLOC_SIZE_COUNT_ATTR(count, idx) __attribute__((alloc_size(idx, count)))
#define DRANG_ALLOC_SIZE_ATTR(idx) __attribute__((alloc_size(idx)))
#define DRANG_ALLOC_ALIGN_ATTR(idx) __attribute__((alloc_align(idx)))
#define DRANG_MALLOC_ATTR __attribute__((malloc))
#else
#define DRANG_PRINTF_ATTR(fmt_idx, arg_idx)
#define DRANG_VPRINTF_ATTR(fmt_idx)
#define DRANG_ALLOC_SIZE_COUNT_ATTR(idx, count)
#define DRANG_ALLOC_SIZE_ATTR(idx)
#define DRANG_ALLOC_ALIGN_ATTR(idx)
#define DRANG_MALLOC_ATTR
#endif