Xfuncproto.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. *
  3. Copyright 1989, 1991, 1998 The Open Group
  4. Permission to use, copy, modify, distribute, and sell this software and its
  5. documentation for any purpose is hereby granted without fee, provided that
  6. the above copyright notice appear in all copies and that both that
  7. copyright notice and this permission notice appear in supporting
  8. documentation.
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  15. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall not be
  18. used in advertising or otherwise to promote the sale, use or other dealings
  19. in this Software without prior written authorization from The Open Group.
  20. *
  21. */
  22. /* Definitions to make function prototypes manageable */
  23. #ifndef _XFUNCPROTO_H_
  24. #define _XFUNCPROTO_H_
  25. #ifndef NeedFunctionPrototypes
  26. #define NeedFunctionPrototypes 1
  27. #endif /* NeedFunctionPrototypes */
  28. #ifndef NeedVarargsPrototypes
  29. #define NeedVarargsPrototypes 1
  30. #endif /* NeedVarargsPrototypes */
  31. #if NeedFunctionPrototypes
  32. #ifndef NeedNestedPrototypes
  33. #define NeedNestedPrototypes 1
  34. #endif /* NeedNestedPrototypes */
  35. #ifndef _Xconst
  36. #define _Xconst const
  37. #endif /* _Xconst */
  38. /* Function prototype configuration (see configure for more info) */
  39. #if !defined(NARROWPROTO) && \
  40. (defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__))
  41. #define NARROWPROTO
  42. #endif
  43. #ifndef FUNCPROTO
  44. #define FUNCPROTO 15
  45. #endif
  46. #ifndef NeedWidePrototypes
  47. #ifdef NARROWPROTO
  48. #define NeedWidePrototypes 0
  49. #else
  50. #define NeedWidePrototypes 1 /* default to make interropt. easier */
  51. #endif
  52. #endif /* NeedWidePrototypes */
  53. #endif /* NeedFunctionPrototypes */
  54. #ifndef _XFUNCPROTOBEGIN
  55. #if defined(__cplusplus) || defined(c_plusplus) /* for C++ V2.0 */
  56. #define _XFUNCPROTOBEGIN extern "C" { /* do not leave open across includes */
  57. #define _XFUNCPROTOEND }
  58. #else
  59. #define _XFUNCPROTOBEGIN
  60. #define _XFUNCPROTOEND
  61. #endif
  62. #endif /* _XFUNCPROTOBEGIN */
  63. /* http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute */
  64. #ifndef __has_attribute
  65. # define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
  66. #endif
  67. #ifndef __has_feature
  68. # define __has_feature(x) 0 /* Compatibility with non-clang compilers. */
  69. #endif
  70. #ifndef __has_extension
  71. # define __has_extension(x) 0 /* Compatibility with non-clang compilers. */
  72. #endif
  73. /* Added in X11R6.9, so available in any version of modular xproto */
  74. #if __has_attribute(__sentinel__) || (defined(__GNUC__) && (__GNUC__ >= 4))
  75. # define _X_SENTINEL(x) __attribute__ ((__sentinel__(x)))
  76. #else
  77. # define _X_SENTINEL(x)
  78. #endif /* GNUC >= 4 */
  79. /* Added in X11R6.9, so available in any version of modular xproto */
  80. #if (__has_attribute(visibility) || (defined(__GNUC__) && (__GNUC__ >= 4))) \
  81. && !defined(__CYGWIN__) && !defined(__MINGW32__)
  82. # define _X_EXPORT __attribute__((visibility("default")))
  83. # define _X_HIDDEN __attribute__((visibility("hidden")))
  84. # define _X_INTERNAL __attribute__((visibility("internal")))
  85. #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
  86. # define _X_EXPORT __global
  87. # define _X_HIDDEN __hidden
  88. # define _X_INTERNAL __hidden
  89. #else /* not gcc >= 4 and not Sun Studio >= 8 */
  90. # define _X_EXPORT
  91. # define _X_HIDDEN
  92. # define _X_INTERNAL
  93. #endif /* GNUC >= 4 */
  94. /* Branch prediction hints for individual conditionals */
  95. /* requires xproto >= 7.0.9 */
  96. #if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303)
  97. # define _X_LIKELY(x) __builtin_expect(!!(x), 1)
  98. # define _X_UNLIKELY(x) __builtin_expect(!!(x), 0)
  99. #else /* not gcc >= 3.3 */
  100. # define _X_LIKELY(x) (x)
  101. # define _X_UNLIKELY(x) (x)
  102. #endif
  103. /* Bulk branch prediction hints via marking error path functions as "cold" */
  104. /* requires xproto >= 7.0.25 */
  105. #if __has_attribute(__cold__) || \
  106. (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) /* 4.3+ */
  107. # define _X_COLD __attribute__((__cold__))
  108. #else
  109. # define _X_COLD /* nothing */
  110. #endif
  111. /* Added in X11R6.9, so available in any version of modular xproto */
  112. #if __has_attribute(deprecated) \
  113. || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 301)) \
  114. || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5130))
  115. # define _X_DEPRECATED __attribute__((deprecated))
  116. #else /* not gcc >= 3.1 */
  117. # define _X_DEPRECATED
  118. #endif
  119. /* requires xproto >= 7.0.30 */
  120. #if __has_extension(attribute_deprecated_with_message) || \
  121. (defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))))
  122. # define _X_DEPRECATED_MSG(_msg) __attribute__((deprecated(_msg)))
  123. #else
  124. # define _X_DEPRECATED_MSG(_msg) _X_DEPRECATED
  125. #endif
  126. /* requires xproto >= 7.0.17 */
  127. #if __has_attribute(noreturn) \
  128. || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
  129. || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
  130. # define _X_NORETURN __attribute((noreturn))
  131. #else
  132. # define _X_NORETURN
  133. #endif /* GNUC */
  134. /* Added in X11R6.9, so available in any version of modular xproto */
  135. #if __has_attribute(__format__) \
  136. || defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)
  137. # define _X_ATTRIBUTE_PRINTF(x,y) __attribute__((__format__(__printf__,x,y)))
  138. #else /* not gcc >= 2.3 */
  139. # define _X_ATTRIBUTE_PRINTF(x,y)
  140. #endif
  141. /* requires xproto >= 7.0.22 - since this uses either gcc or C99 variable
  142. argument macros, must be only used inside #ifdef _X_NONNULL guards, as
  143. many legacy X clients are compiled in C89 mode still. */
  144. #if __has_attribute(nonnull) \
  145. && defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */
  146. #define _X_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
  147. #elif __has_attribute(nonnull) \
  148. || defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303)
  149. #define _X_NONNULL(args...) __attribute__((nonnull(args)))
  150. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */
  151. #define _X_NONNULL(...) /* */
  152. #endif
  153. /* requires xproto >= 7.0.22 */
  154. #if __has_attribute(__unused__) \
  155. || defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)
  156. #define _X_UNUSED __attribute__((__unused__))
  157. #else
  158. #define _X_UNUSED /* */
  159. #endif
  160. /* C99 keyword "inline" or equivalent extensions in pre-C99 compilers */
  161. /* requires xproto >= 7.0.9
  162. (introduced in 7.0.8 but didn't support all compilers until 7.0.9) */
  163. #if defined(inline) /* assume autoconf set it correctly */ || \
  164. (defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L)) /* C99 */ || \
  165. (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550))
  166. # define _X_INLINE inline
  167. #elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
  168. # define _X_INLINE __inline__
  169. #else
  170. # define _X_INLINE
  171. #endif
  172. /* C99 keyword "restrict" or equivalent extensions in pre-C99 compilers */
  173. /* requires xproto >= 7.0.21 */
  174. #ifndef _X_RESTRICT_KYWD
  175. # if defined(restrict) /* assume autoconf set it correctly */ || \
  176. (defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */ \
  177. && !defined(__cplusplus)) /* Workaround g++ issue on Solaris */
  178. # define _X_RESTRICT_KYWD restrict
  179. # elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
  180. # define _X_RESTRICT_KYWD __restrict__
  181. # else
  182. # define _X_RESTRICT_KYWD
  183. # endif
  184. #endif
  185. /* requires xproto >= 7.0.30 */
  186. #if __has_attribute(no_sanitize_thread)
  187. # define _X_NOTSAN __attribute__((no_sanitize_thread))
  188. #else
  189. # define _X_NOTSAN
  190. #endif
  191. /* Mark a char array/pointer as not containing a NUL-terminated string */
  192. /* requires xproto >= 7.0.33 */
  193. #if __has_attribute(nonstring)
  194. # define _X_NONSTRING __attribute__((nonstring))
  195. #else
  196. # define _X_NONSTRING
  197. #endif
  198. #endif /* _XFUNCPROTO_H_ */