Blame pcap/funcattrs.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_funcattrs_h
Packit 209cc3
#define lib_pcap_funcattrs_h
Packit 209cc3
Packit 209cc3
#include <pcap/compiler-tests.h>
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Attributes to apply to functions and their arguments, using various
Packit 209cc3
 * compiler-specific extensions.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * PCAP_API_DEF must be used when defining *data* exported from
Packit 209cc3
 * libpcap.  It can be used when defining *functions* exported
Packit 209cc3
 * from libpcap, but it doesn't have to be used there.  It
Packit 209cc3
 * should not be used in declarations in headers.
Packit 209cc3
 *
Packit 209cc3
 * PCAP_API must be used when *declaring* data or functions
Packit 209cc3
 * exported from libpcap; PCAP_API_DEF won't work on all platforms.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
#if defined(_WIN32)
Packit 209cc3
  /*
Packit 209cc3
   * For Windows:
Packit 209cc3
   *
Packit 209cc3
   *    when building libpcap:
Packit 209cc3
   *
Packit 209cc3
   *       if we're building it as a DLL, we have to declare API
Packit 209cc3
   *       functions with __declspec(dllexport);
Packit 209cc3
   *
Packit 209cc3
   *       if we're building it as a static library, we don't want
Packit 209cc3
   *       to do so.
Packit 209cc3
   *
Packit 209cc3
   *    when using libpcap:
Packit 209cc3
   *
Packit 209cc3
   *       if we're using the DLL, calls to its functions are a
Packit 209cc3
   *       little more efficient if they're declared with
Packit 209cc3
   *       __declspec(dllimport);
Packit 209cc3
   *
Packit 209cc3
   *       if we're not using the dll, we don't want to declare
Packit 209cc3
   *       them that way.
Packit 209cc3
   *
Packit 209cc3
   * So:
Packit 209cc3
   *
Packit 209cc3
   *    if pcap_EXPORTS is defined, we define PCAP_API_DEF as
Packit 209cc3
   *     __declspec(dllexport);
Packit 209cc3
   *
Packit 209cc3
   *    if PCAP_DLL is defined, we define PCAP_API_DEF as
Packit 209cc3
   *    __declspec(dllimport);
Packit 209cc3
   *
Packit 209cc3
   *    otherwise, we define PCAP_API_DEF as nothing.
Packit 209cc3
   */
Packit 209cc3
  #if defined(pcap_EXPORTS)
Packit 209cc3
    /*
Packit 209cc3
     * We're compiling libpcap as a DLL, so we should export functions
Packit 209cc3
     * in our API.
Packit 209cc3
     */
Packit 209cc3
    #define PCAP_API_DEF	__declspec(dllexport)
Packit 209cc3
  #elif defined(PCAP_DLL)
Packit 209cc3
    /*
Packit 209cc3
     * We're using libpcap as a DLL, so the calls will be a little more
Packit 209cc3
     * efficient if we explicitly import the functions.
Packit 209cc3
     */
Packit 209cc3
    #define PCAP_API_DEF	__declspec(dllimport)
Packit 209cc3
  #else
Packit 209cc3
    /*
Packit 209cc3
     * Either we're building libpcap as a static library, or we're using
Packit 209cc3
     * it as a static library, or we don't know for certain that we're
Packit 209cc3
     * using it as a dynamic library, so neither import nor export the
Packit 209cc3
     * functions explicitly.
Packit 209cc3
     */
Packit 209cc3
    #define PCAP_API_DEF
Packit 209cc3
  #endif
Packit 209cc3
#elif defined(MSDOS)
Packit 209cc3
  /* XXX - does this need special treatment? */
Packit 209cc3
  #define PCAP_API_DEF
Packit 209cc3
#else /* UN*X */
Packit 209cc3
  #ifdef pcap_EXPORTS
Packit 209cc3
    /*
Packit 209cc3
     * We're compiling libpcap as a (dynamic) shared library, so we should
Packit 209cc3
     * export functions in our API.  The compiler might be configured not
Packit 209cc3
     * to export functions from a shared library by default, so we might
Packit 209cc3
     * have to explicitly mark functions as exported.
Packit 209cc3
     */
Packit 209cc3
    #if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) \
Packit 209cc3
        || PCAP_IS_AT_LEAST_XL_C_VERSION(12,0)
Packit 209cc3
      /*
Packit 209cc3
       * GCC 3.4 or later, or some compiler asserting compatibility with
Packit 209cc3
       * GCC 3.4 or later, or XL C 13.0 or later, so we have
Packit 209cc3
       * __attribute__((visibility()).
Packit 209cc3
       */
Packit 209cc3
      #define PCAP_API_DEF	__attribute__((visibility("default")))
Packit 209cc3
    #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
Packit 209cc3
      /*
Packit 209cc3
       * Sun C 5.5 or later, so we have __global.
Packit 209cc3
       * (Sun C 5.9 and later also have __attribute__((visibility()),
Packit 209cc3
       * but there's no reason to prefer it with Sun C.)
Packit 209cc3
       */
Packit 209cc3
      #define PCAP_API_DEF	__global
Packit 209cc3
    #else
Packit 209cc3
      /*
Packit 209cc3
       * We don't have anything to say.
Packit 209cc3
       */
Packit 209cc3
      #define PCAP_API_DEF
Packit 209cc3
    #endif
Packit 209cc3
  #else
Packit 209cc3
    /*
Packit 209cc3
     * We're not building libpcap.
Packit 209cc3
     */
Packit 209cc3
    #define PCAP_API_DEF
Packit 209cc3
  #endif
Packit 209cc3
#endif /* _WIN32/MSDOS/UN*X */
Packit 209cc3
Packit 209cc3
#define PCAP_API	PCAP_API_DEF extern
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * PCAP_NORETURN, before a function declaration, means "this function
Packit 209cc3
 * never returns".  (It must go before the function declaration, e.g.
Packit 209cc3
 * "extern PCAP_NORETURN func(...)" rather than after the function
Packit 209cc3
 * declaration, as the MSVC version has to go before the declaration.)
Packit 209cc3
 *
Packit 209cc3
 * PCAP_NORETURN_DEF, before a function *definition*, means "this
Packit 209cc3
 * function never returns"; it would be used only for static functions
Packit 209cc3
 * that are defined before any use, and thus have no declaration.
Packit 209cc3
 * (MSVC doesn't support that; I guess the "decl" in "__declspec"
Packit 209cc3
 * means "declaration", and __declspec doesn't work with definitions.)
Packit 209cc3
 */
Packit 209cc3
#if __has_attribute(noreturn) \
Packit 209cc3
    || PCAP_IS_AT_LEAST_GNUC_VERSION(2,5) \
Packit 209cc3
    || PCAP_IS_AT_LEAST_SUNC_VERSION(5,9) \
Packit 209cc3
    || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \
Packit 209cc3
    || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10)
Packit 209cc3
  /*
Packit 209cc3
   * Compiler with support for __attribute((noreturn)), or GCC 2.5 or
Packit 209cc3
   * later, or some compiler asserting compatibility with GCC 2.5 or
Packit 209cc3
   * later, or Solaris Studio 12 (Sun C 5.9) or later, or IBM XL C 10.1
Packit 209cc3
   * or later (do any earlier versions of XL C support this?), or HP aCC
Packit 209cc3
   * A.06.10 or later.
Packit 209cc3
   */
Packit 209cc3
  #define PCAP_NORETURN __attribute((noreturn))
Packit 209cc3
  #define PCAP_NORETURN_DEF __attribute((noreturn))
Packit 209cc3
#elif defined(_MSC_VER)
Packit 209cc3
  /*
Packit 209cc3
   * MSVC.
Packit 209cc3
   */
Packit 209cc3
  #define PCAP_NORETURN __declspec(noreturn)
Packit 209cc3
  #define PCAP_NORETURN_DEF
Packit 209cc3
#else
Packit 209cc3
  #define PCAP_NORETURN
Packit 209cc3
  #define PCAP_NORETURN_DEF
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * PCAP_PRINTFLIKE(x,y), after a function declaration, means "this function
Packit 209cc3
 * does printf-style formatting, with the xth argument being the format
Packit 209cc3
 * string and the yth argument being the first argument for the format
Packit 209cc3
 * string".
Packit 209cc3
 */
Packit 209cc3
#if __has_attribute(__format__) \
Packit 209cc3
    || PCAP_IS_AT_LEAST_GNUC_VERSION(2,3) \
Packit 209cc3
    || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \
Packit 209cc3
    || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10)
Packit 209cc3
  /*
Packit 209cc3
   * Compiler with support for it, or GCC 2.3 or later, or some compiler
Packit 209cc3
   * asserting compatibility with GCC 2.3 or later, or IBM XL C 10.1
Packit 209cc3
   * and later (do any earlier versions of XL C support this?),
Packit 209cc3
   * or HP aCC A.06.10 and later.
Packit 209cc3
   */
Packit 209cc3
  #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
Packit 209cc3
#else
Packit 209cc3
  #define PCAP_PRINTFLIKE(x,y)
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * PCAP_DEPRECATED(func, msg), after a function declaration, marks the
Packit 209cc3
 * function as deprecated.
Packit 209cc3
 *
Packit 209cc3
 * The first argument is the name of the function; the second argument is
Packit 209cc3
 * a string giving the warning message to use if the compiler supports that.
Packit 209cc3
 *
Packit 209cc3
 * (Thank you, Microsoft, for requiring the function name.)
Packit 209cc3
 */
Packit 209cc3
#if __has_attribute(deprecated) \
Packit 209cc3
    || PCAP_IS_AT_LEAST_GNUC_VERSION(4,5) \
Packit 209cc3
    || PCAP_IS_AT_LEAST_SUNC_VERSION(5,13)
Packit 209cc3
  /*
Packit 209cc3
   * Compiler that supports __has_attribute and __attribute__((deprecated)),
Packit 209cc3
   * or GCC 4.5 or later, or Sun/Oracle C 12.4 (Sun C 5.13) or later.
Packit 209cc3
   *
Packit 209cc3
   * Those support __attribute__((deprecated(msg))) (we assume, perhaps
Packit 209cc3
   * incorrectly, that anything that supports __has_attribute() is
Packit 209cc3
   * recent enough to support __attribute__((deprecated(msg)))).
Packit 209cc3
   */
Packit 209cc3
  #define PCAP_DEPRECATED(func, msg)	__attribute__((deprecated(msg)))
Packit 209cc3
#elif PCAP_IS_AT_LEAST_GNUC_VERSION(3,1)
Packit 209cc3
  /*
Packit 209cc3
   * GCC 3.1 through 4.4.
Packit 209cc3
   *
Packit 209cc3
   * Those support __attribute__((deprecated)) but not
Packit 209cc3
   * __attribute__((deprecated(msg))).
Packit 209cc3
   */
Packit 209cc3
  #define PCAP_DEPRECATED(func, msg)	__attribute__((deprecated))
Packit 209cc3
#elif (defined(_MSC_VER) && (_MSC_VER >= 1500)) && !defined(BUILDING_PCAP)
Packit 209cc3
  /*
Packit 209cc3
   * MSVC from Visual Studio 2008 or later, and we're not building
Packit 209cc3
   * libpcap itself.
Packit 209cc3
   *
Packit 209cc3
   * If we *are* building libpcap, we don't want this, as it'll warn
Packit 209cc3
   * us even if we *define* the function.
Packit 209cc3
   */
Packit 209cc3
  #define PCAP_DEPRECATED(func, msg)	__pragma(deprecated(func))
Packit 209cc3
#else
Packit 209cc3
  #define PCAP_DEPRECATED(func, msg)
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * For flagging arguments as format strings in MSVC.
Packit 209cc3
 */
Packit 209cc3
#ifdef _MSC_VER
Packit 209cc3
 #include <sal.h>
Packit 209cc3
 #if _MSC_VER > 1400
Packit 209cc3
  #define PCAP_FORMAT_STRING(p) _Printf_format_string_ p
Packit 209cc3
 #else
Packit 209cc3
  #define PCAP_FORMAT_STRING(p) __format_string p
Packit 209cc3
 #endif
Packit 209cc3
#else
Packit 209cc3
 #define PCAP_FORMAT_STRING(p) p
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
#endif /* lib_pcap_funcattrs_h */