]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Do not substitute strdup().
authorDenis Ovsienko <[email protected]>
Sat, 18 Feb 2023 23:26:53 +0000 (23:26 +0000)
committerDenis Ovsienko <[email protected]>
Sun, 19 Feb 2023 11:33:13 +0000 (11:33 +0000)
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.

CHANGES
CMakeLists.txt
Makefile.in
cmakeconfig.h.in
configure.ac
interface.h
missing/strdup.c [deleted file]
netdissect.h

diff --git a/CHANGES b/CHANGES
index 08139588c4ab5818807ad80444ed2421e8c39e98..a976bd7f2278d64747c141f5dc03b4dab52009da 100644 (file)
--- 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.
     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()
       (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()
index a707f67ff14ee02f8defbfec1a73cabf8cf49d82..6e530e7b11b0b5f9a39390be3bbda2855721b540 100644 (file)
@@ -339,7 +339,6 @@ endif(HAVE_RPC_RPC_H)
 #
 check_function_exists(strlcat HAVE_STRLCAT)
 check_function_exists(strlcpy HAVE_STRLCPY)
 #
 check_function_exists(strlcat HAVE_STRLCAT)
 check_function_exists(strlcpy HAVE_STRLCPY)
-check_function_exists(strdup HAVE_STRDUP)
 check_function_exists(strsep HAVE_STRSEP)
 
 #
 check_function_exists(strsep HAVE_STRSEP)
 
 #
@@ -1261,7 +1260,7 @@ set(NETDISSECT_SOURCE_LIST_C
 #
 # Replace missing functions
 #
 #
 # 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})
     string(TOUPPER ${FUNC} FUNC_UPPERCASE)
     set(HAVE_FUNC_UPPERCASE HAVE_${FUNC_UPPERCASE})
     if(NOT ${HAVE_FUNC_UPPERCASE})
index 08036b7651022ffb008b4bc0332a49616869ef54..9d03c21b91fa929a50d07b30b45302eb631f27d0 100644 (file)
@@ -367,7 +367,6 @@ EXTRA_DIST = \
        missing/getopt_long.h \
        missing/getservent.c \
        missing/pcap_dump_ftell.c \
        missing/getopt_long.h \
        missing/getservent.c \
        missing/pcap_dump_ftell.c \
-       missing/strdup.c \
        missing/strlcat.c \
        missing/strlcpy.c \
        missing/strsep.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
        $(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
 strlcat.o: $(srcdir)/missing/strlcat.c
        $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcat.c
 strlcpy.o: $(srcdir)/missing/strlcpy.c
index d008c794981cf67f97d6d51a1a6d13f25a830492..05df2d2763a4ccec2bbb04ae6422293390718ba1 100644 (file)
 /* Define to 1 if you have the <stdlib.h> header file. */
 #cmakedefine HAVE_STDLIB_H 1
 
 /* 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
 
 /* Define to 1 if you have the <strings.h> header file. */
 #cmakedefine HAVE_STRINGS_H 1
 
index 64cc182f4972f83adf7ee5801c7f032d0a557011..94e767b366fe1e0758b62124b477576006a7ce5d 100644 (file)
@@ -420,7 +420,7 @@ if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then
        fi
 fi
 
        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)
 
 AC_CHECK_FUNCS(fork vfork)
 AC_CHECK_FUNCS(setlinebuf)
 
index 58e5ab33e51f4a0b1878929fa4cfcaf9ccb6bba5..b129312ab41688ed866dde81fa17f9e0195fec9c 100644 (file)
@@ -41,10 +41,6 @@ extern size_t strlcat(char *, const char *, size_t);
 extern size_t strlcpy(char *, const char *, size_t);
 #endif
 
 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
 #ifndef HAVE_STRSEP
 extern char *strsep(char **, const char *);
 #endif
diff --git a/missing/strdup.c b/missing/strdup.c
deleted file mode 100644 (file)
index 9cbf35a..0000000
+++ /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);
-}
index aa6dfe5b9ea56260d4819a8553b37c1f40474405..b744fe87677c3b9d883c89c56a8a5a83eab67afe 100644 (file)
@@ -130,10 +130,6 @@ extern size_t strlcat (char *, const char *, size_t);
 extern size_t strlcpy (char *, const char *, size_t);
 #endif
 
 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
 #ifndef HAVE_STRSEP
 extern char *strsep(char **, const char *);
 #endif