]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Patch from Pekka Savola <[email protected]> to get rid of "savestr()"
authorguy <guy>
Sat, 20 Jan 2001 07:22:20 +0000 (07:22 +0000)
committerguy <guy>
Sat, 20 Jan 2001 07:22:20 +0000 (07:22 +0000)
(which doesn't actually seem to be significantly more efficient than
"strdup()", at least not to the extent that it makes any difference to
"tcpdump"), modified to use the BSD "strdup()", rather than the old
"savestr()", on platforms that lack "strdup()".

FILES
addrtoname.c
config.h.in
configure
configure.in
interface.h
missing/strdup.c [new file with mode: 0644]
print-atalk.c
print-decnet.c
savestr.c [deleted file]
savestr.h [deleted file]

diff --git a/FILES b/FILES
index 987589e95cec3c8ddc2abad63917bbf9c9a13b4a..643faeb3cdea78cf501a268fbeb403c8fcc2005d 100644 (file)
--- a/FILES
+++ b/FILES
@@ -61,6 +61,7 @@ missing/snprintf.c
 missing/sockstorage.h
 missing/strlcat.c
 missing/strlcpy.c
+missing/strdup.c
 mkdep
 nameser.h
 netbios.h
@@ -144,8 +145,6 @@ print-vrrp.c
 print-wb.c
 route6d.h
 rx.h
-savestr.c
-savestr.h
 send-ack.awk
 setsignal.c
 setsignal.h
index f399b044474f17fb7cc8b46d6faf5c48c1fbd1e1..d5f71d3e3574a5f3aa1b5e5f7ca80afc9992074b 100644 (file)
@@ -23,7 +23,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.70 2001-01-17 18:27:36 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.71 2001-01-20 07:22:21 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -58,7 +58,6 @@ struct rtentry;
 #include "interface.h"
 #include "addrtoname.h"
 #include "llc.h"
-#include "savestr.h"
 #include "setsignal.h"
 
 /* Forwards */
@@ -210,7 +209,7 @@ getname(const u_char *ap)
                        if (hp) {
                                char *dotp;
 
-                               p->name = savestr(hp->h_name);
+                               p->name = strdup(hp->h_name);
                                if (Nflag) {
                                        /* Remove domain qualifications */
                                        dotp = strchr(p->name, '.');
@@ -221,7 +220,7 @@ getname(const u_char *ap)
                        }
                }
        }
-       p->name = savestr(intoa(addr));
+       p->name = strdup(intoa(addr));
        return (p->name);
 }
 
@@ -273,7 +272,7 @@ getname6(const u_char *ap)
                        if (hp) {
                                char *dotp;
 
-                               p->name = savestr(hp->h_name);
+                               p->name = strdup(hp->h_name);
                                if (Nflag) {
                                        /* Remove domain qualifications */
                                        dotp = strchr(p->name, '.');
@@ -285,7 +284,7 @@ getname6(const u_char *ap)
                }
        }
        cp = (char *)inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf));
-       p->name = savestr(cp);
+       p->name = strdup(cp);
        return (p->name);
 }
 #endif /* INET6 */
@@ -409,7 +408,7 @@ etheraddr_string(register const u_char *ep)
        if (!nflag) {
                char buf[128];
                if (ether_ntohost(buf, (struct ether_addr *)ep) == 0) {
-                       tp->e_name = savestr(buf);
+                       tp->e_name = strdup(buf);
                        return (tp->e_name);
                }
        }
@@ -425,7 +424,7 @@ etheraddr_string(register const u_char *ep)
                *cp++ = hex[*ep++ & 0xf];
        }
        *cp = '\0';
-       tp->e_name = savestr(buf);
+       tp->e_name = strdup(buf);
        return (tp->e_name);
 }
 
@@ -451,7 +450,7 @@ etherproto_string(u_short port)
        *cp++ = hex[port >> 4 & 0xf];
        *cp++ = hex[port & 0xf];
        *cp++ = '\0';
-       tp->name = savestr(buf);
+       tp->name = strdup(buf);
        return (tp->name);
 }
 
@@ -478,7 +477,7 @@ protoid_string(register const u_char *pi)
                *cp++ = hex[*pi++ & 0xf];
        }
        *cp = '\0';
-       tp->p_name = savestr(buf);
+       tp->p_name = strdup(buf);
        return (tp->p_name);
 }
 
@@ -497,7 +496,7 @@ llcsap_string(u_char sap)
        tp->nxt = newhnamemem();
 
        snprintf(buf, sizeof(buf), "sap %02x", sap & 0xff);
-       tp->name = savestr(buf);
+       tp->name = strdup(buf);
        return (tp->name);
 }
 
@@ -541,7 +540,7 @@ tcpport_string(u_short port)
        tp->nxt = newhnamemem();
 
        (void)snprintf(buf, sizeof(buf), "%u", i);
-       tp->name = savestr(buf);
+       tp->name = strdup(buf);
        return (tp->name);
 }
 
@@ -560,7 +559,7 @@ udpport_string(register u_short port)
        tp->nxt = newhnamemem();
 
        (void)snprintf(buf, sizeof(buf), "%u", i);
-       tp->name = savestr(buf);
+       tp->name = strdup(buf);
        return (tp->name);
 }
 
@@ -586,9 +585,9 @@ init_servarray(void)
                        table = table->nxt;
                if (nflag) {
                        (void)snprintf(buf, sizeof(buf), "%d", port);
-                       table->name = savestr(buf);
+                       table->name = strdup(buf);
                } else
-                       table->name = savestr(sv->s_name);
+                       table->name = strdup(sv->s_name);
                table->addr = port;
                table->nxt = newhnamemem();
        }
@@ -637,7 +636,7 @@ init_protoidarray(void)
 
                memcpy((char *)&protoid[3], (char *)&etype, 2);
                tp = lookup_protoid(protoid);
-               tp->p_name = savestr(eproto_db[i].s);
+               tp->p_name = strdup(eproto_db[i].s);
        }
 }
 
@@ -679,7 +678,7 @@ init_etherarray(void)
        if (fp != NULL) {
                while ((ep = pcap_next_etherent(fp)) != NULL) {
                        tp = lookup_emem(ep->addr);
-                       tp->e_name = savestr(ep->name);
+                       tp->e_name = strdup(ep->name);
                }
                (void)fclose(fp);
        }
@@ -695,7 +694,7 @@ init_etherarray(void)
 #ifdef HAVE_ETHER_NTOHOST
                 /* Use yp/nis version of name if available */
                 if (ether_ntohost(name, (struct ether_addr *)el->addr) == 0) {
-                        tp->e_name = savestr(name);
+                        tp->e_name = strdup(name);
                        continue;
                }
 #endif
index 36926814960bfaee94762c5d581d1af67b464a52..06983b1ce71879f98cdb149c344bcb93482e6b4c 100644 (file)
 /* Define if you have the strcasecmp function.  */
 #undef HAVE_STRCASECMP
 
+/* Define if you have the strdup function.  */
+#undef HAVE_STRDUP
+
 /* Define if you have the strlcat function.  */
 #undef HAVE_STRLCAT
 
index 408631691442b53b945636e5c95bae05f4b2d9a3..ac65efb1373089f69790455d0b77cc13368182cd 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# From configure.in Revision: 1.133 
+# From configure.in Revision: 1.134 
 
 
 
@@ -2832,7 +2832,7 @@ if test "$missing_includes" = "yes"; then
 fi
 
 
-for ac_func in vfprintf strcasecmp strlcat strlcpy
+for ac_func in vfprintf strcasecmp strlcat strlcpy strdup
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo "configure:2839: checking for $ac_func" >&5
index 29f77785450b143f7c580a4bce3a66b39274c175..8851f0fc9d0c9b1b95e442ba05f70ac91dc8ea3a 100644 (file)
@@ -1,4 +1,4 @@
-dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.133 2001-01-17 18:27:36 guy Exp $ (LBL)
+dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.134 2001-01-20 07:22:22 guy Exp $ (LBL)
 dnl
 dnl Copyright (c) 1994, 1995, 1996, 1997
 dnl    The Regents of the University of California.  All rights reserved.
@@ -6,7 +6,7 @@ dnl
 dnl Process this file with autoconf to produce a configure script.
 dnl
 
-AC_REVISION($Revision: 1.133 $)
+AC_REVISION($Revision: 1.134 $)
 AC_PREREQ(2.13)
 AC_INIT(tcpdump.c)
 
@@ -450,7 +450,7 @@ if test "$missing_includes" = "yes"; then
 fi
 
 
-AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy)
+AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy strdup)
 AC_CHECK_FUNCS(ether_ntohost setlinebuf)
 
 usegetipnodeby=yes
index 43d31e21bc56fc689b619d8761f2ae752f286d27..9fc2f385a6d27841e3421cc2fe65ea129f387bc0 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.151 2001-01-15 03:59:13 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.152 2001-01-20 07:22:22 guy Exp $ (LBL)
  */
 
 #ifndef tcpdump_interface_h
@@ -55,6 +55,10 @@ 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
+
 struct tok {
        int v;                  /* value */
        char *s;                /* string */
diff --git a/missing/strdup.c b/missing/strdup.c
new file mode 100644 (file)
index 0000000..079a8ff
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char rcsid[] =
+    "@(#) $Header: /tcpdump/master/tcpdump/missing/strdup.c,v 1.1 2001-01-20 07:26:08 guy Exp $ (LBL)";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "interface.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 b00c08ff5538534beea59ad69aec6cb9217f0253..e60e674a827b9a36d92e8f427c6ac76e05c6afcf 100644 (file)
@@ -23,7 +23,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.64 2000-10-30 06:22:14 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.65 2001-01-20 07:22:23 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -46,7 +46,6 @@ static const char rcsid[] =
 #include "ethertype.h"
 #include "extract.h"                   /* must come after interface.h */
 #include "appletalk.h"
-#include "savestr.h"
 
 static struct tok type2str[] = {
        { ddpRTMP,              "rtmp" },
@@ -542,7 +541,7 @@ ataddr_string(u_short atnet, u_char athost)
                                ;
                        tp->addr = i3;
                        tp->nxt = newhnamemem();
-                       tp->name = savestr(nambuf);
+                       tp->name = strdup(nambuf);
                }
                fclose(fp);
        }
@@ -559,7 +558,7 @@ ataddr_string(u_short atnet, u_char athost)
                        tp->nxt = newhnamemem();
                        (void)snprintf(nambuf, sizeof(nambuf), "%s.%d",
                            tp2->name, athost);
-                       tp->name = savestr(nambuf);
+                       tp->name = strdup(nambuf);
                        return (tp->name);
                }
 
@@ -571,7 +570,7 @@ ataddr_string(u_short atnet, u_char athost)
        else
                (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet >> 8,
                    atnet & 0xff);
-       tp->name = savestr(nambuf);
+       tp->name = strdup(nambuf);
 
        return (tp->name);
 }
index 16d0ee0c56ff98c806713b11cfb19e960a47f0a3..6f8facce5c602aac2caf226e51a920c7c0db504d 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.30 2000-09-28 06:42:57 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.31 2001-01-20 07:22:24 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -753,7 +753,7 @@ dnname_string(u_short dnaddr)
 
        dna.a_len = sizeof(short);
        memcpy((char *)dna.a_addr, (char *)&dnaddr, sizeof(short));
-       return (savestr(dnet_htoa(&dna)));
+       return (strdup(dnet_htoa(&dna)));
 #else
        return(dnnum_string(dnaddr));   /* punt */
 #endif
diff --git a/savestr.c b/savestr.c
deleted file mode 100644 (file)
index 7ff87ad..0000000
--- a/savestr.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 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: (1) source code distributions
- * retain the above copyright notice and this paragraph in its entirety, (2)
- * distributions including binary code include the above copyright notice and
- * this paragraph in its entirety in the documentation or other materials
- * provided with the distribution, and (3) all advertising materials mentioning
- * features or use of this software display the following acknowledgement:
- * ``This product includes software developed by the University of California,
- * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-#ifndef lint
-static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/Attic/savestr.c,v 1.6 2000-07-11 00:49:02 assar Exp $ (LBL)";
-#endif
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <sys/types.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef HAVE_OS_PROTO_H
-#include "os-proto.h"
-#endif
-
-#include "savestr.h"
-
-/* A replacement for strdup() that cuts down on malloc() overhead */
-char *
-savestr(register const char *str)
-{
-       register u_int size;
-       register char *p;
-       static char *strptr = NULL;
-       static u_int strsize = 0;
-
-       size = strlen(str) + 1;
-       if (size > strsize) {
-               strsize = 1024;
-               if (strsize < size)
-                       strsize = size;
-               strptr = (char *)malloc(strsize);
-               if (strptr == NULL) {
-                       fprintf(stderr, "savestr: malloc\n");
-                       exit(1);
-               }
-       }
-       (void)strcpy(strptr, str);
-       p = strptr;
-       strptr += size;
-       strsize -= size;
-       return (p);
-}
diff --git a/savestr.h b/savestr.h
deleted file mode 100644 (file)
index 319febf..0000000
--- a/savestr.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 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: (1) source code distributions
- * retain the above copyright notice and this paragraph in its entirety, (2)
- * distributions including binary code include the above copyright notice and
- * this paragraph in its entirety in the documentation or other materials
- * provided with the distribution, and (3) all advertising materials mentioning
- * features or use of this software display the following acknowledgement:
- * ``This product includes software developed by the University of California,
- * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- * @(#) $Header: /tcpdump/master/tcpdump/Attic/savestr.h,v 1.1 1999-10-07 23:47:12 mcr Exp $ (LBL)
- */
-
-extern char *savestr(const char *);