[IOT-1911] Make resource/csdk/stack W4 compliant.
[platform/upstream/iotivity.git] / resource / c_common / platform_features.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //******************************************************************
20
21 /**
22  * @file
23  *
24  * This file contains compiler and platform feature definitions.  These
25  * can be used to enable functionality on only platforms that support
26  * said functionality.
27  */
28
29 #ifndef PLATFORM_FEATURES_H_
30 #define PLATFORM_FEATURES_H_
31
32
33 #if (__cplusplus >=201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__)
34 #  define SUPPORTS_DEFAULT_CTOR
35 #endif
36
37 #if (__STDC_VERSION__ >= 201112L)
38 #  include <assert.h>
39 #  define OC_STATIC_ASSERT(condition, msg) static_assert(condition, msg)
40 #elif defined(_WIN32)
41 #  if defined(__msys_nt__) && !defined(__cplusplus)
42 #    define static_assert _Static_assert
43 #  endif
44 #  define OC_STATIC_ASSERT(condition, msg) static_assert(condition, msg)
45 #else
46 #  define OC_STATIC_ASSERT(condition, msg) ((void)sizeof(char[2*!!(condition) - 1]))
47 #endif
48
49 #ifndef INLINE_API
50 #  if defined(__cplusplus)
51 #    define INLINE_API inline
52 #  else
53 #    ifdef _MSC_VER
54 #      define INLINE_API static __inline
55 #    else
56 #      define INLINE_API static inline
57 #    endif
58 #  endif
59 #endif
60
61 #ifdef _MSC_VER
62 #  define OC_ANNOTATE_UNUSED
63 #else
64 #  define OC_ANNOTATE_UNUSED  __attribute__((unused))
65 #endif
66
67 #ifdef _WIN32
68 #  define __func__ __FUNCTION__
69 #  define strncasecmp _strnicmp
70 #  define strtok_r strtok_s
71 #  if _MSC_VER && (_MSC_VER < 1900)
72 #    include "windows/include/vs12_snprintf.h"
73 #  endif
74 #  define ssize_t SSIZE_T
75 #  define SHUT_RDWR           SD_BOTH
76 #  define sleep(SECS)         Sleep(1000*(SECS))
77 #  ifdef __cplusplus
78 #    define SUPPORTS_DEFAULT_CTOR
79 #  endif
80 #  include "windows/include/memmem.h"
81 #  include "windows/include/win_sleep.h"
82 #  include "windows/include/pthread_create.h"
83 #endif
84
85 #ifdef HAVE_WINSOCK2_H
86 #  define OPTVAL_T(t)    (const char*)(t)
87 #  define OC_CLOSE_SOCKET(s) closesocket(s)
88 #else
89 #  define OPTVAL_T(t)    (t)
90 #  define OC_CLOSE_SOCKET(s) close(s)
91 #endif
92
93 #ifndef SIZE_MAX
94 /* Some systems fail to define SIZE_MAX in <stdint.h>, even though C99 requires it...
95  * Conversion from signed to unsigned is defined in 6.3.1.3 (Signed and unsigned integers) p2,
96  * which says: "the value is converted by repeatedly adding or subtracting one more than the
97  * maximum value that can be represented in the new type until the value is in the range of the
98  * new type."
99  * So -1 gets converted to size_t by adding SIZE_MAX + 1, which results in SIZE_MAX.
100  */
101 #  define SIZE_MAX ((size_t)-1)
102 #endif
103
104 #ifdef WITH_ARDUINO
105 /**
106  * UINT16_MAX does not appear to be defined on Arduino so we define it here.
107  */
108 #  define UINT16_MAX 65535
109 #endif
110
111 #endif