ua_util.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef UA_UTIL_H_
  2. #define UA_UTIL_H_
  3. #include "ua_config.h"
  4. /*********************/
  5. /* Memory Management */
  6. /*********************/
  7. #include <stdlib.h> // malloc, free
  8. #include <string.h> // memcpy
  9. #include <assert.h> // assert
  10. #ifdef _WIN32
  11. # include <malloc.h>
  12. #endif
  13. /* Visual Studio needs __restrict */
  14. #ifdef _MSC_VER
  15. # define UA_RESTRICT __restrict
  16. #else
  17. # define UA_RESTRICT restrict
  18. #endif
  19. /* Visual Studio does not know fnct/unistd file access results */
  20. #ifdef _MSC_VER
  21. #ifndef R_OK
  22. #define R_OK 4 /* Test for read permission. */
  23. #endif
  24. #ifndef R_OK
  25. #define W_OK 2 /* Test for write permission. */
  26. #endif
  27. #ifndef X_OK
  28. #define X_OK 1 /* Test for execute permission. */
  29. #endif
  30. #ifndef F_OK
  31. #define F_OK 0 /* Test for existence. */
  32. #endif
  33. #endif
  34. #define UA_NULL ((void *)0)
  35. // subtract from nodeids to get from the encoding to the content
  36. #define UA_ENCODINGOFFSET_XML 1
  37. #define UA_ENCODINGOFFSET_BINARY 2
  38. #define UA_assert(ignore) assert(ignore)
  39. /* Replace the macros with functions for custom allocators if necessary */
  40. #ifndef UA_free
  41. # define UA_free(ptr) free(ptr)
  42. #endif
  43. #ifndef UA_malloc
  44. # define UA_malloc(size) malloc(size)
  45. #endif
  46. #ifndef UA_calloc
  47. # define UA_calloc(num, size) calloc(num, size)
  48. #endif
  49. #ifndef UA_realloc
  50. # define UA_realloc(ptr, size) realloc(ptr, size)
  51. #endif
  52. #define UA_memcpy(dst, src, size) memcpy(dst, src, size)
  53. #define UA_memset(ptr, value, size) memset(ptr, value, size)
  54. #ifndef NO_ALLOCA
  55. # ifdef __GNUC__
  56. # define UA_alloca(size) __builtin_alloca (size)
  57. # elif defined(_WIN32)
  58. # define UA_alloca(SIZE) _alloca(SIZE)
  59. # else
  60. # include <alloca.h>
  61. # define UA_alloca(SIZE) alloca(SIZE)
  62. # endif
  63. #endif
  64. /********************/
  65. /* System Libraries */
  66. /********************/
  67. #include <stdarg.h> // va_start, va_end
  68. #include <time.h>
  69. #include <stdio.h> // printf
  70. #include <inttypes.h>
  71. #ifdef _WIN32
  72. # include <winsock2.h> //needed for amalgation
  73. # include <windows.h>
  74. # undef SLIST_ENTRY
  75. # define RAND(SEED) (UA_UInt32)rand()
  76. #else
  77. #ifdef __CYGWIN__
  78. extern int rand_r (unsigned int *__seed);
  79. #endif
  80. # include <sys/time.h>
  81. # define RAND(SEED) (UA_UInt32)rand_r(SEED)
  82. #endif
  83. /*************************/
  84. /* External Dependencies */
  85. /*************************/
  86. #include "queue.h"
  87. #ifdef UA_MULTITHREADING
  88. # define _LGPL_SOURCE
  89. # include <urcu.h>
  90. # include <urcu/wfcqueue.h>
  91. # include <urcu/uatomic.h>
  92. # include <urcu/rculfhash.h>
  93. #include <urcu/lfstack.h>
  94. #endif
  95. #endif /* UA_UTIL_H_ */