platform.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * platform setting definition
  3. *
  4. * (c) Philippe, philippe_44@outlook.com
  5. *
  6. * This software is released under the MIT License.
  7. * https://opensource.org/licenses/MIT
  8. *
  9. */
  10. #ifndef __PLATFORM_H
  11. #define __PLATFORM_H
  12. #ifdef WIN32
  13. #define LINUX 0
  14. #define WIN 1
  15. #else
  16. #define LINUX 1
  17. #define WIN 0
  18. #endif
  19. #include <stdbool.h>
  20. #include <signal.h>
  21. #include <sys/stat.h>
  22. #ifdef WIN32
  23. #include <winsock2.h>
  24. #include <ws2tcpip.h>
  25. #include <io.h>
  26. #include <iphlpapi.h>
  27. #include <sys/timeb.h>
  28. typedef unsigned __int8 u8_t;
  29. typedef unsigned __int16 u16_t;
  30. typedef unsigned __int32 u32_t;
  31. typedef unsigned __int64 u64_t;
  32. typedef __int16 s16_t;
  33. typedef __int32 s32_t;
  34. typedef __int64 s64_t;
  35. #define inline __inline
  36. int gettimeofday(struct timeval *tv, struct timezone *tz);
  37. char *strcasestr(const char *haystack, const char *needle);
  38. #define usleep(x) Sleep((x)/1000)
  39. #define sleep(x) Sleep((x)*1000)
  40. #define last_error() WSAGetLastError()
  41. #define ERROR_WOULDBLOCK WSAEWOULDBLOCK
  42. #define open _open
  43. #define read _read
  44. #define poll WSAPoll
  45. #define snprintf _snprintf
  46. #define strcasecmp stricmp
  47. #define _random(x) random(x)
  48. #define VALGRIND_MAKE_MEM_DEFINED(x,y)
  49. #define S_ADDR(X) X.S_un.S_addr
  50. #define in_addr_t u32_t
  51. #define socklen_t int
  52. #define ssize_t int
  53. #define RTLD_NOW 0
  54. #else
  55. #include <strings.h>
  56. #include <sys/types.h>
  57. #include <unistd.h>
  58. #include <inttypes.h>
  59. /*
  60. #include <netinet/in.h>
  61. #include <netinet/tcp.h>
  62. #include <sys/time.h>
  63. #include <netdb.h>
  64. */
  65. #include <arpa/inet.h>
  66. #include <sys/socket.h>
  67. #include <sys/poll.h>
  68. #include <lwip/inet.h>
  69. #include <pthread.h>
  70. #include <errno.h>
  71. #define min(a,b) (((a) < (b)) ? (a) : (b))
  72. #define max(a,b) (((a) > (b)) ? (a) : (b))
  73. typedef int16_t s16_t;
  74. typedef int32_t s32_t;
  75. typedef int64_t s64_t;
  76. typedef uint8_t u8_t;
  77. typedef uint16_t u16_t;
  78. typedef uint32_t u32_t;
  79. typedef unsigned long long u64_t;
  80. #define last_error() errno
  81. #define ERROR_WOULDBLOCK EWOULDBLOCK
  82. char *strlwr(char *str);
  83. #define _random(x) random()
  84. #define closesocket(s) close(s)
  85. #define S_ADDR(X) X.s_addr
  86. #endif
  87. typedef struct ntp_s {
  88. u32_t seconds;
  89. u32_t fraction;
  90. } ntp_t;
  91. u64_t timeval_to_ntp(struct timeval tv, struct ntp_s *ntp);
  92. u64_t get_ntp(struct ntp_s *ntp);
  93. // we expect somebody to provide the ms clock, system-wide
  94. u32_t _gettime_ms_(void);
  95. #define gettime_ms _gettime_ms_
  96. #endif // __PLATFORM