compat.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Copyright (c) 2009-2010 Satoshi Nakamoto
  3. * Copyright (c) 2009-2014 The Bitcoin developers
  4. * Copyright (c) 2013-2015 The Anoncoin Core developers
  5. *
  6. * Distributed under the MIT software license, see the accompanying
  7. * file COPYING or http://www.opensource.org/licenses/mit-license.php.
  8. *
  9. * See full documentation about SAM at http://www.i2p2.i2p/samv3.html
  10. */
  11. #pragma once
  12. #ifdef WIN32
  13. #ifdef _WIN32_WINNT
  14. #undef _WIN32_WINNT
  15. #endif // _WIN32_WINNT
  16. #define _WIN32_WINNT 0x0501
  17. #ifndef WIN32_LEAN_AND_MEAN
  18. #define WIN32_LEAN_AND_MEAN 1
  19. #endif // WIN32_LEAN_AND_MEAN
  20. #ifndef NOMINMAX
  21. #define NOMINMAX
  22. #endif // NOMINMAX
  23. #ifdef FD_SETSIZE
  24. #undef FD_SETSIZE // prevent redefinition compiler warning
  25. #endif // FD_SETSIZE
  26. #define FD_SETSIZE 1024 // max number of fds in fd_set
  27. #include <winsock2.h> // Must be included before mswsock.h and windows.h
  28. #include <mswsock.h>
  29. #include <windows.h>
  30. #include <ws2tcpip.h>
  31. #else // WIN32
  32. #include <sys/fcntl.h>
  33. #include <sys/mman.h>
  34. #include <sys/socket.h>
  35. #include <sys/types.h>
  36. #include <net/if.h>
  37. #include <netinet/in.h>
  38. #include <arpa/inet.h>
  39. #include <ifaddrs.h>
  40. #include <limits.h>
  41. #include <netdb.h>
  42. #include <unistd.h>
  43. #endif // WIN32
  44. #ifdef WIN32
  45. #define MSG_DONTWAIT 0
  46. #else // WIN32
  47. typedef u_int SOCKET;
  48. #include "errno.h"
  49. #define WSAGetLastError() errno
  50. #define WSAEINVAL EINVAL
  51. #define WSAEALREADY EALREADY
  52. #define WSAEWOULDBLOCK EWOULDBLOCK
  53. #define WSAEMSGSIZE EMSGSIZE
  54. #define WSAEINTR EINTR
  55. #define WSAEINPROGRESS EINPROGRESS
  56. #define WSAEADDRINUSE EADDRINUSE
  57. #define WSAENOTSOCK EBADF
  58. #define INVALID_SOCKET (SOCKET)(~0)
  59. #define SOCKET_ERROR -1
  60. #endif // WIN32
  61. #ifdef WIN32
  62. #ifndef S_IRUSR
  63. #define S_IRUSR 0400
  64. #define S_IWUSR 0200
  65. #endif // S_IRUSR
  66. #else // WIN32
  67. #define MAX_PATH 1024
  68. #endif // WIN32
  69. // As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0
  70. #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
  71. #define MSG_NOSIGNAL 0
  72. #endif
  73. #ifndef WIN32
  74. // PRIO_MAX is not defined on Solaris
  75. #ifndef PRIO_MAX
  76. #define PRIO_MAX 20
  77. #endif // PRIO_MAX
  78. #define THREAD_PRIORITY_LOWEST PRIO_MAX
  79. #define THREAD_PRIORITY_BELOW_NORMAL 2
  80. #define THREAD_PRIORITY_NORMAL 0
  81. #define THREAD_PRIORITY_ABOVE_NORMAL (-2)
  82. #endif // WIN32
  83. size_t strnlen_int(const char *start, size_t max_len);