#ifndef HAVE_STRLCPY
#include "compat/strlcpy.h"
#endif
+#ifndef HAVE_STRNDUP
+#include "compat/strndup.h"
+#endif
+
#include "mgt.h"
/*--------------------------------------------------------------------*/
}
#endif
-static char *
-strndup(const char *p, unsigned n)
-{
- char *q;
-
- q = malloc(n + 1);
- if (q != NULL) {
- memcpy(q, p, n);
- q[n] = '\0';
- }
- return (q);
-}
-
int
TCP_parse(const char *str, char **addr, char **port)
{
AC_CHECK_FUNCS([setproctitle])
AC_CHECK_FUNCS([srandomdev])
AC_CHECK_FUNCS([strlcat strlcpy])
+AC_CHECK_FUNCS([strndup])
AC_CHECK_FUNCS([vis strvis strvisx])
# On some systems, clock_gettime is in librt rather than libc
compat/srandomdev.h \
compat/strlcat.h \
compat/strlcpy.h \
+ compat/strndup.h \
compat/vasprintf.h \
compat/vis.h \
hash.h \
--- /dev/null
+/*
+ * $Id$
+ */
+
+#ifndef COMPAT_STRNDUP_H_INCLUDED
+#define COMPAT_STRNDUP_H_INCLUDED
+
+#ifndef HAVE_STRNDUP
+char *strndup(const char *str, size_t len);
+#endif
+
+#endif
srandomdev.c \
strlcat.c \
strlcpy.c \
+ strndup.c \
vis.c
libcompat_a_CFLAGS = -include config.h
--- /dev/null
+/*
+ * $Id$
+ *
+ */
+
+#ifndef HAVE_STRNDUP
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "compat/strndup.h"
+
+char *
+strndup(const char *str, size_t len)
+{
+ char *dup;
+
+ /* wasteful if len is large and str is short */
+ if ((dup = calloc(len + 1, 1)) != NULL)
+ strncpy(dup, str, len);
+ return (dup);
+}
+
+#endif