Clean up handling of missing functions.

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>
This commit is contained in:
Guy Harris 2014-07-06 14:02:39 -07:00
parent e649420686
commit 5bfc21cf9e
16 changed files with 103 additions and 70 deletions

View 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

View File

@ -216,9 +216,14 @@
/* 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

View 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)

View File

@ -77,7 +77,7 @@
#endif
#endif
#ifdef NEED_STRPTIME_H
#ifndef HAVE_STRPTIME
# include "wsutil/strptime.h"
#endif

View 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

View 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>

View 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"

View 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"

View 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

View File

@ -59,7 +59,7 @@
* yet defined.
*/
#include <time.h>
/*#ifdef NEED_STRPTIME_H*/
/*#ifndef HAVE_STRPTIME*/
#ifndef strptime
#include "wsutil/strptime.h"
#endif

View File

@ -139,7 +139,7 @@
#include "wsutil/wsgetopt.h"
#endif
#ifdef NEED_STRPTIME_H
#ifndef HAVE_STRPTIME
# include "wsutil/strptime.h"
#endif
@ -159,7 +159,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

View File

@ -125,7 +125,7 @@
#include <wsutil/crc32.h>
#include <epan/in_cksum.h>
#ifdef NEED_STRPTIME_H
#ifndef HAVE_STRPTIME
# include "wsutil/strptime.h"
#endif

View 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 \

View 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

32
wsutil/strncasecmp.h Normal file
View File

@ -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

View File

@ -31,6 +31,10 @@
#include <string.h>
#include <time.h>
#ifndef HAVE_STRNCASECMP
#include "wsutil/strncasecmp.h"
#endif
#ifdef _LIBC
# include "../locale/localeinfo.h"
#endif