]>
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
38 #include <pcap/compiler-tests.h>
41 * Attributes to apply to functions and their arguments, using various
42 * compiler-specific extensions.
46 * PCAP_API_DEF must be used when defining *data* exported from
47 * libpcap. It can be used when defining *functions* exported
48 * from libpcap, but it doesn't have to be used there. It
49 * should not be used in declarations in headers.
51 * PCAP_API must be used when *declaring* data or functions
52 * exported from libpcap; PCAP_API_DEF won't work on all platforms.
58 * We're compiling libpcap, so we should export functions in our
61 #define PCAP_API_DEF __declspec(dllexport)
63 #define PCAP_API_DEF __declspec(dllimport)
66 /* XXX - does this need special treatment? */
71 * We're compiling libpcap, so we should export functions in our API.
72 * The compiler might be configured not to export functions from a
73 * shared library by default, so we might have to explicitly mark
74 * functions as exported.
76 #if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) \
77 || PCAP_IS_AT_LEAST_XL_C_VERSION(12,0)
79 * GCC 3.4 or later, or some compiler asserting compatibility with
80 * GCC 3.4 or later, or XL C 13.0 or later, so we have
81 * __attribute__((visibility()).
83 #define PCAP_API_DEF __attribute__((visibility("default")))
84 #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
86 * Sun C 5.5 or later, so we have __global.
87 * (Sun C 5.9 and later also have __attribute__((visibility()),
88 * but there's no reason to prefer it with Sun C.)
90 #define PCAP_API_DEF __global
93 * We don't have anything to say.
99 * We're not building libpcap.
103 #endif /* _WIN32/MSDOS/UN*X */
105 #define PCAP_API PCAP_API_DEF extern
108 * PCAP_NORETURN, before a function declaration, means "this function
109 * never returns". (It must go before the function declaration, e.g.
110 * "extern PCAP_NORETURN func(...)" rather than after the function
111 * declaration, as the MSVC version has to go before the declaration.)
113 #if __has_attribute(noreturn) \
114 || PCAP_IS_AT_LEAST_GNUC_VERSION(2,5) \
115 || PCAP_IS_AT_LEAST_SUNC_VERSION(5,9) \
116 || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \
117 || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10)
119 * Compiler with support for __attribute((noreturn)), or GCC 2.5 and
120 * later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1
121 * and later (do any earlier versions of XL C support this?), or
122 * HP aCC A.06.10 and later.
124 #define PCAP_NORETURN __attribute((noreturn))
125 #elif defined(_MSC_VER)
129 #define PCAP_NORETURN __declspec(noreturn)
131 #define PCAP_NORETURN
135 * PCAP_PRINTFLIKE(x,y), after a function declaration, means "this function
136 * does printf-style formatting, with the xth argument being the format
137 * string and the yth argument being the first argument for the format
140 #if __has_attribute(__format__) \
141 || PCAP_IS_AT_LEAST_GNUC_VERSION(2,3) \
142 || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \
143 || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10)
145 * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1
146 * and later (do any earlier versions of XL C support this?),
147 * or HP aCC A.06.10 and later.
149 #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
151 #define PCAP_PRINTFLIKE(x,y)
155 * PCAP_DEPRECATED(func, msg), after a function declaration, marks the
156 * function as deprecated.
158 * The first argument is the name of the function; the second argument is
159 * a string giving the warning message to use if the compiler supports that.
161 * (Thank you, Microsoft, for requiring the function name.)
163 #if __has_attribute(deprecated) \
164 || PCAP_IS_AT_LEAST_GNUC_VERSION(4,5) \
165 || PCAP_IS_AT_LEAST_SUNC_VERSION(5,13)
167 * Compiler that supports __has_attribute and __attribute__((deprecated)),
168 * or GCC 4.5 and later, or Sun/Oracle C 12.4 (Sun C 5.13) or later.
170 * Those support __attribute__((deprecated(msg))) (we assume, perhaps
171 * incorrectly, that anything that supports __has_attribute() is
172 * recent enough to support __attribute__((deprecated(msg)))).
174 #define PCAP_DEPRECATED(func, msg) __attribute__((deprecated(msg)))
175 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(3,1)
177 * GCC 3.1 through 4.4.
179 * Those support __attribute__((deprecated)) but not
180 * __attribute__((deprecated(msg))).
182 #define PCAP_DEPRECATED(func, msg) __attribute__((deprecated))
183 #elif (defined(_MSC_VER) && (_MSC_VER >= 1500)) && !defined(BUILDING_PCAP)
185 * MSVC from Visual Studio 2008 or later, and we're not building
188 * If we *are* building libpcap, we don't want this, as it'll warn
189 * us even if we *define* the function.
191 #define PCAP_DEPRECATED(func, msg) __pragma(deprecated(func))
193 #define PCAP_DEPRECATED(func, msg)
197 * For flagging arguments as format strings in MSVC.
202 #define PCAP_FORMAT_STRING(p) _Printf_format_string_ p
204 #define PCAP_FORMAT_STRING(p) __format_string p
207 #define PCAP_FORMAT_STRING(p) p
210 #endif /* lib_pcap_funcattrs_h */