summaryrefslogtreecommitdiff
path: root/ngircd/src/portab/strndup.c
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-10-23 23:44:03 +0800
committerMistivia <i@mistivia.com>2025-10-23 23:44:07 +0800
commitc8aeef18cb46a617b6397b9822263895e97e9048 (patch)
treeebe127e7c194039f315b74a5998b05a271c57b9d /ngircd/src/portab/strndup.c
add ircd
Diffstat (limited to 'ngircd/src/portab/strndup.c')
-rw-r--r--ngircd/src/portab/strndup.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/ngircd/src/portab/strndup.c b/ngircd/src/portab/strndup.c
new file mode 100644
index 0000000..d63b972
--- /dev/null
+++ b/ngircd/src/portab/strndup.c
@@ -0,0 +1,34 @@
+/*
+ * ngIRCd -- The Next Generation IRC Daemon
+ */
+
+#include "portab.h"
+
+/**
+ * @file
+ * strndup() implementation. Public domain.
+ */
+
+#ifndef HAVE_STRNDUP
+
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.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