]> git.puffer.fish Git - mirror/frr.git/commitdiff
* configure.ac: Test existance of strndup.
authorhasso <hasso>
Mon, 19 Sep 2005 09:53:21 +0000 (09:53 +0000)
committerhasso <hasso>
Mon, 19 Sep 2005 09:53:21 +0000 (09:53 +0000)
* lib/str.[ch]: Add strndup() from glibc.

ChangeLog
configure.ac
lib/ChangeLog
lib/str.c
lib/str.h

index e12339a96bbf0a49edca1ea6107ad963f7a9e788..c4f8950bda5b507a723fb9a375a8f14065cf75ed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-09-19 Hasso Tepper <hasso at quagga.net>
+
+       * configure.ac: Test existance of strndup.
+
 2005-08-25 Paul Jakma <paul@jakma.org>
 
        * configure.ac: Add -fno-omit-frame-pointer after -Os in default
index 15bd07516066713d8e32403fc8c330531f5cc9ed..7aa9844c32c2307605c4169eb5d10acaad95315b 100755 (executable)
@@ -5,7 +5,7 @@
 ##  Copyright (c) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
 ##  Portions Copyright (c) 2003 Paul Jakma <paul@dishone.st>
 ##
-## $Id: configure.ac,v 1.111 2005/08/25 14:50:05 paul Exp $
+## $Id: configure.ac,v 1.112 2005/09/19 09:53:21 hasso Exp $
 AC_PREREQ(2.53)
 
 AC_INIT(Quagga, 0.99.1, [http://bugzilla.quagga.net])
@@ -497,7 +497,7 @@ dnl check existance of functions
 dnl ----------------------------
 AC_CHECK_FUNCS(memset memcpy strerror inet_aton daemon snprintf vsnprintf \
                strlcat strlcpy if_nametoindex if_indextoname getifaddrs \
-              fcntl strnlen)
+              fcntl strnlen strndup)
 AC_CHECK_FUNCS(setproctitle, ,
   [AC_CHECK_LIB(util, setproctitle, 
      [LIBS="$LIBS -lutil"
index 08d6278f65c0be38ad4435289910dcd30c2ee21a..53e1eb2229be584bf3fd978849d78483050b5d60 100644 (file)
@@ -1,3 +1,7 @@
+2005-09-19 Hasso Tepper <hasso at quagga.net>
+
+       * str.[ch]: Add strndup() from glibc.
+
 2005-09-05 Paul Jakma <paul.jakma@sun.com>
 
        * command.c: (install_element) be more robust. Eg, cmd_init
index 00d03194d7246fc5e999a148fd3d47ab6ede9fae..4ab71e19758e91fcf69593209052ade511938cfe 100644 (file)
--- a/lib/str.c
+++ b/lib/str.c
@@ -11,6 +11,9 @@
 
  Note that these are not terribly efficient, since they make more than one
  pass over the argument strings.  At some point, they should be optimized.
+ The implementation of strndup is copied from glibc-2.3.5:
+    Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
 */
 
 
@@ -89,3 +92,18 @@ strnlen(const char *s, size_t maxlen)
   return (p = (const char *)memchr(s, '\0', maxlen)) ? (size_t)(p-s) : maxlen;
 }
 #endif
+
+#ifndef HAVE_STRNDUP
+char *
+strndup (const char *s, size_t maxlen)
+{
+    size_t len = strnlen (s, maxlen);
+    char *new = (char *) malloc (len + 1);
+
+    if (new == NULL)
+      return NULL;
+
+    new[len] = '\0';
+    return (char *) memcpy (new, s, len);
+}
+#endif
index 145863d265498c19df420f71f6132374db4623a7..7b83fe1cb14bfd284173cfd10f031f65a3eedeaa 100644 (file)
--- a/lib/str.h
+++ b/lib/str.h
@@ -1,5 +1,5 @@
 /*
- * $Id: str.h,v 1.3 2005/05/06 21:25:49 paul Exp $
+ * $Id: str.h,v 1.4 2005/09/19 09:53:21 hasso Exp $
  */
 
 #ifndef _ZEBRA_STR_H
@@ -25,5 +25,9 @@ extern size_t strlcat(char *, const char *, size_t);
 extern size_t strnlen(const char *s, size_t maxlen);
 #endif
 
+#ifndef HAVE_STRNDUP
+extern char * strndup (const char *, size_t);
+#endif
+
 #endif /* _ZEBRA_STR_H */