Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5563 serge 1
/**************************************************************************
2
 *
3
 * Copyright 2007-2013 VMware, Inc.
4
 * All Rights Reserved.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the
8
 * "Software"), to deal in the Software without restriction, including
9
 * without limitation the rights to use, copy, modify, merge, publish,
10
 * distribute, sub license, and/or sell copies of the Software, and to
11
 * permit persons to whom the Software is furnished to do so, subject to
12
 * the following conditions:
13
 *
14
 * The above copyright notice and this permission notice (including the
15
 * next paragraph) shall be included in all copies or substantial portions
16
 * of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21
 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 *
26
 **************************************************************************/
27
 
28
#ifndef _C99_COMPAT_H_
29
#define _C99_COMPAT_H_
30
 
31
 
32
/*
33
 * MSVC hacks.
34
 */
35
#if defined(_MSC_VER)
36
   /*
37
    * Visual Studio 2012 will complain if we define the `inline` keyword, but
38
    * actually it only supports the keyword on C++.
39
    *
40
    * To avoid this the _ALLOW_KEYWORD_MACROS must be set.
41
    */
42
#  if (_MSC_VER >= 1700) && !defined(_ALLOW_KEYWORD_MACROS)
43
#    define _ALLOW_KEYWORD_MACROS
44
#  endif
45
 
46
   /*
47
    * XXX: MSVC has a `__restrict` keyword, but it also has a
48
    * `__declspec(restrict)` modifier, so it is impossible to define a
49
    * `restrict` macro without interfering with the latter.  Furthermore the
50
    * MSVC standard library uses __declspec(restrict) under the _CRTRESTRICT
51
    * macro.  For now resolve this issue by redefining _CRTRESTRICT, but going
52
    * forward we should probably should stop using restrict, especially
53
    * considering that our code does not obbey strict aliasing rules any way.
54
    */
55
#  include 
56
#  undef _CRTRESTRICT
57
#  define _CRTRESTRICT
58
#endif
59
 
60
 
61
/*
62
 * C99 inline keyword
63
 */
64
#ifndef inline
65
#  ifdef __cplusplus
66
     /* C++ supports inline keyword */
67
#  elif defined(__GNUC__)
68
#    define inline __inline__
69
#  elif defined(_MSC_VER)
70
#    define inline __inline
71
#  elif defined(__ICL)
72
#    define inline __inline
73
#  elif defined(__INTEL_COMPILER)
74
     /* Intel compiler supports inline keyword */
75
#  elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
76
#    define inline __inline
77
#  elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
78
     /* C99 supports inline keyword */
79
#  elif (__STDC_VERSION__ >= 199901L)
80
     /* C99 supports inline keyword */
81
#  else
82
#    define inline
83
#  endif
84
#endif
85
 
86
 
87
/*
88
 * C99 restrict keyword
89
 *
90
 * See also:
91
 * - http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html
92
 */
93
#ifndef restrict
94
#  if (__STDC_VERSION__ >= 199901L)
95
     /* C99 */
96
#  elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
97
     /* C99 */
98
#  elif defined(__GNUC__)
99
#    define restrict __restrict__
100
#  elif defined(_MSC_VER)
101
#    define restrict __restrict
102
#  else
103
#    define restrict /* */
104
#  endif
105
#endif
106
 
107
 
108
/*
109
 * C99 __func__ macro
110
 */
111
#ifndef __func__
112
#  if (__STDC_VERSION__ >= 199901L)
113
     /* C99 */
114
#  elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
115
     /* C99 */
116
#  elif defined(__GNUC__)
117
#    if __GNUC__ >= 2
118
#      define __func__ __FUNCTION__
119
#    else
120
#      define __func__ ""
121
#    endif
122
#  elif defined(_MSC_VER)
123
#    if _MSC_VER >= 1300
124
#      define __func__ __FUNCTION__
125
#    else
126
#      define __func__ ""
127
#    endif
128
#  else
129
#    define __func__ ""
130
#  endif
131
#endif
132
 
133
 
134
/* Simple test case for debugging */
135
#if 0
136
static inline const char *
137
test_c99_compat_h(const void * restrict a,
138
                  const void * restrict b)
139
{
140
   return __func__;
141
}
142
#endif
143
 
144
 
145
#endif /* _C99_COMPAT_H_ */