ua_util.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef UA_UTIL_H_
  2. #define UA_UTIL_H_
  3. #ifndef UA_AMALGAMATE
  4. # include "ua_config.h"
  5. #endif
  6. #ifndef __USE_POSIX
  7. # define __USE_POSIX
  8. #endif
  9. #ifndef _POSIX_SOURCE
  10. # define _POSIX_SOURCE
  11. # define _POSIX_C_SOURCE 199309L
  12. #endif
  13. #ifndef _BSD_SOURCE
  14. # define _BSD_SOURCE
  15. #endif
  16. /*********************/
  17. /* Memory Management */
  18. /*********************/
  19. #include <stdlib.h> // malloc, free
  20. #include <string.h> // memcpy
  21. #include <assert.h> // assert
  22. #ifdef _WIN32
  23. # include <malloc.h>
  24. #else
  25. # include <alloca.h>
  26. #endif
  27. #define UA_NULL ((void *)0)
  28. // subtract from nodeids to get from the encoding to the content
  29. #define UA_ENCODINGOFFSET_XML 1
  30. #define UA_ENCODINGOFFSET_BINARY 2
  31. #define UA_assert(ignore) assert(ignore)
  32. /* Replace the macros with functions for custom allocators if necessary */
  33. #define UA_free(ptr) free(ptr)
  34. #define UA_malloc(size) malloc(size)
  35. #define UA_calloc(num, size) calloc(num, size)
  36. #define UA_realloc(ptr, size) realloc(ptr, size)
  37. #define UA_memcpy(dst, src, size) memcpy(dst, src, size)
  38. #define UA_memset(ptr, value, size) memset(ptr, value, size)
  39. #ifdef _WIN32
  40. # define UA_alloca(SIZE) _alloca(SIZE)
  41. #else
  42. # define UA_alloca(SIZE) alloca(SIZE)
  43. #endif
  44. /********************/
  45. /* System Libraries */
  46. /********************/
  47. #include <stdarg.h> // va_start, va_end
  48. #include <time.h>
  49. #include <stdio.h> // printf
  50. #include <inttypes.h>
  51. #ifdef _WIN32
  52. # include <windows.h>
  53. # undef SLIST_ENTRY
  54. # define RAND(SEED) (UA_UInt32)rand()
  55. #else
  56. # include <endian.h>
  57. # include <sys/time.h>
  58. # define RAND(SEED) (UA_UInt32)rand_r(SEED)
  59. #endif
  60. /*************************/
  61. /* External Dependencies */
  62. /*************************/
  63. #ifndef UA_AMALGAMATE
  64. # include "queue.h"
  65. #endif
  66. #ifdef UA_MULTITHREADING
  67. # define _LGPL_SOURCE
  68. # include <urcu.h>
  69. # include <urcu/wfcqueue.h>
  70. # include <urcu/compiler.h> // for caa_container_of
  71. # include <urcu/uatomic.h>
  72. # include <urcu/rculfhash.h>
  73. #endif
  74. #endif /* UA_UTIL_H_ */