| 1 |
|
| 2 |
s |
| 3 |
C |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef RIST_COMMON_ATTRIBUTES_H |
| 10 |
#define RIST_COMMON_ATTRIBUTES_H |
| 11 |
|
| 12 |
|
| 13 |
#if defined(_WIN32) || defined(__CYGWIN__) |
| 14 |
# define RIST_PRIV |
| 15 |
#else |
| 16 |
# if __GNUC__ >= 4 |
| 17 |
# define RIST_PRIV __attribute__ ((visibility ("hidden"))) |
| 18 |
# else |
| 19 |
# define RIST_PRIV |
| 20 |
# endif |
| 21 |
#endif |
| 22 |
|
| 23 |
#ifdef _WIN32 |
| 24 |
#if defined(__GNUC__) |
| 25 |
# define RIST_PACKED_STRUCT(sname,sbody) \ |
| 26 |
struct __attribute__((packed)) sname sbody; |
| 27 |
#else |
| 28 |
# define RIST_PACKED_STRUCT(sname,sbody) \ |
| 29 |
__pragma( pack(push, 1) ) \ |
| 30 |
struct sname sbody; \ |
| 31 |
__pragma( pack(pop) ) |
| 32 |
#endif |
| 33 |
#else |
| 34 |
# define RIST_PACKED_STRUCT(sname,sbody) \ |
| 35 |
struct __attribute__((packed)) sname sbody; |
| 36 |
#endif |
| 37 |
|
| 38 |
|
| 39 |
#ifdef __GNUC__ |
| 40 |
# define RIST_LIKELY(p) __builtin_expect(!!(p), 1) |
| 41 |
# define RIST_UNLIKELY(p) __builtin_expect(!!(p), 0) |
| 42 |
#else |
| 43 |
# define RIST_LIKELY(p) (!!(p)) |
| 44 |
# define RIST_UNLIKELY(p) (!!(p)) |
| 45 |
#endif |
| 46 |
|
| 47 |
#define RIST_MARK_UNUSED(unused_param) ((void)(unused_param)) |
| 48 |
|
| 49 |
#if defined(__GNUC__) && __GNUC__ >= 7 |
| 50 |
#define RIST_FALLTHROUGH ; __attribute__ ((fallthrough)) |
| 51 |
#else |
| 52 |
#define RIST_FALLTHROUGH ((void)0) |
| 53 |
#endif |
| 54 |
|
| 55 |
#ifdef _WIN32 |
| 56 |
#ifdef _WIN64 |
| 57 |
#ifdef __GNUC__ |
| 58 |
#ifndef __MINGW32__ |
| 59 |
#ifndef _SSIZE_T_DEFINED |
| 60 |
typedef long long ssize_t; |
| 61 |
#define _SSIZE_T_DEFINED |
| 62 |
#endif |
| 63 |
enum |
| 64 |
{ |
| 65 |
POLLERR=0x1, |
| 66 |
POLLHUP=0x2, |
| 67 |
POLLNVAL=0x4, |
| 68 |
POLLWRNORM=0x10, |
| 69 |
POLLWRBAND=0x20, |
| 70 |
POLLRDNORM=0x100, |
| 71 |
POLLRDBAND=0x200, |
| 72 |
POLLPRI=0x400, |
| 73 |
}; |
| 74 |
#define POLLIN (POLLRDNORM|POLLRDBAND) |
| 75 |
#define POLLOUT (POLLWRNORM|POLLWRBAND) |
| 76 |
struct pollfd |
| 77 |
{ |
| 78 |
int fd; |
| 79 |
unsigned events; |
| 80 |
unsigned revents; |
| 81 |
}; |
| 82 |
struct pollfd; |
| 83 |
#endif |
| 84 |
#else |
| 85 |
#include <stdint.h> |
| 86 |
#ifndef _SSIZE_T_DEFINED |
| 87 |
typedef int64_t ssize_t; |
| 88 |
#define _SSIZE_T_DEFINED |
| 89 |
#endif |
| 90 |
#endif |
| 91 |
#else |
| 92 |
#ifndef _SSIZE_T_DEFINED |
| 93 |
typedef signed int ssize_t; |
| 94 |
#define _SSIZE_T_DEFINED |
| 95 |
#endif |
| 96 |
#endif |
| 97 |
#endif |
| 98 |
|
| 99 |
#define STR_HELPER(x) #x |
| 100 |
#define STR(x) STR_HELPER(x) |
| 101 |
|
| 102 |
#define SET_BIT(value, pos) (value |= (1U << pos)) |
| 103 |
#define UNSET_BIT(value, pos) (value &= (1U << pos)) |
| 104 |
|
| 105 |
#endif |