]>
The Tcpdump Group git mirrors - libpcap/blob - pcap/funcattrs.h
1 /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
3 * Copyright (c) 1993, 1994, 1995, 1996, 1997
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the Computer Systems
17 * Engineering Group at Lawrence Berkeley Laboratory.
18 * 4. Neither the name of the University nor of the Laboratory may be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #ifndef lib_pcap_funcattrs_h
36 #define lib_pcap_funcattrs_h
39 * Attributes to apply to functions and their arguments, using various
40 * compiler-specific extensions.
44 * PCAP_API_DEF must be used when defining *data* exported from
45 * libpcap. It can be used when defining *functions* exported
46 * from libpcap, but it doesn't have to be used there. It
47 * should not be used in declarations in headers.
49 * PCAP_API must be used when *declaring* data or functions
50 * exported from libpcap; PCAP_API_DEF won't work on all platforms.
54 * This was introduced by Clang:
56 * http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
58 * in some version (which version?); it has been picked up by GCC 5.0.
60 #ifndef __has_attribute
62 * It's a macro, so you can check whether it's defined to check
63 * whether it's supported.
65 * If it's not, define it to always return 0, so that we move on to
66 * the fallback checks.
68 #define __has_attribute(x) 0
72 * Check whether this is GCC major.minor or a later release, or some
73 * compiler that claims to be "just like GCC" of that version or a
76 #define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \
77 (defined(__GNUC__) && \
78 (__GNUC__ > (major) || \
79 (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))))
82 * Check wehether this is Sun C/SunPro C/Oracle Studio major.minor
85 * The version number in __SUNPRO_C is encoded in hex BCD, with the
86 * uppermost hex digit being the major version number, the next
87 * one or two hex digits being the minor version number, and
88 * the last digit being the patch version.
90 * It represents the *compiler* version, not the product version;
93 * https://sourceforge.net/p/predef/wiki/Compilers/
95 * for a partial mapping, which we assume continues for later
96 * 12.x product releases.
98 #define PCAP_SUNPRO_VERSION_TO_BCD(major, minor) \
100 (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \
101 (((major) << 8) | ((minor) << 4)))
102 #define PCAP_IS_AT_LEAST_SUNC_VERSION(major, minor) \
103 (defined(__SUNPRO_C) && \
104 (__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor))))
107 * Check wehether this is IBM XL C major.minor or a later release.
109 * The version number in __xlC__ has the major version in the
110 * upper 8 bits and the minor version in the lower 8 bits.
112 #define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \
113 (defined(__xlC__) && __xlC__ >= (((major) << 8) | (minor)))
116 * Check wehether this is Sun C/SunPro C/Oracle Studio major.minor
117 * or a later release.
119 * The version number in __HP_aCC is encoded in zero-padded decimal BCD,
120 * with the "A." stripped off, the uppermost two decimal digits being
121 * the major version number, the next two decimal digits being the minor
122 * version number, and the last two decimal digits being the patch version.
123 * (Strip off the A., remove the . between the major and minor version
124 * number, and add two digits of patch.)
126 #define PCAP_IS_AT_LEAST_HP_C_VERSION(major, minor) \
127 (defined(__HP_aCC) && \
128 (__HP_aCC >= ((major)*10000 + (minor)*100)))
133 * We're compiling libpcap, so we should export functions in our
136 #define PCAP_API_DEF __declspec(dllexport)
138 #define PCAP_API_DEF __declspec(dllimport)
141 /* XXX - does this need special treatment? */
146 * We're compiling libpcap, so we should export functions in our API.
147 * The compiler might be configured not to export functions from a
148 * shared library by default, so we might have to explicitly mark
149 * functions as exported.
151 #if PCAP_IS_AT_LEAST_GNUC_VERSION(3, 4) \
152 || PCAP_IS_AT_LEAST_XL_C_VERSION(12, 0)
154 * GCC 3.4 or later, or some compiler asserting compatibility with
155 * GCC 3.4 or later, or XL C 13.0 or later, so we have
156 * __attribute__((visibility()).
158 #define PCAP_API_DEF __attribute__((visibility("default")))
159 #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5, 5)
161 * Sun C 5.5 or later, so we have __global.
162 * (Sun C 5.9 and later also have __attribute__((visibility()),
163 * but there's no reason to prefer it with Sun C.)
165 #define PCAP_API_DEF __global
168 * We don't have anything to say.
174 * We're not building libpcap.
178 #endif /* _WIN32/MSDOS/UN*X */
180 #define PCAP_API PCAP_API_DEF extern
183 * PCAP_NORETURN, before a function declaration, means "this function
184 * never returns". (It must go before the function declaration, e.g.
185 * "extern PCAP_NORETURN func(...)" rather than after the function
186 * declaration, as the MSVC version has to go before the declaration.)
188 #if __has_attribute(noreturn) \
189 || PCAP_IS_AT_LEAST_GNUC_VERSION(2, 5) \
190 || PCAP_IS_AT_LEAST_SUNC_VERSION(5, 9) \
191 || PCAP_IS_AT_LEAST_XL_C_VERSION(10, 1) \
192 || PCAP_IS_AT_LEAST_HP_C_VERSION(6, 10)
194 * Compiler with support for __attribute((noreturn)), or GCC 2.5 and
195 * later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1
196 * and later (do any earlier versions of XL C support this?), or
197 * HP aCC A.06.10 and later.
199 #define PCAP_NORETURN __attribute((noreturn))
200 #elif defined(_MSC_VER)
204 #define PCAP_NORETURN __declspec(noreturn)
206 #define PCAP_NORETURN
210 * PCAP_PRINTFLIKE(x,y), after a function declaration, means "this function
211 * does printf-style formatting, with the xth argument being the format
212 * string and the yth argument being the first argument for the format
215 #if __has_attribute(__format__) \
216 || PCAP_IS_AT_LEAST_GNUC_VERSION(2, 3) \
217 || PCAP_IS_AT_LEAST_XL_C_VERSION(10, 1) \
218 || PCAP_IS_AT_LEAST_HP_C_VERSION(6, 10)
220 * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1
221 * and later (do any earlier versions of XL C support this?),
222 * or HP aCC A.06.10 and later.
224 #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
226 #define PCAP_PRINTFLIKE(x,y)
230 * PCAP_DEPRECATED(func, msg), after a function declaration, marks the
231 * function as deprecated.
233 * The first argument is the name of the function; the second argument is
234 * a string giving the warning message to use if the compiler supports that.
236 * (Thank you, Microsoft, for requiring the function name.)
238 #if __has_attribute(deprecated) \
239 || PCAP_IS_AT_LEAST_GNUC_VERSION(4, 5) \
240 || PCAP_IS_AT_LEAST_SUNC_VERSION(5, 13)
242 * Compiler that supports __has_attribute and __attribute__((deprecated)),
243 * or GCC 4.5 and later, or Sun/Oracle C 12.4 (Sun C 5.13) or later.
245 * Those support __attribute__((deprecated(msg))) (we assume, perhaps
246 * incorrectly, that anything that supports __has_attribute() is
247 * recent enough to support __attribute__((deprecated(msg)))).
249 #define PCAP_DEPRECATED(func, msg) __attribute__((deprecated(msg)))
250 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(3, 1)
252 * GCC 3.1 through 4.4.
254 * Those support __attribute__((deprecated)) but not
255 * __attribute__((deprecated(msg))).
257 #define PCAP_DEPRECATED(func, msg) __attribute__((deprecated))
258 #elif (defined(_MSC_VER) && (_MSC_VER >= 1500)) && !defined(BUILDING_PCAP)
260 * MSVC from Visual Studio 2008 or later, and we're not building
263 * If we *are* building libpcap, we don't want this, as it'll warn
264 * us even if we *define* the function.
266 #define PCAP_DEPRECATED(func, msg) __pragma(deprecated(func))
268 #define PCAP_DEPRECATED(func, msg)
272 * For flagging arguments as format strings in MSVC.
277 #define PCAP_FORMAT_STRING(p) _Printf_format_string_ p
279 #define PCAP_FORMAT_STRING(p) __format_string p
282 #define PCAP_FORMAT_STRING(p) p
285 #endif /* lib_pcap_funcattrs_h */