Clean up handling of missing functions.
authorGuy Harris <guy@alum.mit.edu>
Sun, 6 Jul 2014 21:02:39 +0000 (14:02 -0700)
committerGuy Harris <guy@alum.mit.edu>
Sun, 6 Jul 2014 21:03:09 +0000 (21:03 +0000)
With autotools, CMake, and nmake, if we have a function, #define
HAVE_{function_name_in_all_caps}, otherwise don't #define it.

If we provide our own version of a function in libwsutil, make sure we
have a header that declares it, and *ONLY* include that header if
HAVE_{function_name_in_all_caps} is *NOT* defined, so that we don't have
the system declaration and our declaration colliding.

Check for inet_aton, strncasecmp, and strptime with CMake, just as we do
with autotools.

Simplify the addition of {function_name_in_all_caps}_LO to libwsutil in
autotools.

Change-Id: Id5be5c73f79f81919a3a865324e400eca7b88889
Reviewed-on: https://code.wireshark.org/review/2903
Reviewed-by: Guy Harris <guy@alum.mit.edu>
16 files changed:
ConfigureChecks.cmake
config.h.win32
configure.ac
editcap.c
epan/addr_resolv.c
epan/dissectors/packet-dcom.c
epan/dissectors/packet-lbmr.c
epan/dissectors/packet-lbtrm.c
epan/ftypes/ftype-time.c
epan/tvbuff.c
text2pcap.c
ui/text_import.c
wsutil/Makefile.am
wsutil/strncasecmp.c
wsutil/strncasecmp.h [new file with mode: 0644]
wsutil/strptime.c

index 918a62803dcc6554556670ea03768143209402ce..cfa63150ea82fe86a2582be7c7e1c27412731723 100644 (file)
@@ -31,7 +31,6 @@ check_include_file("dlfcn.h"             HAVE_DLFCN_H)
 check_include_file("fcntl.h"             HAVE_FCNTL_H)
 check_include_file("getopt.h"            HAVE_GETOPT_H)
 check_include_file("grp.h"               HAVE_GRP_H)
-check_include_file("inet/aton.h"         HAVE_INET_ATON_H)
 check_include_file("inttypes.h"          HAVE_INTTYPES_H)
 check_include_file("memory.h"            HAVE_MEMORY_H)
 check_include_file("netinet/in.h"        HAVE_NETINET_IN_H)
@@ -83,6 +82,7 @@ cmake_pop_check_state()
 check_function_exists("gethostbyname2"   HAVE_GETHOSTBYNAME2)
 check_function_exists("getopt"           HAVE_GETOPT)
 check_function_exists("getprotobynumber" HAVE_GETPROTOBYNUMBER)
+check_function_exists("inet_aton"        HAVE_INET_ATON)
 check_function_exists("inet_ntop"        HAVE_INET_NTOP_PROTO)
 check_function_exists("issetugid"        HAVE_ISSETUGID)
 check_function_exists("mmap"             HAVE_MMAP)
@@ -91,6 +91,18 @@ check_function_exists("mkdtemp"          HAVE_MKDTEMP)
 check_function_exists("mkstemp"          HAVE_MKSTEMP)
 check_function_exists("setresgid"        HAVE_SETRESGID)
 check_function_exists("setresuid"        HAVE_SETRESUID)
+
+#
+# Windows doesn't have strncasecmp, but does have stricmp, which has
+# the same signature and behavior.  We #define strncasecmp to stricmp
+# on Windows.
+#
+if(WIN32)
+    check_function_exists("stricmp"          HAVE_STRNCASECMP)
+else()
+    check_function_exists("strncasecmp"      HAVE_STRNCASECMP)
+endif()
+check_function_exists("strptime"         HAVE_STRPTIME)
 check_function_exists("sysconf"          HAVE_SYSCONF)
 
 #Struct members
index 2db0fed13237af6b024fb0b4fb2d5ae3ffd0cdf2..b19b7dc7b63facc5c2c35bae1cda6d198ee2ac35 100644 (file)
 /* Define to have ntddndis.h */
 @HAVE_NTDDNDIS_H@
 
-/* #undef HAVE_INET_ATON_H */
+/* Define to 1 if you have the strncasecmp function. */
+/* Actually, we don't, but we have strnicmp, and #define strncasecmp to strnicmp below */
+#define HAVE_STRNCASECMP 1
+
+/* Define if you have the strptime function. */
+/* #undef HAVE_STRPTIME 1 */
+
 #define NEED_INET_V6DEFS_H  1
-#define NEED_STRPTIME_H     1
 
 #ifndef WIN32
 #define WIN32                  1
index 13347884f63456bffa99277b9a32a8c92ee33e4a..13c1de5f949602b66690aa147dc846d8df475e38 100644 (file)
@@ -2530,38 +2530,30 @@ AC_C_BIGENDIAN
 # XXX - do we need this?
 AC_PROG_GCC_TRADITIONAL
 
-GETOPT_LO=""
 AC_CHECK_FUNC(getopt,
-  [GETOPT_LO=""
-   AC_DEFINE(HAVE_GETOPT, 1, [Define to 1 if you have the getopt function.])
+  [
+    GETOPT_LO=""
+    AC_DEFINE(HAVE_GETOPT, 1, [Define to 1 if you have the getopt function.])
   ],
-  GETOPT_LO="wsgetopt.lo"
-)
-if test "$ac_cv_func_getopt" = no ; then
-  GETOPT_LO="wsgetopt.lo"
-fi
-AM_CONDITIONAL(NEED_GETOPT_LO, test "x$ac_cv_func_getopt" = "xno")
+  GETOPT_LO="wsgetopt.lo")
 AC_SUBST(GETOPT_LO)
 
-AC_CHECK_FUNC(strncasecmp, STRNCASECMP_LO="",
+AC_CHECK_FUNC(strncasecmp,
+  [
+    STRNCASECMP_LO=""
+    AC_DEFINE(HAVE_STRNCASECMP, 1, [Define to 1 if you have the strncasecmp function.])
+  ],
   STRNCASECMP_LO="strncasecmp.lo")
-if test "$ac_cv_func_strncasecmp" = no ; then
-  STRNCASECMP_LO="strncasecmp.lo"
-fi
-AM_CONDITIONAL(NEED_STRNCASECMP_LO, test "x$ac_cv_func_strncasecmp" = "xno")
 AC_SUBST(STRNCASECMP_LO)
 
 AC_CHECK_FUNCS(mkstemp mkdtemp)
 
-AC_SEARCH_LIBS(inet_aton, [socket nsl], have_inet_aton=yes,
-    have_inet_aton=no)
-if test "$have_inet_aton" = no; then
-  INET_ATON_LO="inet_aton.lo"
-  AC_DEFINE(HAVE_INET_ATON_H, 0, [Define unless inet/aton.h needs to be included])
-else
-  INET_ATON_LO=""
-fi
-AM_CONDITIONAL(NEED_INET_ATON_LO, test "x$have_inet_aton" = "xno")
+AC_SEARCH_LIBS(inet_aton, [socket nsl],
+  [
+    INET_ATON_LO=""
+    AC_DEFINE(HAVE_INET_ATON, 0, [Define to 1 if you have the inet_aton function.])
+  ],
+  INET_ATON_LO="inet_aton.lo")
 AC_SUBST(INET_ATON_LO)
 
 AC_SEARCH_LIBS(inet_pton, [socket nsl], [
@@ -2623,15 +2615,12 @@ extern const char *inet_ntop(int, const void *, char *, socklen_t);],, [
 AM_CONDITIONAL(NEED_INET_NTOP_LO, test "x$INET_NTOP_LO" != "x")
 AC_SUBST(INET_NTOP_LO)
 
-AC_CHECK_FUNC(strptime, STRPTIME_LO="",
-  [STRPTIME_LO="strptime.lo"
-   AC_DEFINE(NEED_STRPTIME_H, 1, [Define if strptime.h needs to be included])
-])
-if test "$ac_cv_func_strptime" = no ; then
-  STRPTIME_LO="strptime.lo"
-fi
-AC_SUBST(STRPTIME_C)
-AM_CONDITIONAL(NEED_STRPTIME_LO, test "x$ac_cv_func_strptime" = "no")
+AC_CHECK_FUNC(strptime,
+  [
+    STRPTIME_LO=""
+    AC_DEFINE(HAVE_STRPTIME, 1, [Define if you have the strptime function.])
+  ],
+  STRPTIME_LO="strptime.lo")
 AC_SUBST(STRPTIME_LO)
 
 AC_CHECK_FUNCS(getprotobynumber gethostbyname2)
index 4432d41984fdcbd9452cf169a8887321c82cfeab..a6d4720e3c8072c9c31c91eeea92fe03d75763c6 100644 (file)
--- a/editcap.c
+++ b/editcap.c
@@ -77,7 +77,7 @@
 #endif
 #endif
 
-#ifdef NEED_STRPTIME_H
+#ifndef HAVE_STRPTIME
 # include "wsutil/strptime.h"
 #endif
 
index fbfc7295debae8bfeb872f0922115cb84536e3e5..7e1420976c213643ec5685782c7dc84c16495325 100644 (file)
@@ -85,7 +85,7 @@
 #include <winsock2.h>       /* needed to define AF_ values on Windows */
 #endif
 
-#ifndef HAVE_INET_ATON_H
+#ifndef HAVE_INET_ATON
 # include "wsutil/inet_aton.h"
 #endif
 
index d26b407f96fb6a54084e3c0f0b112efed1c9281d..c185ce4d0ddd1df8622fe14964a06aff21fed537 100644 (file)
@@ -81,7 +81,9 @@
 #include <epan/exceptions.h>
 #include <epan/wmem/wmem.h>
 #include <epan/addr_resolv.h>
+#ifndef HAVE_INET_ATON
 #include <wsutil/inet_aton.h>
+#endif
 #include <epan/expert.h>
 #include <epan/prefs.h>
 #include <ctype.h>
index f891bcc236e715fa2bf234d888dd8f2dc72a7e56..8e95b68bc9f8e6bcdd3ba233c8df08eadc35f579 100644 (file)
@@ -41,7 +41,9 @@
 #include <epan/value_string.h>
 #include <epan/wmem/wmem.h>
 #include <epan/to_str.h>
-#include <wsutil/inet_aton.h>
+#ifndef HAVE_INET_ATON
+    #include <wsutil/inet_aton.h>
+#endif
 #include <wsutil/pint.h>
 #include "packet-lbm.h"
 #include "packet-lbtru.h"
index 4fa8b42820d95df21f54d3e229fa51965a784748..c7165aa59f52381330d7a275108054c2033b52b5 100644 (file)
@@ -38,7 +38,9 @@
 #include <epan/tap.h>
 #include <epan/conversation.h>
 #include <epan/to_str.h>
-#include <wsutil/inet_aton.h>
+#ifndef HAVE_INET_ATON
+    #include <wsutil/inet_aton.h>
+#endif
 #include <wsutil/pint.h>
 #include "packet-lbm.h"
 #include "packet-lbtrm.h"
index 8b3471956f5b2b4de0c8e706ab5fa9e0ea6bfed5..1bbf793169e2e3d8c8361b2e1c81458801dc17a0 100644 (file)
@@ -39,7 +39,7 @@
 #include <ftypes-int.h>
 #include <epan/to_str.h>
 
-#ifdef NEED_STRPTIME_H
+#ifndef HAVE_STRPTIME
 #include "wsutil/strptime.h"
 #endif
 
index 1ad77b7cf9921c25da7c81269d25d82fa8bad506..11fe105cdfa12c99ae04267df2b01a0ab5eef168 100644 (file)
@@ -59,7 +59,7 @@
  * yet defined.
  */
 #include <time.h>
-/*#ifdef NEED_STRPTIME_H*/
+/*#ifndef HAVE_STRPTIME*/
 #ifndef strptime
 #include "wsutil/strptime.h"
 #endif
index e308ffc3ea8b5c2af477634ab3c4375acb29d8cd..d5ba3e718de7e016108c0275b31a18a415d4245b 100644 (file)
 #include "wsutil/wsgetopt.h"
 #endif
 
-#ifdef NEED_STRPTIME_H
+#ifndef HAVE_STRPTIME
 # include "wsutil/strptime.h"
 #endif
 
 #include <winsock2.h>       /* needed to define AF_ values on Windows */
 #endif
 
-#ifndef HAVE_INET_ATON_H
+#ifndef HAVE_INET_ATON
 # include "wsutil/inet_aton.h"
 #endif
 
index 374b5af28399430bc7e1f4c1ab9e706ce1aacbaa..7b40c49a505f84e94131f037b0e30fdc918a65dd 100644 (file)
 #include <wsutil/crc32.h>
 #include <epan/in_cksum.h>
 
-#ifdef NEED_STRPTIME_H
+#ifndef HAVE_STRPTIME
 # include "wsutil/strptime.h"
 #endif
 
index 385acc6e736c4eca792610fee5b8fc1ddf107722..c2e0c22186c5dda6e5e7389b6ac581ce20b92db2 100644 (file)
@@ -25,32 +25,14 @@ DIST_SUBDIRS = $(SUBDIRS)
 ACLOCAL_AMFLAGS = `../aclocal-flags`
 
 # Optional objects that I know how to build. These will be
-# linked into libwsutil.
-wsutil_optional_objects =
-
-if NEED_GETOPT_LO
-wsutil_optional_objects += @GETOPT_LO@
-endif
-
-if NEED_INET_ATON_LO
-wsutil_optional_objects += @INET_ATON_LO@
-endif
-
-if NEED_INET_NTOP_LO
-wsutil_optional_objects += @INET_NTOP_LO@
-endif
-
-if NEED_INET_PTON_LO
-wsutil_optional_objects += @INET_PTON_LO@
-endif
-
-if NEED_STRNCASECMP_LO
-wsutil_optional_objects += @STRNCASECMP_LO@
-endif
-
-if NEED_STRPTIME_LO
-wsutil_optional_objects += @STRPTIME_LO@
-endif
+# linked into libwsutil if necessary.
+wsutil_optional_objects = \
+       @GETOPT_LO@             \
+       @INET_ATON_LO@          \
+       @INET_NTOP_LO@          \
+       @INET_PTON_LO@          \
+       @STRNCASECMP_LO@        \
+       @STRPTIME_LO@
 
 if SSE42_SUPPORTED
 wsutil_optional_objects += libwsutil_sse42.la
@@ -92,6 +74,7 @@ EXTRA_libwsutil_la_SOURCES=   \
        inet_pton.c             \
        inet_v6defs.h           \
        strncasecmp.c           \
+       strncasecmp.h           \
        strptime.c              \
        strptime.h              \
        wsgetopt.c              \
index da8b862482446eecdaeff3152cf6f3be8817b2ac..57953b9f04b4c9d13614471539dd4a3ac09af824 100644 (file)
@@ -21,6 +21,8 @@
 #include <string.h>
 #include <ctype.h>
 
+#include "wsutil/strncasecmp.h"
+
 /* Compare no more than N characters of S1 and S2,
    ignoring case, returning less than, equal to or
    greater than zero if S1 is lexicographically less
diff --git a/wsutil/strncasecmp.h b/wsutil/strncasecmp.h
new file mode 100644 (file)
index 0000000..bfc3b63
--- /dev/null
@@ -0,0 +1,32 @@
+/* strncasecmp.h
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __STRNCASECMP_H__
+#define __STRNCASECMP_H__
+
+#include "ws_symbol_export.h"
+
+/*
+ * Version of "strncasecmp()", for the benefit of OSes that don't have it.
+ */
+WS_DLL_PUBLIC int strncasecmp (const char *, const char *, size_t);
+
+#endif
index d6603a9d5337198cf9a0e2f217f4e8c0d40ee006..7a8fe2a13ebd7eaab3d79d31a2983c5b3fccd457 100644 (file)
 #include <string.h>
 #include <time.h>
 
+#ifndef HAVE_STRNCASECMP
+#include "wsutil/strncasecmp.h"
+#endif
+
 #ifdef _LIBC
 # include "../locale/localeinfo.h"
 #endif