Files
thehub/libs/utils/compat.h
T

121 lines
3.0 KiB
C
Raw Permalink Normal View History

2017-11-09 19:34:51 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2009-2010 Satoshi Nakamoto
* Copyright (C) 2009-2015 The Bitcoin Core developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2013-04-13 00:13:08 -05:00
2018-01-16 10:47:52 +00:00
#ifndef FLOWEE_COMPAT_H
#define FLOWEE_COMPAT_H
2012-01-03 23:33:31 +01:00
2014-11-26 08:19:07 +01:00
#if defined(HAVE_CONFIG_H)
2018-01-16 10:47:52 +00:00
#include "config/flowee-config.h"
2014-11-26 08:19:07 +01:00
#endif
2012-04-15 22:10:54 +02:00
#ifdef WIN32
2013-10-11 15:37:36 +02:00
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
2012-04-15 22:10:54 +02:00
#define _WIN32_WINNT 0x0501
#ifndef WIN32_LEAN_AND_MEAN
2012-04-15 22:10:54 +02:00
#define WIN32_LEAN_AND_MEAN 1
#endif
2012-04-15 22:10:54 +02:00
#ifndef NOMINMAX
#define NOMINMAX
#endif
2013-10-11 15:37:36 +02:00
#ifdef FD_SETSIZE
#undef FD_SETSIZE // prevent redefinition compiler warning
#endif
#define FD_SETSIZE 1024 // max number of fds in fd_set
2013-04-13 00:13:08 -05:00
#include <winsock2.h> // Must be included before mswsock.h and windows.h
#include <mswsock.h>
#include <windows.h>
2012-04-15 22:10:54 +02:00
#include <ws2tcpip.h>
#else
2013-04-13 00:13:08 -05:00
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <sys/socket.h>
2014-05-02 20:45:03 +02:00
#include <sys/types.h>
#include <net/if.h>
#include <netinet/in.h>
2015-10-21 23:52:29 +00:00
#include <netinet/tcp.h>
2014-05-02 20:45:03 +02:00
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <climits>
2014-05-02 20:45:03 +02:00
#include <netdb.h>
2013-04-13 00:13:08 -05:00
#include <unistd.h>
2012-04-15 22:10:54 +02:00
#endif
2012-01-03 23:33:31 +01:00
#ifdef WIN32
#define MSG_DONTWAIT 0
#else
2013-07-24 14:53:45 +02:00
typedef u_int SOCKET;
2012-01-03 23:33:31 +01:00
#include "errno.h"
#define WSAGetLastError() errno
#define WSAEINVAL EINVAL
#define WSAEALREADY EALREADY
#define WSAEWOULDBLOCK EWOULDBLOCK
#define WSAEMSGSIZE EMSGSIZE
#define WSAEINTR EINTR
#define WSAEINPROGRESS EINPROGRESS
#define WSAEADDRINUSE EADDRINUSE
#define WSAENOTSOCK EBADF
#define INVALID_SOCKET (SOCKET)(~0)
#define SOCKET_ERROR -1
#endif
#ifdef WIN32
#ifndef S_IRUSR
#define S_IRUSR 0400
#define S_IWUSR 0200
#endif
#else
#define MAX_PATH 1024
#endif
// As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0
#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
#define MSG_NOSIGNAL 0
2018-08-07 12:56:15 +00:00
#elif defined(__APPLE__)
#define MSG_NOSIGNAL SO_NOSIGPIPE
#endif
#ifndef WIN32
// PRIO_MAX is not defined on Solaris
#ifndef PRIO_MAX
#define PRIO_MAX 20
#endif
#define THREAD_PRIORITY_LOWEST PRIO_MAX
#define THREAD_PRIORITY_BELOW_NORMAL 2
#define THREAD_PRIORITY_NORMAL 0
#define THREAD_PRIORITY_ABOVE_NORMAL (-2)
#endif
#if HAVE_DECL_STRNLEN == 0
size_t strnlen( const char *start, size_t max_len);
#endif // HAVE_DECL_STRNLEN
bool static inline IsSelectableSocket(SOCKET s) {
#ifdef WIN32
return true;
#else
2015-07-20 17:10:02 +02:00
return (s < FD_SETSIZE);
#endif
}
2018-01-16 10:47:52 +00:00
#endif