summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Ovsienko <denis@ovsienko.info>2023-02-18 23:26:53 +0000
committerDenis Ovsienko <denis@ovsienko.info>2023-02-19 11:33:13 +0000
commitafe133ecef9a8593ecf7fcbb557276c05f2bc7ab (patch)
treed5c3c13e7bd201a9755d1b9f0721a0af01879093
parent114515274fd958b47ef758260b31018a3b18936e (diff)
downloadtcpdump-afe133ecef9a8593ecf7fcbb557276c05f2bc7ab.tar.gz
Do not substitute strdup().
libpcap has been using strdup() for a long time too, but never substituted it under the assumption the function is available in all supported OSes, see libpcap commit cb71eef from 2006. The only exception to that is Windows, which can have a different name for the function, but both libpcap and tcpdump for that already use a separate workaround, which does not involve the substitution. Let's take this as a proof that strdup() substitution in tcpdump is dead code, and remove it.
-rw-r--r--CHANGES1
-rw-r--r--CMakeLists.txt3
-rw-r--r--Makefile.in3
-rw-r--r--cmakeconfig.h.in3
-rw-r--r--configure.ac2
-rw-r--r--interface.h4
-rw-r--r--missing/strdup.c52
-rw-r--r--netdissect.h4
8 files changed, 3 insertions, 69 deletions
diff --git a/CHANGES b/CHANGES
index 08139588..a976bd7f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -33,6 +33,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
Source code:
Use %zu when printing a sizeof to squelch compiler warnings
Remove unused missing/snprintf.c.
+ Remove unused missing/strdup.c.
(FIXME: somebody please wrap the line below just before the release)
AODV, AppleTalk, BOOTP, CHDLC, DCCP, EGP, EIGRP, ForCES, Geneve, GRE, Juniper, L2TP, NetFlow, NTP, OLSR, PGM, RIP, RSVP, SCTP, SNMP, TCP, UDP, vsock: Modernize packet parsing style
DCCP, EGP: Replace custom code with tok2str()
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a707f67f..6e530e7b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -339,7 +339,6 @@ endif(HAVE_RPC_RPC_H)
#
check_function_exists(strlcat HAVE_STRLCAT)
check_function_exists(strlcpy HAVE_STRLCPY)
-check_function_exists(strdup HAVE_STRDUP)
check_function_exists(strsep HAVE_STRSEP)
#
@@ -1261,7 +1260,7 @@ set(NETDISSECT_SOURCE_LIST_C
#
# Replace missing functions
#
-foreach(FUNC strlcat strlcpy strdup strsep getservent getopt_long)
+foreach(FUNC strlcat strlcpy strsep getservent getopt_long)
string(TOUPPER ${FUNC} FUNC_UPPERCASE)
set(HAVE_FUNC_UPPERCASE HAVE_${FUNC_UPPERCASE})
if(NOT ${HAVE_FUNC_UPPERCASE})
diff --git a/Makefile.in b/Makefile.in
index 08036b76..9d03c21b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -367,7 +367,6 @@ EXTRA_DIST = \
missing/getopt_long.h \
missing/getservent.c \
missing/pcap_dump_ftell.c \
- missing/strdup.c \
missing/strlcat.c \
missing/strlcpy.c \
missing/strsep.c \
@@ -414,8 +413,6 @@ getservent.o: $(srcdir)/missing/getservent.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/getservent.c
getopt_long.o: $(srcdir)/missing/getopt_long.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/getopt_long.c
-strdup.o: $(srcdir)/missing/strdup.c
- $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strdup.c
strlcat.o: $(srcdir)/missing/strlcat.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcat.c
strlcpy.o: $(srcdir)/missing/strlcpy.c
diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in
index d008c794..05df2d27 100644
--- a/cmakeconfig.h.in
+++ b/cmakeconfig.h.in
@@ -174,9 +174,6 @@
/* Define to 1 if you have the <stdlib.h> header file. */
#cmakedefine HAVE_STDLIB_H 1
-/* Define to 1 if you have the `strdup' function. */
-#cmakedefine HAVE_STRDUP 1
-
/* Define to 1 if you have the <strings.h> header file. */
#cmakedefine HAVE_STRINGS_H 1
diff --git a/configure.ac b/configure.ac
index 64cc182f..94e767b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -420,7 +420,7 @@ if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then
fi
fi
-AC_REPLACE_FUNCS(strlcat strlcpy strdup strsep getservent getopt_long)
+AC_REPLACE_FUNCS(strlcat strlcpy strsep getservent getopt_long)
AC_CHECK_FUNCS(fork vfork)
AC_CHECK_FUNCS(setlinebuf)
diff --git a/interface.h b/interface.h
index 58e5ab33..b129312a 100644
--- a/interface.h
+++ b/interface.h
@@ -41,10 +41,6 @@ extern size_t strlcat(char *, const char *, size_t);
extern size_t strlcpy(char *, const char *, size_t);
#endif
-#ifndef HAVE_STRDUP
-extern char *strdup(const char *);
-#endif
-
#ifndef HAVE_STRSEP
extern char *strsep(char **, const char *);
#endif
diff --git a/missing/strdup.c b/missing/strdup.c
deleted file mode 100644
index 9cbf35ae..00000000
--- a/missing/strdup.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- * 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 University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * 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.
- */
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "netdissect.h"
-
-char *
-strdup(str)
- const char *str;
-{
- size_t len;
- char *copy;
-
- len = strlen(str) + 1;
- if ((copy = malloc(len)) == NULL)
- return (NULL);
- memcpy(copy, str, len);
- return (copy);
-}
diff --git a/netdissect.h b/netdissect.h
index aa6dfe5b..b744fe87 100644
--- a/netdissect.h
+++ b/netdissect.h
@@ -130,10 +130,6 @@ extern size_t strlcat (char *, const char *, size_t);
extern size_t strlcpy (char *, const char *, size_t);
#endif
-#ifndef HAVE_STRDUP
-extern char *strdup (const char *str);
-#endif
-
#ifndef HAVE_STRSEP
extern char *strsep(char **, const char *);
#endif