hplatform.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #ifndef HW_PLATFORM_H_
  2. #define HW_PLATFORM_H_
  3. #include "hconfig.h"
  4. // OS
  5. #if defined(WIN64) || defined(_WIN64)
  6. #define OS_WIN64
  7. #define OS_WIN32
  8. #elif defined(WIN32)|| defined(_WIN32)
  9. #define OS_WIN32
  10. #elif defined(ANDROID) || defined(__ANDROID__)
  11. #define OS_ANDROID
  12. #define OS_LINUX
  13. #elif defined(linux) || defined(__linux) || defined(__linux__)
  14. #define OS_LINUX
  15. #elif defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))
  16. #include <TargetConditionals.h>
  17. #if defined(TARGET_OS_MAC) && TARGET_OS_MAC
  18. #define OS_MAC
  19. #define OS_DARWIN
  20. #ifdef __LP64__
  21. #define OS_DARWIN64
  22. #else
  23. #define OS_DARWIN32
  24. #endif
  25. #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
  26. #define OS_IOS
  27. #else
  28. #define OS_MACOS
  29. #endif
  30. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
  31. #define OS_FREEBSD
  32. #define OS_BSD
  33. #elif defined(__NetBSD__)
  34. #define OS_NETBSD
  35. #define OS_BSD
  36. #elif defined(__OpenBSD__)
  37. #define OS_OPENBSD
  38. #define OS_BSD
  39. #else
  40. #error "Unsupported operating system platform!"
  41. #endif
  42. #if defined(OS_WIN32) || defined(OS_WIN64)
  43. #undef OS_UNIX
  44. #define OS_WIN
  45. #else
  46. #define OS_UNIX
  47. #endif
  48. // CC
  49. // _MSC_VER
  50. #ifdef _MSC_VER
  51. #pragma warning (disable: 4100) // unused param
  52. #pragma warning (disable: 4819) // Unicode
  53. #undef HAVE_PTHREAD_H
  54. #define HAVE_PTHREAD_H 0
  55. #endif
  56. // __MINGW32__
  57. // __GNUC__
  58. #ifdef __GNUC__
  59. #ifndef _GNU_SOURCE
  60. #define _GNU_SOURCE 1
  61. #endif
  62. #endif
  63. // __clang__
  64. #ifndef BUILD_STATIC_LIB
  65. #ifdef _MSC_VER
  66. #define EXPORT __declspec(dllexport)
  67. #elif defined(__GNUC__)
  68. #define EXPORT __attribute__((visibility("default")))
  69. #else
  70. #define EXPORT
  71. #endif
  72. #else
  73. #define EXPORT
  74. #endif
  75. // ARCH
  76. #if defined(__i386) || defined(__i386__) || defined(_M_IX86)
  77. #define ARCH_X86
  78. #define ARCH_X86_32
  79. #elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
  80. #define ARCH_X64
  81. #define ARCH_X86_64
  82. #elif defined(__arm__)
  83. #define ARCH_ARM
  84. #elif defined(__aarch64__) || defined(__ARM64__)
  85. #define ARCH_ARM64
  86. #endif
  87. // ENDIAN
  88. #ifndef BIG_ENDIAN
  89. #define BIG_ENDIAN 4321
  90. #endif
  91. #ifndef LITTLE_ENDIAN
  92. #define LITTLE_ENDIAN 1234
  93. #endif
  94. #define NET_ENDIAN BIG_ENDIAN
  95. #ifndef BYTE_ORDER
  96. #if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(__ARMEL__)
  97. #define BYTE_ORDER LITTLE_ENDIAN
  98. #elif defined(__ARMEB__)
  99. #define BYTE_ORDER BIG_ENDIAN
  100. #endif
  101. #endif
  102. // header files
  103. #ifdef OS_WIN
  104. #ifndef WIN32_LEAN_AND_MEAN
  105. #define WIN32_LEAN_AND_MEAN
  106. #endif
  107. #define _CRT_NONSTDC_NO_DEPRECATE
  108. #define _CRT_SECURE_NO_WARNINGS
  109. #define _WINSOCK_DEPRECATED_NO_WARNINGS
  110. #include <winsock2.h>
  111. #include <ws2tcpip.h> // for inet_pton,inet_ntop
  112. #include <windows.h>
  113. #include <process.h> // for getpid,exec
  114. #include <direct.h> // for mkdir,rmdir,chdir,getcwd
  115. #include <io.h> // for open,close,read,write,lseek,tell
  116. #define MKDIR(dir) mkdir(dir)
  117. #else
  118. #include <unistd.h>
  119. #include <dirent.h> // for mkdir,rmdir,chdir,getcwd
  120. #include <sys/time.h> // for gettimeofday
  121. // socket
  122. #include <sys/socket.h>
  123. #include <arpa/inet.h>
  124. #include <netinet/in.h>
  125. #include <netinet/tcp.h>
  126. #include <netinet/udp.h>
  127. #include <netdb.h> // for gethostbyname
  128. #define MKDIR(dir) mkdir(dir, 0777)
  129. #endif
  130. // ANSI C
  131. #include <assert.h>
  132. #include <stddef.h>
  133. #include <stdarg.h>
  134. #include <stdio.h>
  135. #include <stdlib.h>
  136. #include <string.h>
  137. #include <ctype.h>
  138. #include <float.h>
  139. #include <limits.h>
  140. #include <time.h>
  141. #include <math.h>
  142. #include <errno.h>
  143. #include <signal.h>
  144. #if HAVE_STDBOOL_H
  145. #include <stdbool.h>
  146. #endif
  147. #if HAVE_STDINT_H
  148. #include <stdint.h>
  149. #elif defined(_MSC_VER) && _MSC_VER < 1700
  150. typedef __int8 int8_t;
  151. typedef __int16 int16_t;
  152. typedef __int32 int32_t;
  153. typedef __int64 int64_t;
  154. typedef unsigned __int8 uint8_t;
  155. typedef unsigned __int16 uint16_t;
  156. typedef unsigned __int32 uint32_t;
  157. typedef unsigned __int64 uint64_t;
  158. #endif
  159. #ifdef HAVE_SYS_TYPES_H
  160. #include <sys/types.h>
  161. #endif
  162. #if HAVE_SYS_STAT_H
  163. #include <sys/stat.h>
  164. #endif
  165. #ifdef HAVE_FCNTL_H
  166. #include <fcntl.h>
  167. #endif
  168. #ifdef HAVE_PTHREAD_H
  169. #include <pthread.h>
  170. #endif
  171. #endif // HW_PLATFORM_H_