UPnPsdk
0.1
Universal Plug and Play +, Software Development Kit
Loading...
Searching...
No Matches
port.hpp
Go to the documentation of this file.
1
#ifndef UPnPsdk_INCLUDE_PORT_HPP
2
#define UPnPsdk_INCLUDE_PORT_HPP
3
// Copyright (C) 2021+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
4
// Redistribution only with this Copyright remark. Last modified: 2025-02-21
12
// Header file for portable definitions
13
// ====================================
14
// This header should be includable into any source file to have portable
15
// definitions available. It should not build any inline code.
16
17
// clang-format off
18
19
// Check Debug settings. Exlusive NDEBUG or DEBUG must be set.
20
// -----------------------------------------------------------
21
#if defined(NDEBUG) && defined(DEBUG)
22
#error "NDEBUG and DEBUG are defined. Only one is possible."
23
#endif
24
#if !defined(NDEBUG) && !defined(DEBUG)
25
#error "Neither NDEBUG nor DEBUG is definded."
26
#endif
27
28
// Check that we have the correct bit size for Large-file support when this
29
// header is included into an application that uses the SDK
30
// ------------------------------------------------------------------------
31
#ifdef UPNP_LARGEFILE_SENSITIVE
32
#include <climits>
33
static_assert
(
sizeof
(off_t) * CHAR_BIT == 64,
34
"UPnPsdk has Large-file support on 32 bit architectures. "
35
"Application MUST provide LFS."
);
36
#endif
37
38
// Header file for portable <unistd.h>
39
// -----------------------------------
40
// On MS Windows <unistd.h> isn't available. We can use <io.h> instead for most
41
// functions but it's not 100% compatible.
42
#ifdef _MSC_VER
43
#include <io.h>
44
#define STDIN_FILENO 0
45
#define STDOUT_FILENO 1
46
#define STDERR_FILENO 2
47
#else
48
#include <unistd.h>
49
#endif
50
51
// Make size_t and ssize_t portable
52
// --------------------------------
53
// no ssize_t defined for VC but SSIZE_T
54
#ifdef _MSC_VER
55
#include <BaseTsd.h>
// for SSIZE_T
56
#define ssize_t SSIZE_T
57
// Needed for some uncompatible arguments on MS Windows.
58
#define SIZEP_T int
59
#define SSIZEP_T int
60
#else
61
#define SIZEP_T size_t
62
#define SSIZEP_T ssize_t
63
#endif
64
72
#ifdef __STRICT_ANSI__
73
#define UPnPsdk_INLINE __inline__
74
#else
75
#define UPnPsdk_INLINE inline
76
#endif
77
78
#ifdef _MSC_VER
79
// POSIX names for functions
80
#define strcasecmp _stricmp
81
#define strncasecmp strnicmp
82
#endif
83
84
#if (!defined(_MSC_VER) && !defined(IN6_IS_ADDR_GLOBAL)) || defined(DOXYGEN_RUN)
85
// On win32 this is a function and will not be detected by macro conditional
86
// "if defined". For detailed information look at Unit Test
87
// 'AddrinfoTestSuite.check_in6_is_addr_global'.
89
#define IN6_IS_ADDR_GLOBAL(a) \
90
((((__const uint32_t*)(a))[0] & htonl((uint32_t)0xe0000000)) == \
91
htonl((uint32_t)0x20000000))
92
#endif
93
94
// Macros to disable and enable compiler warnings
95
// ----------------------------------------------
96
// Warning 4251: 'type' : class 'type1' needs to have dll-interface to be used
97
// by clients of class 'type2'.
98
// This can be ignored for classes from the C++ STL (best if it is private).
99
#ifdef _MSC_VER
100
#define SUPPRESS_MSVC_WARN_4251_NEXT_LINE \
101
_Pragma("warning(suppress: 4251)")
102
#else
103
#define SUPPRESS_MSVC_WARN_4251_NEXT_LINE
104
#endif
105
106
#ifdef _MSC_VER
107
#define DISABLE_MSVC_WARN_4251 \
108
_Pragma("warning(push)") \
109
_Pragma("warning(disable: 4251)")
110
#else
111
#define DISABLE_MSVC_WARN_4251
112
#endif
113
114
// Warning 4273: 'function' : inconsistent DLL linkage.
115
// This is expected on propagate global variables with included header file
116
// (__declspec(dllimport)) in its source file (__declspec(dllexport)).
117
#ifdef _MSC_VER
118
#define SUPPRESS_MSVC_WARN_4273_NEXT_LINE \
119
_Pragma("warning(suppress: 4273)")
120
#else
121
#define SUPPRESS_MSVC_WARN_4273_NEXT_LINE
122
#endif
123
124
#ifdef _MSC_VER
125
#define DISABLE_MSVC_WARN_4273 \
126
_Pragma("warning(push)") \
127
_Pragma("warning(disable: 4273)")
128
#else
129
#define DISABLE_MSVC_WARN_4273
130
#endif
131
132
#ifdef _MSC_VER
133
#define ENABLE_MSVC_WARN \
134
_Pragma("warning(pop)")
135
#else
136
#define ENABLE_MSVC_WARN
137
#endif
138
139
// This has been taken from removed Compa/src/inc/upnputil.hpp
140
/* C specific */
141
/* VC needs these in C++ mode too (do other compilers?) */
142
#if !defined(__cplusplus) || defined(UPNP_USE_MSVCPP)
143
#ifdef _WIN32
144
#ifndef S_ISREG
145
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
146
#endif
147
#ifndef S_ISDIR
148
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
149
#endif
150
#define sleep(a) Sleep((a) * 1000)
151
#define usleep(a) Sleep((a) / 1000)
152
#define strerror_r(a, b, c) (strerror_s((b), (c), (a)))
153
#endif
/* _WIN32 */
154
#endif
/* !defined(__cplusplus) || defined(UPNP_USE_MSVCPP) */
155
156
// clang-format on
157
159
#endif
// UPnPsdk_INCLUDE_PORT_HPP
UPnPsdk
include
UPnPsdk
port.hpp
Generated by
1.9.8