/home/travis/build/open62541/open62541/src/ua_util.h
Go to the documentation of this file.
00001 #ifndef UA_UTIL_H_
00002 #define UA_UTIL_H_
00003 
00004 #ifndef UA_AMALGAMATE
00005 # include "ua_config.h"
00006 #endif
00007 
00008 #ifndef __USE_POSIX
00009 # define __USE_POSIX
00010 #endif
00011 #ifndef _POSIX_SOURCE
00012 # define _POSIX_SOURCE
00013 #endif
00014 #ifndef _POSIX_C_SOURCE
00015 # define _POSIX_C_SOURCE 199309L
00016 #endif
00017 #ifndef _BSD_SOURCE
00018 # define _BSD_SOURCE
00019 #endif
00020 #ifndef _DEFAULT_SOURCE
00021 # define _DEFAULT_SOURCE
00022 #endif
00023 
00024 /*********************/
00025 /* Memory Management */
00026 /*********************/
00027 
00028 #include <stdlib.h> // malloc, free
00029 #include <string.h> // memcpy
00030 #include <assert.h> // assert
00031 
00032 #ifdef _WIN32
00033 # include <malloc.h>
00034 #endif
00035 
00036 #define UA_NULL ((void *)0)
00037 
00038 // subtract from nodeids to get from the encoding to the content
00039 #define UA_ENCODINGOFFSET_XML 1
00040 #define UA_ENCODINGOFFSET_BINARY 2
00041 
00042 #define UA_assert(ignore) assert(ignore)
00043 
00044 /* Replace the macros with functions for custom allocators if necessary */
00045 #define UA_free(ptr) free(ptr)
00046 #define UA_malloc(size) malloc(size)
00047 #define UA_calloc(num, size) calloc(num, size)
00048 #define UA_realloc(ptr, size) realloc(ptr, size)
00049 #define UA_memcpy(dst, src, size) memcpy(dst, src, size)
00050 #define UA_memset(ptr, value, size) memset(ptr, value, size)
00051 
00052 #ifdef _WIN32
00053     # define UA_alloca(SIZE) _alloca(SIZE)
00054 #else
00055  #ifdef __GNUC__
00056     # define UA_alloca(size)   __builtin_alloca (size)
00057  #else
00058     # include <alloca.h>
00059     # define UA_alloca(SIZE) alloca(SIZE)
00060  #endif
00061 #endif
00062 
00063 /********************/
00064 /* System Libraries */
00065 /********************/
00066 
00067 #include <stdarg.h> // va_start, va_end
00068 #include <time.h>
00069 #include <stdio.h> // printf
00070 #include <inttypes.h>
00071 
00072 #ifdef _WIN32
00073 # include <winsock2.h> //needed for amalgation
00074 # include <windows.h>
00075 # undef SLIST_ENTRY
00076 # define RAND(SEED) (UA_UInt32)rand()
00077 #else
00078 # include <endian.h>
00079 # include <sys/time.h>
00080 # define RAND(SEED) (UA_UInt32)rand_r(SEED)
00081 #endif
00082 
00083 /*************************/
00084 /* External Dependencies */
00085 /*************************/
00086 
00087 #ifndef UA_AMALGAMATE
00088 # include "queue.h"
00089 #endif
00090 
00091 #ifdef UA_MULTITHREADING
00092 # define _LGPL_SOURCE
00093 # include <urcu.h>
00094 # include <urcu/wfcqueue.h>
00095 # include <urcu/compiler.h> // for caa_container_of
00096 # include <urcu/uatomic.h>
00097 # include <urcu/rculfhash.h>
00098 #endif
00099 
00100 #endif /* UA_UTIL_H_ */