]> The Tcpdump Group git mirrors - libpcap/commitdiff
Use compiler #defines to determine how to handle some function attributes.
authorGuy Harris <[email protected]>
Sun, 19 Mar 2017 18:18:43 +0000 (11:18 -0700)
committerGuy Harris <[email protected]>
Sun, 19 Mar 2017 18:18:43 +0000 (11:18 -0700)
Take the set of tests in the test programs that check compiler and
version to decide how to mark functions as printflike or as not
returning, and put them into a header.  Use that throughout the libpcap
code, rather than doing configuration-time tests that have to be
replicated in the autoconf script and CMake files.

That obviates the need to put those tests into CMakeLists.txt and means
that, if we ever make functions with those attributes available by code
outside libpcap (for example, if we ever introduce a plugin mechanism
for libpcap, to allow third-party pcap modules to be maintained
separately from libpcap), we can use those declarations (making a public
header file dependent on the results of a configure script usually
doesn't work well, for a variety of reasons).

17 files changed:
Makefile.in
aclocal.m4
cmakeconfig.h.in
config.h.in
configure
configure.ac
funcattrs.h [new file with mode: 0644]
gencode.h
portability.h
tests/can_set_rfmon_test.c
tests/capturetest.c
tests/filtertest.c
tests/findalldevstest.c
tests/opentest.c
tests/reactivatetest.c
tests/selpolltest.c
tests/valgrindtest.c

index bf10bf979921d24216913e2e54ec5481b9fa61aa..cc383fcc39402674c915b030989ea69e46f17083 100644 (file)
@@ -119,6 +119,7 @@ HDR = $(PUBHDR) \
        atmuni31.h \
        ethertype.h \
        extract.h \
+       funcattrs.h \
        gencode.h \
        ieee80211.h \
        llc.h \
index 83f5761f0b13c1a941d8bb156cd75d4d609040fc..a06e217425dac8de9c6f01918a7ac0e434acd966 100644 (file)
@@ -1142,38 +1142,6 @@ fi
 AC_MSG_RESULT($ac_cv___attribute___unused)
 ])
 
-dnl
-dnl Test whether __attribute__((format)) can be used without warnings
-dnl
-
-AC_DEFUN(AC_C___ATTRIBUTE___FORMAT, [
-AC_MSG_CHECKING([whether __attribute__((format)) can be used without warnings])
-AC_CACHE_VAL(ac_cv___attribute___format, [
-save_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
-AC_COMPILE_IFELSE([
-  AC_LANG_SOURCE([[
-#include <stdlib.h>
-
-extern int foo(const char *fmt, ...)
-                 __attribute__ ((format (printf, 1, 2)));
-
-int
-main(int argc, char **argv)
-{
-  foo("%s", "test");
-}
-  ]])],
-ac_cv___attribute___format=yes,
-ac_cv___attribute___format=no)])
-CFLAGS="$save_CFLAGS"
-if test "$ac_cv___attribute___format" = "yes"; then
-  AC_DEFINE(__ATTRIBUTE___FORMAT_OK, 1,
-    [define if your compiler allows __attribute__((format)) without a warning])
-fi
-AC_MSG_RESULT($ac_cv___attribute___format)
-])
-
 dnl
 dnl Checks to see if tpacket_stats is defined in linux/if_packet.h
 dnl If so then pcap-linux.c can use this to report proper statistics.
index b4f946d0ff11d48517b6e837a64a00d0b3c26c02..566afde3d518a0d9301705d700be036df3f36a0e 100644 (file)
 /* define on AIX to get certain functions */
 #cmakedefine _SUN 1
 
-/* define if your compiler allows __attribute__((format)) without a warning */
-#cmakedefine __ATTRIBUTE___FORMAT_OK 1
-
 #if 0
 /* to handle Ultrix compilers that don't support const in prototypes */
 #cmakedefine const 1
index 290aba28f1795c2c043a565c99c48f833bf64eb2..d901c7501ca8d71a41451fcbf1ddadcb3ab0c3c1 100644 (file)
 /* define on AIX to get certain functions */
 #undef _SUN
 
-/* define if your compiler allows __attribute__((format)) without a warning */
-#undef __ATTRIBUTE___FORMAT_OK
-
 /* to handle Ultrix compilers that don't support const in prototypes */
 #undef const
 
index 8071ecffbbbb66e58db98a9f6ff2c29e50f8af7c..a4904572bbc1bf1aa09ab53b9f5e1a7674d702fd 100755 (executable)
--- a/configure
+++ b/configure
@@ -3906,48 +3906,6 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv___attribute___unused" >&5
 $as_echo "$ac_cv___attribute___unused" >&6; }
 
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether __attribute__((format)) can be used without warnings" >&5
-$as_echo_n "checking whether __attribute__((format)) can be used without warnings... " >&6; }
-if ${ac_cv___attribute___format+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-
-save_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-
-#include <stdlib.h>
-
-extern int foo(const char *fmt, ...)
-                 __attribute__ ((format (printf, 1, 2)));
-
-int
-main(int argc, char **argv)
-{
-  foo("%s", "test");
-}
-
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  ac_cv___attribute___format=yes
-else
-  ac_cv___attribute___format=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-
-CFLAGS="$save_CFLAGS"
-if test "$ac_cv___attribute___format" = "yes"; then
-
-$as_echo "#define __ATTRIBUTE___FORMAT_OK 1" >>confdefs.h
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv___attribute___format" >&5
-$as_echo "$ac_cv___attribute___format" >&6; }
-
 fi
 
 ac_ext=c
index d275bcaf9b48c425e5e7acdcac0feb8ef25463a8..4ae1f0bbe71136a3342f1fe0ec1d99bdd01a3954 100644 (file)
@@ -27,7 +27,6 @@ AC_LBL_C_INLINE
 AC_C___ATTRIBUTE__
 if test "$ac_cv___attribute__" = "yes"; then
        AC_C___ATTRIBUTE___UNUSED
-       AC_C___ATTRIBUTE___FORMAT
 fi
 
 AC_CHECK_HEADERS(sys/bitypes.h)
diff --git a/funcattrs.h b/funcattrs.h
new file mode 100644 (file)
index 0000000..b9866b7
--- /dev/null
@@ -0,0 +1,116 @@
+/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
+/*
+ * Copyright (c) 1993, 1994, 1995, 1996, 1997
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the Computer Systems
+ *     Engineering Group at Lawrence Berkeley Laboratory.
+ * 4. Neither the name of the University nor of the Laboratory may be used
+ *    to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lib_funcattrs_h
+#define lib_funcattrs_h
+
+/*
+ * Attributes to apply to functions and their arguments, using various
+ * compiler-specific extensions.
+ */
+
+/*
+ * This was introduced by Clang:
+ *
+ *     http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
+ *
+ * in some version (which version?); it has been picked up by GCC 5.0.
+ */
+#ifndef __has_attribute
+  /*
+   * It's a macro, so you can check whether it's defined to check
+   * whether it's supported.
+   *
+   * If it's not, define it to always return 0, so that we move on to
+   * the fallback checks.
+   */
+  #define __has_attribute(x) 0
+#endif
+
+/*
+ * PCAP_NORETURN, after a function declaration, means "this function
+ * never returns".
+ */
+#if __has_attribute(noreturn) \
+    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
+    || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) \
+    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
+    || (defined(__HP_aCC) && __HP_aCC >= 61000)
+  /*
+   * Compiler with support for it, or GCC 2.5 and later, or Solaris Studio 12
+   * (Sun C 5.9) and later, or IBM XL C 10.1 and later (do any earlier
+   * versions of XL C support this?), or HP aCC A.06.10 and later.
+   */
+  #define PCAP_NORETURN __attribute((noreturn))
+#elif defined(_MSC_VER)
+  #define PCAP_NORETURN __declspec(noreturn)
+#else
+  #define PCAP_NORETURN
+#endif
+
+/*
+ * PCAP_PRINTFLIKE(x,y), after a function declaration, means "this function
+ * does printf-style formatting, with the xth argument being the format
+ * string and the yth argument being the first argument for the format
+ * string".
+ */
+#if __has_attribute(__format__) \
+    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)) \
+    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
+    || (defined(__HP_aCC) && __HP_aCC >= 61000)
+  /*
+   * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1
+   * and later (do any earlier versions of XL C support this?),
+   * or HP aCC A.06.10 and later.
+   */
+  #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
+#else
+  #define PCAP_PRINTFLIKE(x,y)
+#endif
+
+/*
+ * For flagging arguments as format strings in MSVC.
+ */
+#if _MSC_VER >= 1400
+ #include <sal.h>
+ #if _MSC_VER > 1400
+  #define PCAP_FORMAT_STRING(p) _Printf_format_string_ p
+ #else
+  #define PCAP_FORMAT_STRING(p) __format_string p
+ #endif
+#else
+ #define PCAP_FORMAT_STRING(p) p
+#endif
+
+#endif /* lib_funcattrs_h */
index 2b089d21d561689cbabd4d165906a54e08f2863a..bd9aeda9f63b205976557a5f6a449deab03cc6d5 100644 (file)
--- a/gencode.h
+++ b/gencode.h
@@ -19,6 +19,8 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#include "funcattrs.h"
+
 /*
  * ATM support:
  *
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef HAVE___ATTRIBUTE__
-#define __attribute__(x)
-#endif /* HAVE___ATTRIBUTE__ */
-
 /* Address qualifiers. */
 
 #define Q_HOST         1
@@ -367,12 +365,8 @@ struct icode {
 
 void bpf_optimize(compiler_state_t *, struct icode *ic);
 void bpf_syntax_error(compiler_state_t *, const char *);
-void bpf_error(compiler_state_t *, const char *, ...)
-    __attribute__((noreturn))
-#ifdef __ATTRIBUTE___FORMAT_OK
-    __attribute__((format (printf, 2, 3)))
-#endif /* __ATTRIBUTE___FORMAT_OK */
-    ;
+void bpf_error(compiler_state_t *, const char *, ...) PCAP_NORETURN
+    PCAP_PRINTFLIKE(2, 3);
 
 void finish_parse(compiler_state_t *, struct block *);
 char *sdup(compiler_state_t *, const char *);
index ce075500ed4e5329dde5b58f742b280b2a671158..d4343e62d564398b75be95f0add252c29ffb439b 100644 (file)
@@ -39,6 +39,8 @@
  * flavors of UN*X.
  */
 
+#include "funcattrs.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -85,20 +87,6 @@ extern "C" {
  #endif
 #endif
 
-/*
- * For flagging arguments as format strings in MSVC.
- */
-#if _MSC_VER >= 1400
- #include <sal.h>
- #if _MSC_VER > 1400
-  #define FORMAT_STRING(p) _Printf_format_string_ p
- #else
-  #define FORMAT_STRING(p) __format_string p
- #endif
-#else
- #define FORMAT_STRING(p) p
-#endif
-
 #ifdef _MSC_VER
   #define strdup       _strdup
   #define sscanf       sscanf_s
@@ -146,11 +134,8 @@ extern "C" {
 #ifdef HAVE_SNPRINTF
 #define pcap_snprintf snprintf
 #else
-extern int pcap_snprintf(char *, size_t, FORMAT_STRING(const char *), ...)
-#ifdef __ATTRIBUTE___FORMAT_OK
-    __attribute__((format (printf, 3, 4)))
-#endif /* __ATTRIBUTE___FORMAT_OK */
-    ;
+extern int pcap_snprintf(char *, size_t, PCAP_FORMAT_STRING(const char *), ...)
+    PCAP_PRINTFLIKE(3, 4);
 #endif
 
 #ifdef HAVE_VSNPRINTF
index f1644e66b7684991f5cee8bda674031b05e0ca0b..53a7f3663ea53b98f4b581f804eeb0979da52e71 100644 (file)
@@ -32,6 +32,8 @@ The Regents of the University of California.  All rights reserved.\n";
 
 #include <pcap.h>
 
+#include "../funcattrs.h"
+
 static const char *program_name;
 
 /* Forwards */
index 14b1554b51892ca7d3491e9b7f6a9e83fa24f00e..09a73b40c4160b7b4a0af4f8e4931dc36e9acb10 100644 (file)
@@ -40,56 +40,9 @@ The Regents of the University of California.  All rights reserved.\n";
 
 #include <pcap.h>
 
-static char *program_name;
-
-/*
- * This was introduced by Clang:
- *
- *     http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
- *
- * in some version (which version?); it has been picked up by GCC 5.0.
- */
-#ifndef __has_attribute
-  /*
-   * It's a macro, so you can check whether it's defined to check
-   * whether it's supported.
-   *
-   * If it's not, define it to always return 0, so that we move on to
-   * the fallback checks.
-   */
-  #define __has_attribute(x) 0
-#endif
+#include "../funcattrs.h"
 
-#if __has_attribute(noreturn) \
-    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
-    || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) \
-    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
-    || (defined(__HP_aCC) && __HP_aCC >= 61000)
-  /*
-   * Compiler with support for it, or GCC 2.5 and later, or Solaris Studio 12
-   * (Sun C 5.9) and later, or IBM XL C 10.1 and later (do any earlier
-   * versions of XL C support this?), or HP aCC A.06.10 and later.
-   */
-  #define PCAP_NORETURN __attribute((noreturn))
-#elif defined( _MSC_VER )
-  #define PCAP_NORETURN __declspec(noreturn)
-#else
-  #define PCAP_NORETURN
-#endif
-
-#if __has_attribute(__format__) \
-    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)) \
-    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
-    || (defined(__HP_aCC) && __HP_aCC >= 61000)
-  /*
-   * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1
-   * and later (do any earlier versions of XL C support this?),
-   * or HP aCC A.06.10 and later.
-   */
-  #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
-#else
-  #define PCAP_PRINTFLIKE(x,y)
-#endif
+static char *program_name;
 
 /* Forwards */
 static void countme(u_char *, const struct pcap_pkthdr *, const u_char *);
index d4440eb06b3d8cb59c9ed25d3a6467007faf78b3..e9a74c6ccf807c8c15898b4510924d7580b12b75 100644 (file)
@@ -50,54 +50,7 @@ The Regents of the University of California.  All rights reserved.\n";
 #include <sys/types.h>
 #include <sys/stat.h>
 
-/*
- * This was introduced by Clang:
- *
- *     http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
- *
- * in some version (which version?); it has been picked up by GCC 5.0.
- */
-#ifndef __has_attribute
-  /*
-   * It's a macro, so you can check whether it's defined to check
-   * whether it's supported.
-   *
-   * If it's not, define it to always return 0, so that we move on to
-   * the fallback checks.
-   */
-  #define __has_attribute(x) 0
-#endif
-
-#if __has_attribute(noreturn) \
-    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
-    || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) \
-    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
-    || (defined(__HP_aCC) && __HP_aCC >= 61000)
-  /*
-   * Compiler with support for it, or GCC 2.5 and later, or Solaris Studio 12
-   * (Sun C 5.9) and later, or IBM XL C 10.1 and later (do any earlier
-   * versions of XL C support this?), or HP aCC A.06.10 and later.
-   */
-  #define PCAP_NORETURN __attribute((noreturn))
-#elif defined( _MSC_VER )
-  #define PCAP_NORETURN __declspec(noreturn)
-#else
-  #define PCAP_NORETURN
-#endif
-
-#if __has_attribute(__format__) \
-    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)) \
-    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
-    || (defined(__HP_aCC) && __HP_aCC >= 61000)
-  /*
-   * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1
-   * and later (do any earlier versions of XL C support this?),
-   * or HP aCC A.06.10 and later.
-   */
-  #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
-#else
-  #define PCAP_PRINTFLIKE(x,y)
-#endif
+#include "../funcattrs.h"
 
 static char *program_name;
 
index cbd3dad73f65c53586602b1a83ae35afd615cdb0..88bc349687f01276a38010bce0b24cd37f4b9c29 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <pcap.h>
 
+#include "../funcattrs.h"
+
 static int ifprint(pcap_if_t *d);
 static char *iptos(bpf_u_int32 in);
 
index b6d634f0d901eaf42199f3c8536ce4a3d5995c32..5874d048507267859d0dba3c5a0863d164c3242a 100644 (file)
@@ -37,59 +37,12 @@ The Regents of the University of California.  All rights reserved.\n";
 #endif
 #include <errno.h>
 
+#include "../funcattrs.h"
+
 #define MAXIMUM_SNAPLEN                65535
 
 static char *program_name;
 
-/*
- * This was introduced by Clang:
- *
- *     http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
- *
- * in some version (which version?); it has been picked up by GCC 5.0.
- */
-#ifndef __has_attribute
-  /*
-   * It's a macro, so you can check whether it's defined to check
-   * whether it's supported.
-   *
-   * If it's not, define it to always return 0, so that we move on to
-   * the fallback checks.
-   */
-  #define __has_attribute(x) 0
-#endif
-
-#if __has_attribute(noreturn) \
-    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
-    || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) \
-    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
-    || (defined(__HP_aCC) && __HP_aCC >= 61000)
-  /*
-   * Compiler with support for it, or GCC 2.5 and later, or Solaris Studio 12
-   * (Sun C 5.9) and later, or IBM XL C 10.1 and later (do any earlier
-   * versions of XL C support this?), or HP aCC A.06.10 and later.
-   */
-  #define PCAP_NORETURN __attribute((noreturn))
-#elif defined( _MSC_VER )
-  #define PCAP_NORETURN __declspec(noreturn)
-#else
-  #define PCAP_NORETURN
-#endif
-
-#if __has_attribute(__format__) \
-    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)) \
-    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
-    || (defined(__HP_aCC) && __HP_aCC >= 61000)
-  /*
-   * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1
-   * and later (do any earlier versions of XL C support this?),
-   * or HP aCC A.06.10 and later.
-   */
-  #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
-#else
-  #define PCAP_PRINTFLIKE(x,y)
-#endif
-
 /* Forwards */
 static void PCAP_NORETURN usage(void);
 static void PCAP_NORETURN error(const char *, ...) PCAP_PRINTFLIKE(1, 2);
index 2e1b7b67adb75e779a03fcef6aa3d3123c0d1fca..c90de155d7c9458aaff2216962125d180c99a6fc 100644 (file)
@@ -31,6 +31,8 @@ The Regents of the University of California.  All rights reserved.\n";
 #include <string.h>
 #include <stdarg.h>
 
+#include "../funcattrs.h"
+
 /* Forwards */
 static void error(const char *, ...);
 
index 4c1415b683545d180154608888dc0c3bf1cf2702..9b1ca25e086a2e4825ad45ddad742baba0f9d56f 100644 (file)
@@ -48,56 +48,9 @@ The Regents of the University of California.  All rights reserved.\n";
 #endif
 #include <poll.h>
 
-char *program_name;
-
-/*
- * This was introduced by Clang:
- *
- *     http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
- *
- * in some version (which version?); it has been picked up by GCC 5.0.
- */
-#ifndef __has_attribute
-  /*
-   * It's a macro, so you can check whether it's defined to check
-   * whether it's supported.
-   *
-   * If it's not, define it to always return 0, so that we move on to
-   * the fallback checks.
-   */
-  #define __has_attribute(x) 0
-#endif
+#include "../funcattrs.h"
 
-#if __has_attribute(noreturn) \
-    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
-    || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) \
-    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
-    || (defined(__HP_aCC) && __HP_aCC >= 61000)
-  /*
-   * Compiler with support for it, or GCC 2.5 and later, or Solaris Studio 12
-   * (Sun C 5.9) and later, or IBM XL C 10.1 and later (do any earlier
-   * versions of XL C support this?), or HP aCC A.06.10 and later.
-   */
-  #define PCAP_NORETURN __attribute((noreturn))
-#elif defined( _MSC_VER )
-  #define PCAP_NORETURN __declspec(noreturn)
-#else
-  #define PCAP_NORETURN
-#endif
-
-#if __has_attribute(__format__) \
-    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)) \
-    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
-    || (defined(__HP_aCC) && __HP_aCC >= 61000)
-  /*
-   * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1
-   * and later (do any earlier versions of XL C support this?),
-   * or HP aCC A.06.10 and later.
-   */
-  #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
-#else
-  #define PCAP_PRINTFLIKE(x,y)
-#endif
+char *program_name;
 
 /* Forwards */
 static void countme(u_char *, const struct pcap_pkthdr *, const u_char *);
index 011fe117b2cd34acd6181e305eb45d5f7387b97c..86bef7decc8fbdb32e1a5e2cd0f7359c267e4104 100644 (file)
@@ -64,6 +64,8 @@ The Regents of the University of California.  All rights reserved.\n";
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include "../funcattrs.h"
+
 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
 /* BSD-flavored OS - use BPF */
 #define USE_BPF
@@ -99,55 +101,6 @@ The Regents of the University of California.  All rights reserved.\n";
 
 static char *program_name;
 
-/*
- * This was introduced by Clang:
- *
- *     http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
- *
- * in some version (which version?); it has been picked up by GCC 5.0.
- */
-#ifndef __has_attribute
-  /*
-   * It's a macro, so you can check whether it's defined to check
-   * whether it's supported.
-   *
-   * If it's not, define it to always return 0, so that we move on to
-   * the fallback checks.
-   */
-  #define __has_attribute(x) 0
-#endif
-
-#if __has_attribute(noreturn) \
-    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
-    || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) \
-    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
-    || (defined(__HP_aCC) && __HP_aCC >= 61000)
-  /*
-   * Compiler with support for it, or GCC 2.5 and later, or Solaris Studio 12
-   * (Sun C 5.9) and later, or IBM XL C 10.1 and later (do any earlier
-   * versions of XL C support this?), or HP aCC A.06.10 and later.
-   */
-  #define PCAP_NORETURN __attribute((noreturn))
-#elif defined( _MSC_VER )
-  #define PCAP_NORETURN __declspec(noreturn)
-#else
-  #define PCAP_NORETURN
-#endif
-
-#if __has_attribute(__format__) \
-    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)) \
-    || (defined(__xlC__) && __xlC__ >= 0x0A01) \
-    || (defined(__HP_aCC) && __HP_aCC >= 61000)
-  /*
-   * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1
-   * and later (do any earlier versions of XL C support this?),
-   * or HP aCC A.06.10 and later.
-   */
-  #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
-#else
-  #define PCAP_PRINTFLIKE(x,y)
-#endif
-
 /* Forwards */
 static void PCAP_NORETURN usage(void);
 static void PCAP_NORETURN error(const char *, ...) PCAP_PRINTFLIKE(1, 2);