summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorhasso <hasso>2005-09-19 09:53:21 +0000
committerhasso <hasso>2005-09-19 09:53:21 +0000
commite6a4feb763749ff0c63558db456e617915fd1386 (patch)
treee348859f9ef281521ad13552e062ea6da44a2248 /lib
parent96e30387f164148fe47da6d4481283a61d761c97 (diff)
* configure.ac: Test existance of strndup.
* lib/str.[ch]: Add strndup() from glibc.
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog4
-rw-r--r--lib/str.c18
-rw-r--r--lib/str.h6
3 files changed, 27 insertions, 1 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 08d6278f..53e1eb22 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -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
diff --git a/lib/str.c b/lib/str.c
index 00d03194..4ab71e19 100644
--- 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
diff --git a/lib/str.h b/lib/str.h
index 145863d2..7b83fe1c 100644
--- 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 */