1b00ab754SHans Petter Selasky /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ 2b00ab754SHans Petter Selasky /* 3b00ab754SHans Petter Selasky * Copyright (c) 1993, 1994, 1995, 1996, 1997 4b00ab754SHans Petter Selasky * The Regents of the University of California. All rights reserved. 5b00ab754SHans Petter Selasky * 6b00ab754SHans Petter Selasky * Redistribution and use in source and binary forms, with or without 7b00ab754SHans Petter Selasky * modification, are permitted provided that the following conditions 8b00ab754SHans Petter Selasky * are met: 9b00ab754SHans Petter Selasky * 1. Redistributions of source code must retain the above copyright 10b00ab754SHans Petter Selasky * notice, this list of conditions and the following disclaimer. 11b00ab754SHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright 12b00ab754SHans Petter Selasky * notice, this list of conditions and the following disclaimer in the 13b00ab754SHans Petter Selasky * documentation and/or other materials provided with the distribution. 14b00ab754SHans Petter Selasky * 3. All advertising materials mentioning features or use of this software 15b00ab754SHans Petter Selasky * must display the following acknowledgement: 16b00ab754SHans Petter Selasky * This product includes software developed by the Computer Systems 17b00ab754SHans Petter Selasky * Engineering Group at Lawrence Berkeley Laboratory. 18b00ab754SHans Petter Selasky * 4. Neither the name of the University nor of the Laboratory may be used 19b00ab754SHans Petter Selasky * to endorse or promote products derived from this software without 20b00ab754SHans Petter Selasky * specific prior written permission. 21b00ab754SHans Petter Selasky * 22b00ab754SHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23b00ab754SHans Petter Selasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24b00ab754SHans Petter Selasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25b00ab754SHans Petter Selasky * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26b00ab754SHans Petter Selasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27b00ab754SHans Petter Selasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28b00ab754SHans Petter Selasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29b00ab754SHans Petter Selasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30b00ab754SHans Petter Selasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31b00ab754SHans Petter Selasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32b00ab754SHans Petter Selasky * SUCH DAMAGE. 33b00ab754SHans Petter Selasky */ 34b00ab754SHans Petter Selasky 35b00ab754SHans Petter Selasky #ifndef lib_pcap_compiler_tests_h 36b00ab754SHans Petter Selasky #define lib_pcap_compiler_tests_h 37b00ab754SHans Petter Selasky 38b00ab754SHans Petter Selasky /* 39b00ab754SHans Petter Selasky * This was introduced by Clang: 40b00ab754SHans Petter Selasky * 41*6f9cba8fSJoseph Mingrone * https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute 42b00ab754SHans Petter Selasky * 43b00ab754SHans Petter Selasky * in some version (which version?); it has been picked up by GCC 5.0. 44b00ab754SHans Petter Selasky */ 45b00ab754SHans Petter Selasky #ifndef __has_attribute 46b00ab754SHans Petter Selasky /* 47b00ab754SHans Petter Selasky * It's a macro, so you can check whether it's defined to check 48b00ab754SHans Petter Selasky * whether it's supported. 49b00ab754SHans Petter Selasky * 50b00ab754SHans Petter Selasky * If it's not, define it to always return 0, so that we move on to 51b00ab754SHans Petter Selasky * the fallback checks. 52b00ab754SHans Petter Selasky */ 53b00ab754SHans Petter Selasky #define __has_attribute(x) 0 54b00ab754SHans Petter Selasky #endif 55b00ab754SHans Petter Selasky 56b00ab754SHans Petter Selasky /* 57b00ab754SHans Petter Selasky * Note that the C90 spec's "6.8.1 Conditional inclusion" and the 58b00ab754SHans Petter Selasky * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say: 59b00ab754SHans Petter Selasky * 60b00ab754SHans Petter Selasky * Prior to evaluation, macro invocations in the list of preprocessing 61b00ab754SHans Petter Selasky * tokens that will become the controlling constant expression are 62b00ab754SHans Petter Selasky * replaced (except for those macro names modified by the defined unary 63b00ab754SHans Petter Selasky * operator), just as in normal text. If the token "defined" is 64b00ab754SHans Petter Selasky * generated as a result of this replacement process or use of the 65b00ab754SHans Petter Selasky * "defined" unary operator does not match one of the two specified 66b00ab754SHans Petter Selasky * forms prior to macro replacement, the behavior is undefined. 67b00ab754SHans Petter Selasky * 68b00ab754SHans Petter Selasky * so you shouldn't use defined() in a #define that's used in #if or 69b00ab754SHans Petter Selasky * #elif. Some versions of Clang, for example, will warn about this. 70b00ab754SHans Petter Selasky * 71b00ab754SHans Petter Selasky * Instead, we check whether the pre-defined macros for particular 72b00ab754SHans Petter Selasky * compilers are defined and, if not, define the "is this version XXX 73b00ab754SHans Petter Selasky * or a later version of this compiler" macros as 0. 74b00ab754SHans Petter Selasky */ 75b00ab754SHans Petter Selasky 76b00ab754SHans Petter Selasky /* 77b00ab754SHans Petter Selasky * Check whether this is GCC major.minor or a later release, or some 78b00ab754SHans Petter Selasky * compiler that claims to be "just like GCC" of that version or a 79b00ab754SHans Petter Selasky * later release. 80b00ab754SHans Petter Selasky */ 81b00ab754SHans Petter Selasky 82b00ab754SHans Petter Selasky #if ! defined(__GNUC__) 83*6f9cba8fSJoseph Mingrone /* Not GCC and not "just like GCC" */ 84b00ab754SHans Petter Selasky #define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) 0 85b00ab754SHans Petter Selasky #else 86*6f9cba8fSJoseph Mingrone /* GCC or "just like GCC" */ 87b00ab754SHans Petter Selasky #define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \ 88b00ab754SHans Petter Selasky (__GNUC__ > (major) || \ 89b00ab754SHans Petter Selasky (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 90b00ab754SHans Petter Selasky #endif 91b00ab754SHans Petter Selasky 92b00ab754SHans Petter Selasky /* 93b00ab754SHans Petter Selasky * Check whether this is Clang major.minor or a later release. 94b00ab754SHans Petter Selasky */ 95b00ab754SHans Petter Selasky 96b00ab754SHans Petter Selasky #if !defined(__clang__) 97*6f9cba8fSJoseph Mingrone /* Not Clang */ 98b00ab754SHans Petter Selasky #define PCAP_IS_AT_LEAST_CLANG_VERSION(major, minor) 0 99b00ab754SHans Petter Selasky #else 100*6f9cba8fSJoseph Mingrone /* Clang */ 101b00ab754SHans Petter Selasky #define PCAP_IS_AT_LEAST_CLANG_VERSION(major, minor) \ 102b00ab754SHans Petter Selasky (__clang_major__ > (major) || \ 103b00ab754SHans Petter Selasky (__clang_major__ == (major) && __clang_minor__ >= (minor))) 104b00ab754SHans Petter Selasky #endif 105b00ab754SHans Petter Selasky 106b00ab754SHans Petter Selasky /* 107b00ab754SHans Petter Selasky * Check whether this is Sun C/SunPro C/Oracle Studio major.minor 108b00ab754SHans Petter Selasky * or a later release. 109b00ab754SHans Petter Selasky * 110b00ab754SHans Petter Selasky * The version number in __SUNPRO_C is encoded in hex BCD, with the 111b00ab754SHans Petter Selasky * uppermost hex digit being the major version number, the next 112b00ab754SHans Petter Selasky * one or two hex digits being the minor version number, and 113b00ab754SHans Petter Selasky * the last digit being the patch version. 114b00ab754SHans Petter Selasky * 115b00ab754SHans Petter Selasky * It represents the *compiler* version, not the product version; 116b00ab754SHans Petter Selasky * see 117b00ab754SHans Petter Selasky * 118b00ab754SHans Petter Selasky * https://sourceforge.net/p/predef/wiki/Compilers/ 119b00ab754SHans Petter Selasky * 120b00ab754SHans Petter Selasky * for a partial mapping, which we assume continues for later 121b00ab754SHans Petter Selasky * 12.x product releases. 122b00ab754SHans Petter Selasky */ 123b00ab754SHans Petter Selasky 124b00ab754SHans Petter Selasky #if ! defined(__SUNPRO_C) 125*6f9cba8fSJoseph Mingrone /* Not Sun/Oracle C */ 126b00ab754SHans Petter Selasky #define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) 0 127b00ab754SHans Petter Selasky #else 128*6f9cba8fSJoseph Mingrone /* Sun/Oracle C */ 129b00ab754SHans Petter Selasky #define PCAP_SUNPRO_VERSION_TO_BCD(major, minor) \ 130b00ab754SHans Petter Selasky (((minor) >= 10) ? \ 131b00ab754SHans Petter Selasky (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \ 132b00ab754SHans Petter Selasky (((major) << 8) | ((minor) << 4))) 133b00ab754SHans Petter Selasky #define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) \ 134b00ab754SHans Petter Selasky (__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor))) 135b00ab754SHans Petter Selasky #endif 136b00ab754SHans Petter Selasky 137b00ab754SHans Petter Selasky /* 138b00ab754SHans Petter Selasky * Check whether this is IBM XL C major.minor or a later release. 139b00ab754SHans Petter Selasky * 140b00ab754SHans Petter Selasky * The version number in __xlC__ has the major version in the 141b00ab754SHans Petter Selasky * upper 8 bits and the minor version in the lower 8 bits. 142*6f9cba8fSJoseph Mingrone * On AIX __xlC__ is always defined, __ibmxl__ becomes defined in XL C 16.1. 143*6f9cba8fSJoseph Mingrone * On Linux since XL C 13.1.6 __xlC__ is not defined by default anymore, but 144*6f9cba8fSJoseph Mingrone * __ibmxl__ is defined since at least XL C 13.1.1. 145b00ab754SHans Petter Selasky */ 146b00ab754SHans Petter Selasky 147*6f9cba8fSJoseph Mingrone #if ! defined(__xlC__) && ! defined(__ibmxl__) 148*6f9cba8fSJoseph Mingrone /* Not XL C */ 149b00ab754SHans Petter Selasky #define PCAP_IS_AT_LEAST_XL_C_VERSION(major,minor) 0 150b00ab754SHans Petter Selasky #else 151*6f9cba8fSJoseph Mingrone /* XL C */ 152*6f9cba8fSJoseph Mingrone #if defined(__ibmxl__) 153*6f9cba8fSJoseph Mingrone /* 154*6f9cba8fSJoseph Mingrone * Later Linux version of XL C; use __ibmxl_version__ to test 155*6f9cba8fSJoseph Mingrone * the version. 156*6f9cba8fSJoseph Mingrone */ 157*6f9cba8fSJoseph Mingrone #define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \ 158*6f9cba8fSJoseph Mingrone (__ibmxl_version__ > (major) || \ 159*6f9cba8fSJoseph Mingrone (__ibmxl_version__ == (major) && __ibmxl_release__ >= (minor))) 160*6f9cba8fSJoseph Mingrone #else /* __ibmxl__ */ 161*6f9cba8fSJoseph Mingrone /* 162*6f9cba8fSJoseph Mingrone * __ibmxl__ not defined; use __xlC__ to test the version. 163*6f9cba8fSJoseph Mingrone */ 164b00ab754SHans Petter Selasky #define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \ 165b00ab754SHans Petter Selasky (__xlC__ >= (((major) << 8) | (minor))) 166*6f9cba8fSJoseph Mingrone #endif /* __ibmxl__ */ 167b00ab754SHans Petter Selasky #endif 168b00ab754SHans Petter Selasky 169b00ab754SHans Petter Selasky /* 170b00ab754SHans Petter Selasky * Check whether this is HP aC++/HP C major.minor or a later release. 171b00ab754SHans Petter Selasky * 172b00ab754SHans Petter Selasky * The version number in __HP_aCC is encoded in zero-padded decimal BCD, 173b00ab754SHans Petter Selasky * with the "A." stripped off, the uppermost two decimal digits being 174b00ab754SHans Petter Selasky * the major version number, the next two decimal digits being the minor 175b00ab754SHans Petter Selasky * version number, and the last two decimal digits being the patch version. 176b00ab754SHans Petter Selasky * (Strip off the A., remove the . between the major and minor version 177b00ab754SHans Petter Selasky * number, and add two digits of patch.) 178b00ab754SHans Petter Selasky */ 179b00ab754SHans Petter Selasky 180b00ab754SHans Petter Selasky #if ! defined(__HP_aCC) 181*6f9cba8fSJoseph Mingrone /* Not HP C */ 182b00ab754SHans Petter Selasky #define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) 0 183b00ab754SHans Petter Selasky #else 184*6f9cba8fSJoseph Mingrone /* HP C */ 185b00ab754SHans Petter Selasky #define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) \ 186b00ab754SHans Petter Selasky (__HP_aCC >= ((major)*10000 + (minor)*100)) 187b00ab754SHans Petter Selasky #endif 188b00ab754SHans Petter Selasky 18957e22627SCy Schubert #endif /* lib_pcap_compiler_tests_h */ 190