diff options
Diffstat (limited to 'src/zix/common.h')
-rw-r--r-- | src/zix/common.h | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/src/zix/common.h b/src/zix/common.h index 9318d0e..f7ec4c3 100644 --- a/src/zix/common.h +++ b/src/zix/common.h @@ -17,6 +17,8 @@ #ifndef ZIX_COMMON_H #define ZIX_COMMON_H +#include <stdbool.h> + /** @addtogroup zix @{ @@ -44,18 +46,40 @@ # define ZIX_API # define ZIX_PRIVATE static #endif + +#ifdef __GNUC__ +# define ZIX_PURE_FUNC __attribute__((pure)) +# define ZIX_CONST_FUNC __attribute__((const)) +# define ZIX_MALLOC_FUNC __attribute__((malloc)) +#else +# define ZIX_PURE_FUNC +# define ZIX_CONST_FUNC +# define ZIX_MALLOC_FUNC +#endif + +#define ZIX_PURE_API ZIX_API ZIX_PURE_FUNC +#define ZIX_CONST_API ZIX_API ZIX_CONST_FUNC +#define ZIX_MALLOC_API ZIX_API ZIX_MALLOC_FUNC + /** @endcond */ #ifdef __cplusplus extern "C" { -#else -# include <stdbool.h> #endif #ifdef __GNUC__ -#define ZIX_UNUSED __attribute__((__unused__)) +#define ZIX_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1))) +#else +#define ZIX_LOG_FUNC(fmt, arg1) +#endif + +// Unused parameter macro to suppresses warnings and make it impossible to use +#if defined(__cplusplus) +# define ZIX_UNUSED(name) +#elif defined(__GNUC__) +# define ZIX_UNUSED(name) name##_unused __attribute__((__unused__)) #else -#define ZIX_UNUSED +# define ZIX_UNUSED(name) name #endif typedef enum { @@ -72,20 +96,13 @@ static inline const char* zix_strerror(const ZixStatus status) { switch (status) { - case ZIX_STATUS_SUCCESS: - return "Success"; - case ZIX_STATUS_ERROR: - return "Unknown error"; - case ZIX_STATUS_NO_MEM: - return "Out of memory"; - case ZIX_STATUS_NOT_FOUND: - return "Not found"; - case ZIX_STATUS_EXISTS: - return "Exists"; - case ZIX_STATUS_BAD_ARG: - return "Bad argument"; - case ZIX_STATUS_BAD_PERMS: - return "Bad permissions"; + case ZIX_STATUS_SUCCESS: return "Success"; + case ZIX_STATUS_ERROR: return "Unknown error"; + case ZIX_STATUS_NO_MEM: return "Out of memory"; + case ZIX_STATUS_NOT_FOUND: return "Not found"; + case ZIX_STATUS_EXISTS: return "Exists"; + case ZIX_STATUS_BAD_ARG: return "Bad argument"; + case ZIX_STATUS_BAD_PERMS: return "Bad permissions"; } return "Unknown error"; } @@ -93,7 +110,9 @@ zix_strerror(const ZixStatus status) /** Function for comparing two elements. */ -typedef int (*ZixComparator)(const void* a, const void* b, void* user_data); +typedef int (*ZixComparator)(const void* a, + const void* b, + const void* user_data); /** Function for testing equality of two elements. |