6 #define UNUSED_ATTR __attribute__((unused))
7 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
8 #define INVALID_FD (-1)
10 #define CONCAT(a, b) a##b
12 // Use during compile time to check conditional values
13 // NOTE: The the failures will present as a generic error
14 // "error: initialization makes pointer from integer without a cast"
15 // but the file and line number will present the condition that
17 #define DUMMY_COUNTER(c) CONCAT(__osi_dummy_, c)
18 #define DUMMY_PTR DUMMY_COUNTER(__COUNTER__)
20 // base/macros.h defines a COMPILE_ASSERT macro to the C++11 keyword
21 // "static_assert" (it undef's COMPILE_ASSERT before redefining it).
22 // C++ code that includes base and osi/include/osi.h can thus easily default to
23 // the definition from libbase but we should check here to avoid compile errors.
24 #ifndef COMPILE_ASSERT
25 #define COMPILE_ASSERT(x) char * DUMMY_PTR = !(x)
26 #endif // COMPILE_ASSERT
28 typedef uint32_t timeout_t;
30 // Macros for safe integer to pointer conversion. In the C language, data is
31 // commonly cast to opaque pointer containers and back for generic parameter
32 // passing in callbacks. These macros should be used sparingly in new code
33 // (never in C++ code). Whenever integers need to be passed as a pointer, use
35 #define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p)))
36 #define UINT_TO_PTR(u) ((void *) ((uintptr_t) (u)))
38 #define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
39 #define INT_TO_PTR(i) ((void *) ((intptr_t) (i)))