Xfuncproto.h revision 17ca54c3
117ca54c3Smrg/*
217ca54c3Smrg *
317ca54c3SmrgCopyright 1989, 1991, 1998  The Open Group
417ca54c3Smrg
517ca54c3SmrgPermission to use, copy, modify, distribute, and sell this software and its
617ca54c3Smrgdocumentation for any purpose is hereby granted without fee, provided that
717ca54c3Smrgthe above copyright notice appear in all copies and that both that
817ca54c3Smrgcopyright notice and this permission notice appear in supporting
917ca54c3Smrgdocumentation.
1017ca54c3Smrg
1117ca54c3SmrgThe above copyright notice and this permission notice shall be included in
1217ca54c3Smrgall copies or substantial portions of the Software.
1317ca54c3Smrg
1417ca54c3SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1517ca54c3SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1617ca54c3SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
1717ca54c3SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1817ca54c3SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1917ca54c3SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2017ca54c3Smrg
2117ca54c3SmrgExcept as contained in this notice, the name of The Open Group shall not be
2217ca54c3Smrgused in advertising or otherwise to promote the sale, use or other dealings
2317ca54c3Smrgin this Software without prior written authorization from The Open Group.
2417ca54c3Smrg *
2517ca54c3Smrg */
2617ca54c3Smrg
2717ca54c3Smrg/* Definitions to make function prototypes manageable */
2817ca54c3Smrg
2917ca54c3Smrg#ifndef _XFUNCPROTO_H_
3017ca54c3Smrg#define _XFUNCPROTO_H_
3117ca54c3Smrg
3217ca54c3Smrg#ifndef NeedFunctionPrototypes
3317ca54c3Smrg#define NeedFunctionPrototypes 1
3417ca54c3Smrg#endif /* NeedFunctionPrototypes */
3517ca54c3Smrg
3617ca54c3Smrg#ifndef NeedVarargsPrototypes
3717ca54c3Smrg#define NeedVarargsPrototypes 1
3817ca54c3Smrg#endif /* NeedVarargsPrototypes */
3917ca54c3Smrg
4017ca54c3Smrg#if NeedFunctionPrototypes
4117ca54c3Smrg
4217ca54c3Smrg#ifndef NeedNestedPrototypes
4317ca54c3Smrg#define NeedNestedPrototypes 1
4417ca54c3Smrg#endif /* NeedNestedPrototypes */
4517ca54c3Smrg
4617ca54c3Smrg#ifndef _Xconst
4717ca54c3Smrg#define _Xconst const
4817ca54c3Smrg#endif /* _Xconst */
4917ca54c3Smrg
5017ca54c3Smrg/* Function prototype configuration (see configure for more info) */
5117ca54c3Smrg#if !defined(NARROWPROTO) && \
5217ca54c3Smrg    (defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__))
5317ca54c3Smrg#define NARROWPROTO
5417ca54c3Smrg#endif
5517ca54c3Smrg#ifndef FUNCPROTO
5617ca54c3Smrg#define FUNCPROTO 15
5717ca54c3Smrg#endif
5817ca54c3Smrg
5917ca54c3Smrg#ifndef NeedWidePrototypes
6017ca54c3Smrg#ifdef NARROWPROTO
6117ca54c3Smrg#define NeedWidePrototypes 0
6217ca54c3Smrg#else
6317ca54c3Smrg#define NeedWidePrototypes 1		/* default to make interropt. easier */
6417ca54c3Smrg#endif
6517ca54c3Smrg#endif /* NeedWidePrototypes */
6617ca54c3Smrg
6717ca54c3Smrg#endif /* NeedFunctionPrototypes */
6817ca54c3Smrg
6917ca54c3Smrg#ifndef _XFUNCPROTOBEGIN
7017ca54c3Smrg#if defined(__cplusplus) || defined(c_plusplus) /* for C++ V2.0 */
7117ca54c3Smrg#define _XFUNCPROTOBEGIN extern "C" {	/* do not leave open across includes */
7217ca54c3Smrg#define _XFUNCPROTOEND }
7317ca54c3Smrg#else
7417ca54c3Smrg#define _XFUNCPROTOBEGIN
7517ca54c3Smrg#define _XFUNCPROTOEND
7617ca54c3Smrg#endif
7717ca54c3Smrg#endif /* _XFUNCPROTOBEGIN */
7817ca54c3Smrg
7917ca54c3Smrg/* http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute */
8017ca54c3Smrg#ifndef __has_attribute
8117ca54c3Smrg# define __has_attribute(x) 0  /* Compatibility with non-clang compilers. */
8217ca54c3Smrg#endif
8317ca54c3Smrg#ifndef __has_feature
8417ca54c3Smrg# define __has_feature(x) 0    /* Compatibility with non-clang compilers. */
8517ca54c3Smrg#endif
8617ca54c3Smrg#ifndef __has_extension
8717ca54c3Smrg# define __has_extension(x) 0  /* Compatibility with non-clang compilers. */
8817ca54c3Smrg#endif
8917ca54c3Smrg
9017ca54c3Smrg/* Added in X11R6.9, so available in any version of modular xproto */
9117ca54c3Smrg#if __has_attribute(__sentinel__) || (defined(__GNUC__) && (__GNUC__ >= 4))
9217ca54c3Smrg# define _X_SENTINEL(x) __attribute__ ((__sentinel__(x)))
9317ca54c3Smrg#else
9417ca54c3Smrg# define _X_SENTINEL(x)
9517ca54c3Smrg#endif /* GNUC >= 4 */
9617ca54c3Smrg
9717ca54c3Smrg/* Added in X11R6.9, so available in any version of modular xproto */
9817ca54c3Smrg#if (__has_attribute(visibility) || (defined(__GNUC__) && (__GNUC__ >= 4))) \
9917ca54c3Smrg    && !defined(__CYGWIN__) && !defined(__MINGW32__)
10017ca54c3Smrg# define _X_EXPORT      __attribute__((visibility("default")))
10117ca54c3Smrg# define _X_HIDDEN      __attribute__((visibility("hidden")))
10217ca54c3Smrg# define _X_INTERNAL    __attribute__((visibility("internal")))
10317ca54c3Smrg#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
10417ca54c3Smrg# define _X_EXPORT      __global
10517ca54c3Smrg# define _X_HIDDEN      __hidden
10617ca54c3Smrg# define _X_INTERNAL    __hidden
10717ca54c3Smrg#else /* not gcc >= 4 and not Sun Studio >= 8 */
10817ca54c3Smrg# define _X_EXPORT
10917ca54c3Smrg# define _X_HIDDEN
11017ca54c3Smrg# define _X_INTERNAL
11117ca54c3Smrg#endif /* GNUC >= 4 */
11217ca54c3Smrg
11317ca54c3Smrg/* Branch prediction hints for individual conditionals */
11417ca54c3Smrg/* requires xproto >= 7.0.9 */
11517ca54c3Smrg#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303)
11617ca54c3Smrg# define _X_LIKELY(x)   __builtin_expect(!!(x), 1)
11717ca54c3Smrg# define _X_UNLIKELY(x) __builtin_expect(!!(x), 0)
11817ca54c3Smrg#else /* not gcc >= 3.3 */
11917ca54c3Smrg# define _X_LIKELY(x)   (x)
12017ca54c3Smrg# define _X_UNLIKELY(x) (x)
12117ca54c3Smrg#endif
12217ca54c3Smrg
12317ca54c3Smrg/* Bulk branch prediction hints via marking error path functions as "cold" */
12417ca54c3Smrg/* requires xproto >= 7.0.25 */
12517ca54c3Smrg#if __has_attribute(__cold__) || \
12617ca54c3Smrg    (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) /* 4.3+ */
12717ca54c3Smrg# define _X_COLD __attribute__((__cold__))
12817ca54c3Smrg#else
12917ca54c3Smrg# define _X_COLD /* nothing */
13017ca54c3Smrg#endif
13117ca54c3Smrg
13217ca54c3Smrg/* Added in X11R6.9, so available in any version of modular xproto */
13317ca54c3Smrg#if __has_attribute(deprecated) \
13417ca54c3Smrg    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 301)) \
13517ca54c3Smrg    || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5130))
13617ca54c3Smrg# define _X_DEPRECATED  __attribute__((deprecated))
13717ca54c3Smrg#else /* not gcc >= 3.1 */
13817ca54c3Smrg# define _X_DEPRECATED
13917ca54c3Smrg#endif
14017ca54c3Smrg
14117ca54c3Smrg/* requires xproto >= 7.0.30 */
14217ca54c3Smrg#if __has_extension(attribute_deprecated_with_message) || \
14317ca54c3Smrg                (defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))))
14417ca54c3Smrg# define _X_DEPRECATED_MSG(_msg) __attribute__((deprecated(_msg)))
14517ca54c3Smrg#else
14617ca54c3Smrg# define _X_DEPRECATED_MSG(_msg) _X_DEPRECATED
14717ca54c3Smrg#endif
14817ca54c3Smrg
14917ca54c3Smrg/* requires xproto >= 7.0.17 */
15017ca54c3Smrg#if __has_attribute(noreturn) \
15117ca54c3Smrg    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
15217ca54c3Smrg    || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
15317ca54c3Smrg# define _X_NORETURN __attribute((noreturn))
15417ca54c3Smrg#else
15517ca54c3Smrg# define _X_NORETURN
15617ca54c3Smrg#endif /* GNUC  */
15717ca54c3Smrg
15817ca54c3Smrg/* Added in X11R6.9, so available in any version of modular xproto */
15917ca54c3Smrg#if __has_attribute(__format__) \
16017ca54c3Smrg    || defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)
16117ca54c3Smrg# define _X_ATTRIBUTE_PRINTF(x,y) __attribute__((__format__(__printf__,x,y)))
16217ca54c3Smrg#else /* not gcc >= 2.3 */
16317ca54c3Smrg# define _X_ATTRIBUTE_PRINTF(x,y)
16417ca54c3Smrg#endif
16517ca54c3Smrg
16617ca54c3Smrg/* requires xproto >= 7.0.22 - since this uses either gcc or C99 variable
16717ca54c3Smrg   argument macros, must be only used inside #ifdef _X_NONNULL guards, as
16817ca54c3Smrg   many legacy X clients are compiled in C89 mode still. */
16917ca54c3Smrg#if __has_attribute(nonnull) \
17017ca54c3Smrg    && defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */
17117ca54c3Smrg#define _X_NONNULL(...)  __attribute__((nonnull(__VA_ARGS__)))
17217ca54c3Smrg#elif __has_attribute(nonnull) \
17317ca54c3Smrg    || defined(__GNUC__) &&  ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303)
17417ca54c3Smrg#define _X_NONNULL(args...)  __attribute__((nonnull(args)))
17517ca54c3Smrg#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */
17617ca54c3Smrg#define _X_NONNULL(...)  /* */
17717ca54c3Smrg#endif
17817ca54c3Smrg
17917ca54c3Smrg/* requires xproto >= 7.0.22 */
18017ca54c3Smrg#if __has_attribute(__unused__) \
18117ca54c3Smrg    || defined(__GNUC__) &&  ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)
18217ca54c3Smrg#define _X_UNUSED  __attribute__((__unused__))
18317ca54c3Smrg#else
18417ca54c3Smrg#define _X_UNUSED  /* */
18517ca54c3Smrg#endif
18617ca54c3Smrg
18717ca54c3Smrg/* C99 keyword "inline" or equivalent extensions in pre-C99 compilers */
18817ca54c3Smrg/* requires xproto >= 7.0.9
18917ca54c3Smrg   (introduced in 7.0.8 but didn't support all compilers until 7.0.9) */
19017ca54c3Smrg#if defined(inline) /* assume autoconf set it correctly */ || \
19117ca54c3Smrg   (defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L)) /* C99 */ || \
19217ca54c3Smrg   (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550))
19317ca54c3Smrg# define _X_INLINE inline
19417ca54c3Smrg#elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
19517ca54c3Smrg# define _X_INLINE __inline__
19617ca54c3Smrg#else
19717ca54c3Smrg# define _X_INLINE
19817ca54c3Smrg#endif
19917ca54c3Smrg
20017ca54c3Smrg/* C99 keyword "restrict" or equivalent extensions in pre-C99 compilers */
20117ca54c3Smrg/* requires xproto >= 7.0.21 */
20217ca54c3Smrg#ifndef _X_RESTRICT_KYWD
20317ca54c3Smrg# if defined(restrict) /* assume autoconf set it correctly */ || \
20417ca54c3Smrg    (defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */ \
20517ca54c3Smrg     && !defined(__cplusplus)) /* Workaround g++ issue on Solaris */
20617ca54c3Smrg#  define _X_RESTRICT_KYWD  restrict
20717ca54c3Smrg# elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
20817ca54c3Smrg#  define _X_RESTRICT_KYWD __restrict__
20917ca54c3Smrg# else
21017ca54c3Smrg#  define _X_RESTRICT_KYWD
21117ca54c3Smrg# endif
21217ca54c3Smrg#endif
21317ca54c3Smrg
21417ca54c3Smrg/* requires xproto >= 7.0.30 */
21517ca54c3Smrg#if __has_attribute(no_sanitize_thread)
21617ca54c3Smrg# define _X_NOTSAN __attribute__((no_sanitize_thread))
21717ca54c3Smrg#else
21817ca54c3Smrg# define _X_NOTSAN
21917ca54c3Smrg#endif
22017ca54c3Smrg
22117ca54c3Smrg#endif /* _XFUNCPROTO_H_ */
222