about summary refs log tree commit diff
path: root/src/portab/strndup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/portab/strndup.c')
-rw-r--r--src/portab/strndup.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/portab/strndup.c b/src/portab/strndup.c
new file mode 100644
index 00000000..d6e01c94
--- /dev/null
+++ b/src/portab/strndup.c
@@ -0,0 +1,37 @@
+/*
+ * ngIRCd -- The Next Generation IRC Daemon
+ */
+
+#include "portab.h"
+
+/**
+ * @file
+ * strndup() implementation. Public domain.
+ */
+
+#ifndef HAVE_STRNDUP
+
+#include "imp.h"
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+#include "exp.h"
+
+GLOBAL char *
+strndup(const char *s, size_t maxlen)
+{
+	char *dup;
+	size_t len = strlen(s);
+
+	if (len > maxlen)
+		len = maxlen;
+	len++;
+	dup = malloc(len);
+	if (dup)
+		strlcpy(dup, s, len);
+	return dup;
+}
+
+#endif
+