platform.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * platform setting definition
  3. *
  4. * (c) Philippe, philippe_44@outlook.com
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #ifndef __PLATFORM_H
  21. #define __PLATFORM_H
  22. #ifdef WIN32
  23. #define LINUX 0
  24. #define WIN 1
  25. #else
  26. #define LINUX 1
  27. #define WIN 0
  28. #endif
  29. #include <stdbool.h>
  30. #include <signal.h>
  31. #include <sys/stat.h>
  32. #ifdef WIN32
  33. #include <winsock2.h>
  34. #include <ws2tcpip.h>
  35. #include <io.h>
  36. #include <iphlpapi.h>
  37. #include <sys/timeb.h>
  38. typedef unsigned __int8 u8_t;
  39. typedef unsigned __int16 u16_t;
  40. typedef unsigned __int32 u32_t;
  41. typedef unsigned __int64 u64_t;
  42. typedef __int16 s16_t;
  43. typedef __int32 s32_t;
  44. typedef __int64 s64_t;
  45. #define inline __inline
  46. int gettimeofday(struct timeval *tv, struct timezone *tz);
  47. char *strcasestr(const char *haystack, const char *needle);
  48. #define usleep(x) Sleep((x)/1000)
  49. #define sleep(x) Sleep((x)*1000)
  50. #define last_error() WSAGetLastError()
  51. #define ERROR_WOULDBLOCK WSAEWOULDBLOCK
  52. #define open _open
  53. #define read _read
  54. #define poll WSAPoll
  55. #define snprintf _snprintf
  56. #define strcasecmp stricmp
  57. #define _random(x) random(x)
  58. #define VALGRIND_MAKE_MEM_DEFINED(x,y)
  59. #define S_ADDR(X) X.S_un.S_addr
  60. #define in_addr_t u32_t
  61. #define socklen_t int
  62. #define ssize_t int
  63. #define RTLD_NOW 0
  64. #else
  65. #include <strings.h>
  66. #include <sys/types.h>
  67. #include <unistd.h>
  68. #include <inttypes.h>
  69. /*
  70. #include <netinet/in.h>
  71. #include <netinet/tcp.h>
  72. #include <sys/time.h>
  73. #include <netdb.h>
  74. */
  75. #include <arpa/inet.h>
  76. #include <sys/socket.h>
  77. #include <sys/poll.h>
  78. #include <lwip/inet.h>
  79. #include <pthread.h>
  80. #include <errno.h>
  81. #define min(a,b) (((a) < (b)) ? (a) : (b))
  82. #define max(a,b) (((a) > (b)) ? (a) : (b))
  83. typedef int16_t s16_t;
  84. typedef int32_t s32_t;
  85. typedef int64_t s64_t;
  86. typedef uint8_t u8_t;
  87. typedef uint16_t u16_t;
  88. typedef uint32_t u32_t;
  89. typedef unsigned long long u64_t;
  90. #define last_error() errno
  91. #define ERROR_WOULDBLOCK EWOULDBLOCK
  92. char *strlwr(char *str);
  93. #define _random(x) random()
  94. #define closesocket(s) close(s)
  95. #define S_ADDR(X) X.s_addr
  96. #endif
  97. typedef struct ntp_s {
  98. u32_t seconds;
  99. u32_t fraction;
  100. } ntp_t;
  101. u64_t timeval_to_ntp(struct timeval tv, struct ntp_s *ntp);
  102. u64_t get_ntp(struct ntp_s *ntp);
  103. // we expect somebody to provide the ms clock, system-wide
  104. u32_t _gettime_ms_(void);
  105. #define gettime_ms _gettime_ms_
  106. #endif // __PLATFORM