Blame pcap/compiler-tests.h

Packit 209cc3
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
Packit 209cc3
/*
Packit 209cc3
 * Copyright (c) 1993, 1994, 1995, 1996, 1997
Packit 209cc3
 *	The Regents of the University of California.  All rights reserved.
Packit 209cc3
 *
Packit 209cc3
 * Redistribution and use in source and binary forms, with or without
Packit 209cc3
 * modification, are permitted provided that the following conditions
Packit 209cc3
 * are met:
Packit 209cc3
 * 1. Redistributions of source code must retain the above copyright
Packit 209cc3
 *    notice, this list of conditions and the following disclaimer.
Packit 209cc3
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 209cc3
 *    notice, this list of conditions and the following disclaimer in the
Packit 209cc3
 *    documentation and/or other materials provided with the distribution.
Packit 209cc3
 * 3. All advertising materials mentioning features or use of this software
Packit 209cc3
 *    must display the following acknowledgement:
Packit 209cc3
 *	This product includes software developed by the Computer Systems
Packit 209cc3
 *	Engineering Group at Lawrence Berkeley Laboratory.
Packit 209cc3
 * 4. Neither the name of the University nor of the Laboratory may be used
Packit 209cc3
 *    to endorse or promote products derived from this software without
Packit 209cc3
 *    specific prior written permission.
Packit 209cc3
 *
Packit 209cc3
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 209cc3
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 209cc3
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 209cc3
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit 209cc3
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 209cc3
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 209cc3
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 209cc3
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 209cc3
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 209cc3
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 209cc3
 * SUCH DAMAGE.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
#ifndef lib_pcap_compiler_tests_h
Packit 209cc3
#define lib_pcap_compiler_tests_h
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * This was introduced by Clang:
Packit 209cc3
 *
Packit 209cc3
 *     http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
Packit 209cc3
 *
Packit 209cc3
 * in some version (which version?); it has been picked up by GCC 5.0.
Packit 209cc3
 */
Packit 209cc3
#ifndef __has_attribute
Packit 209cc3
  /*
Packit 209cc3
   * It's a macro, so you can check whether it's defined to check
Packit 209cc3
   * whether it's supported.
Packit 209cc3
   *
Packit 209cc3
   * If it's not, define it to always return 0, so that we move on to
Packit 209cc3
   * the fallback checks.
Packit 209cc3
   */
Packit 209cc3
  #define __has_attribute(x) 0
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Note that the C90 spec's "6.8.1 Conditional inclusion" and the
Packit 209cc3
 * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say:
Packit 209cc3
 *
Packit 209cc3
 *    Prior to evaluation, macro invocations in the list of preprocessing
Packit 209cc3
 *    tokens that will become the controlling constant expression are
Packit 209cc3
 *    replaced (except for those macro names modified by the defined unary
Packit 209cc3
 *    operator), just as in normal text.  If the token "defined" is
Packit 209cc3
 *    generated as a result of this replacement process or use of the
Packit 209cc3
 *    "defined" unary operator does not match one of the two specified
Packit 209cc3
 *    forms prior to macro replacement, the behavior is undefined.
Packit 209cc3
 *
Packit 209cc3
 * so you shouldn't use defined() in a #define that's used in #if or
Packit 209cc3
 * #elif.  Some versions of Clang, for example, will warn about this.
Packit 209cc3
 *
Packit 209cc3
 * Instead, we check whether the pre-defined macros for particular
Packit 209cc3
 * compilers are defined and, if not, define the "is this version XXX
Packit 209cc3
 * or a later version of this compiler" macros as 0.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Check whether this is GCC major.minor or a later release, or some
Packit 209cc3
 * compiler that claims to be "just like GCC" of that version or a
Packit 209cc3
 * later release.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
#if ! defined(__GNUC__)
Packit 209cc3
#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) 0
Packit 209cc3
#else
Packit 209cc3
#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \
Packit 209cc3
	(__GNUC__ > (major) || \
Packit 209cc3
	 (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Check whether this is Clang major.minor or a later release.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
#if !defined(__clang__)
Packit 209cc3
#define PCAP_IS_AT_LEAST_CLANG_VERSION(major, minor) 0
Packit 209cc3
#else
Packit 209cc3
#define PCAP_IS_AT_LEAST_CLANG_VERSION(major, minor) \
Packit 209cc3
	(__clang_major__ > (major) || \
Packit 209cc3
	 (__clang_major__ == (major) && __clang_minor__ >= (minor)))
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Check whether this is Sun C/SunPro C/Oracle Studio major.minor
Packit 209cc3
 * or a later release.
Packit 209cc3
 *
Packit 209cc3
 * The version number in __SUNPRO_C is encoded in hex BCD, with the
Packit 209cc3
 * uppermost hex digit being the major version number, the next
Packit 209cc3
 * one or two hex digits being the minor version number, and
Packit 209cc3
 * the last digit being the patch version.
Packit 209cc3
 *
Packit 209cc3
 * It represents the *compiler* version, not the product version;
Packit 209cc3
 * see
Packit 209cc3
 *
Packit 209cc3
 *    https://sourceforge.net/p/predef/wiki/Compilers/
Packit 209cc3
 *
Packit 209cc3
 * for a partial mapping, which we assume continues for later
Packit 209cc3
 * 12.x product releases.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
#if ! defined(__SUNPRO_C)
Packit 209cc3
#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) 0
Packit 209cc3
#else
Packit 209cc3
#define PCAP_SUNPRO_VERSION_TO_BCD(major, minor) \
Packit 209cc3
	(((minor) >= 10) ? \
Packit 209cc3
	    (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \
Packit 209cc3
	    (((major) << 8) | ((minor) << 4)))
Packit 209cc3
#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) \
Packit 209cc3
	(__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor)))
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Check whether this is IBM XL C major.minor or a later release.
Packit 209cc3
 *
Packit 209cc3
 * The version number in __xlC__ has the major version in the
Packit 209cc3
 * upper 8 bits and the minor version in the lower 8 bits.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
#if ! defined(__xlC__)
Packit 209cc3
#define PCAP_IS_AT_LEAST_XL_C_VERSION(major,minor) 0
Packit 209cc3
#else
Packit 209cc3
#define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \
Packit 209cc3
	(__xlC__ >= (((major) << 8) | (minor)))
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Check whether this is HP aC++/HP C major.minor or a later release.
Packit 209cc3
 *
Packit 209cc3
 * The version number in __HP_aCC is encoded in zero-padded decimal BCD,
Packit 209cc3
 * with the "A." stripped off, the uppermost two decimal digits being
Packit 209cc3
 * the major version number, the next two decimal digits being the minor
Packit 209cc3
 * version number, and the last two decimal digits being the patch version.
Packit 209cc3
 * (Strip off the A., remove the . between the major and minor version
Packit 209cc3
 * number, and add two digits of patch.)
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
#if ! defined(__HP_aCC)
Packit 209cc3
#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) 0
Packit 209cc3
#else
Packit 209cc3
#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) \
Packit 209cc3
	(__HP_aCC >= ((major)*10000 + (minor)*100))
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
#endif /* lib_pcap_compiler_tests_h */