xref: /dflybsd-src/contrib/libpcap/pcap/compiler-tests.h (revision e75ef36f1332e115895388cede9dfd24ca1a806c)
13a289941SAaron LI /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
23a289941SAaron LI /*
33a289941SAaron LI  * Copyright (c) 1993, 1994, 1995, 1996, 1997
43a289941SAaron LI  *	The Regents of the University of California.  All rights reserved.
53a289941SAaron LI  *
63a289941SAaron LI  * Redistribution and use in source and binary forms, with or without
73a289941SAaron LI  * modification, are permitted provided that the following conditions
83a289941SAaron LI  * are met:
93a289941SAaron LI  * 1. Redistributions of source code must retain the above copyright
103a289941SAaron LI  *    notice, this list of conditions and the following disclaimer.
113a289941SAaron LI  * 2. Redistributions in binary form must reproduce the above copyright
123a289941SAaron LI  *    notice, this list of conditions and the following disclaimer in the
133a289941SAaron LI  *    documentation and/or other materials provided with the distribution.
143a289941SAaron LI  * 3. All advertising materials mentioning features or use of this software
153a289941SAaron LI  *    must display the following acknowledgement:
163a289941SAaron LI  *	This product includes software developed by the Computer Systems
173a289941SAaron LI  *	Engineering Group at Lawrence Berkeley Laboratory.
183a289941SAaron LI  * 4. Neither the name of the University nor of the Laboratory may be used
193a289941SAaron LI  *    to endorse or promote products derived from this software without
203a289941SAaron LI  *    specific prior written permission.
213a289941SAaron LI  *
223a289941SAaron LI  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
233a289941SAaron LI  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
243a289941SAaron LI  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
253a289941SAaron LI  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
263a289941SAaron LI  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
273a289941SAaron LI  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
283a289941SAaron LI  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
293a289941SAaron LI  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
303a289941SAaron LI  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
313a289941SAaron LI  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
323a289941SAaron LI  * SUCH DAMAGE.
333a289941SAaron LI  */
343a289941SAaron LI 
353a289941SAaron LI #ifndef lib_pcap_compiler_tests_h
363a289941SAaron LI #define lib_pcap_compiler_tests_h
373a289941SAaron LI 
383a289941SAaron LI /*
393a289941SAaron LI  * This was introduced by Clang:
403a289941SAaron LI  *
41*ea16f64eSAntonio Huete Jimenez  *     https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
423a289941SAaron LI  *
433a289941SAaron LI  * in some version (which version?); it has been picked up by GCC 5.0.
443a289941SAaron LI  */
453a289941SAaron LI #ifndef __has_attribute
463a289941SAaron LI   /*
473a289941SAaron LI    * It's a macro, so you can check whether it's defined to check
483a289941SAaron LI    * whether it's supported.
493a289941SAaron LI    *
503a289941SAaron LI    * If it's not, define it to always return 0, so that we move on to
513a289941SAaron LI    * the fallback checks.
523a289941SAaron LI    */
533a289941SAaron LI   #define __has_attribute(x) 0
543a289941SAaron LI #endif
553a289941SAaron LI 
563a289941SAaron LI /*
573a289941SAaron LI  * Note that the C90 spec's "6.8.1 Conditional inclusion" and the
583a289941SAaron LI  * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say:
593a289941SAaron LI  *
603a289941SAaron LI  *    Prior to evaluation, macro invocations in the list of preprocessing
613a289941SAaron LI  *    tokens that will become the controlling constant expression are
623a289941SAaron LI  *    replaced (except for those macro names modified by the defined unary
633a289941SAaron LI  *    operator), just as in normal text.  If the token "defined" is
643a289941SAaron LI  *    generated as a result of this replacement process or use of the
653a289941SAaron LI  *    "defined" unary operator does not match one of the two specified
663a289941SAaron LI  *    forms prior to macro replacement, the behavior is undefined.
673a289941SAaron LI  *
683a289941SAaron LI  * so you shouldn't use defined() in a #define that's used in #if or
693a289941SAaron LI  * #elif.  Some versions of Clang, for example, will warn about this.
703a289941SAaron LI  *
713a289941SAaron LI  * Instead, we check whether the pre-defined macros for particular
723a289941SAaron LI  * compilers are defined and, if not, define the "is this version XXX
733a289941SAaron LI  * or a later version of this compiler" macros as 0.
743a289941SAaron LI  */
753a289941SAaron LI 
763a289941SAaron LI /*
773a289941SAaron LI  * Check whether this is GCC major.minor or a later release, or some
783a289941SAaron LI  * compiler that claims to be "just like GCC" of that version or a
793a289941SAaron LI  * later release.
803a289941SAaron LI  */
813a289941SAaron LI 
823a289941SAaron LI #if ! defined(__GNUC__)
833a289941SAaron LI #define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) 0
843a289941SAaron LI #else
853a289941SAaron LI #define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \
863a289941SAaron LI 	(__GNUC__ > (major) || \
873a289941SAaron LI 	 (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
883a289941SAaron LI #endif
893a289941SAaron LI 
903a289941SAaron LI /*
913a289941SAaron LI  * Check whether this is Clang major.minor or a later release.
923a289941SAaron LI  */
933a289941SAaron LI 
943a289941SAaron LI #if !defined(__clang__)
953a289941SAaron LI #define PCAP_IS_AT_LEAST_CLANG_VERSION(major, minor) 0
963a289941SAaron LI #else
973a289941SAaron LI #define PCAP_IS_AT_LEAST_CLANG_VERSION(major, minor) \
983a289941SAaron LI 	(__clang_major__ > (major) || \
993a289941SAaron LI 	 (__clang_major__ == (major) && __clang_minor__ >= (minor)))
1003a289941SAaron LI #endif
1013a289941SAaron LI 
1023a289941SAaron LI /*
1033a289941SAaron LI  * Check whether this is Sun C/SunPro C/Oracle Studio major.minor
1043a289941SAaron LI  * or a later release.
1053a289941SAaron LI  *
1063a289941SAaron LI  * The version number in __SUNPRO_C is encoded in hex BCD, with the
1073a289941SAaron LI  * uppermost hex digit being the major version number, the next
1083a289941SAaron LI  * one or two hex digits being the minor version number, and
1093a289941SAaron LI  * the last digit being the patch version.
1103a289941SAaron LI  *
1113a289941SAaron LI  * It represents the *compiler* version, not the product version;
1123a289941SAaron LI  * see
1133a289941SAaron LI  *
1143a289941SAaron LI  *    https://sourceforge.net/p/predef/wiki/Compilers/
1153a289941SAaron LI  *
1163a289941SAaron LI  * for a partial mapping, which we assume continues for later
1173a289941SAaron LI  * 12.x product releases.
1183a289941SAaron LI  */
1193a289941SAaron LI 
1203a289941SAaron LI #if ! defined(__SUNPRO_C)
1213a289941SAaron LI #define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) 0
1223a289941SAaron LI #else
1233a289941SAaron LI #define PCAP_SUNPRO_VERSION_TO_BCD(major, minor) \
1243a289941SAaron LI 	(((minor) >= 10) ? \
1253a289941SAaron LI 	    (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \
1263a289941SAaron LI 	    (((major) << 8) | ((minor) << 4)))
1273a289941SAaron LI #define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) \
1283a289941SAaron LI 	(__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor)))
1293a289941SAaron LI #endif
1303a289941SAaron LI 
1313a289941SAaron LI /*
1323a289941SAaron LI  * Check whether this is IBM XL C major.minor or a later release.
1333a289941SAaron LI  *
1343a289941SAaron LI  * The version number in __xlC__ has the major version in the
1353a289941SAaron LI  * upper 8 bits and the minor version in the lower 8 bits.
1363a289941SAaron LI  */
1373a289941SAaron LI 
1383a289941SAaron LI #if ! defined(__xlC__)
1393a289941SAaron LI #define PCAP_IS_AT_LEAST_XL_C_VERSION(major,minor) 0
1403a289941SAaron LI #else
1413a289941SAaron LI #define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \
1423a289941SAaron LI 	(__xlC__ >= (((major) << 8) | (minor)))
1433a289941SAaron LI #endif
1443a289941SAaron LI 
1453a289941SAaron LI /*
1463a289941SAaron LI  * Check whether this is HP aC++/HP C major.minor or a later release.
1473a289941SAaron LI  *
1483a289941SAaron LI  * The version number in __HP_aCC is encoded in zero-padded decimal BCD,
1493a289941SAaron LI  * with the "A." stripped off, the uppermost two decimal digits being
1503a289941SAaron LI  * the major version number, the next two decimal digits being the minor
1513a289941SAaron LI  * version number, and the last two decimal digits being the patch version.
1523a289941SAaron LI  * (Strip off the A., remove the . between the major and minor version
1533a289941SAaron LI  * number, and add two digits of patch.)
1543a289941SAaron LI  */
1553a289941SAaron LI 
1563a289941SAaron LI #if ! defined(__HP_aCC)
1573a289941SAaron LI #define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) 0
1583a289941SAaron LI #else
1593a289941SAaron LI #define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) \
1603a289941SAaron LI 	(__HP_aCC >= ((major)*10000 + (minor)*100))
1613a289941SAaron LI #endif
1623a289941SAaron LI 
1633a289941SAaron LI #endif /* lib_pcap_compiler_tests_h */
164