aboutsummaryrefslogtreecommitdiffstats
path: root/memory/wcsndup.c
diff options
context:
space:
mode:
Diffstat (limited to 'memory/wcsndup.c')
-rw-r--r--memory/wcsndup.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/memory/wcsndup.c b/memory/wcsndup.c
new file mode 100644
index 0000000..0d65ce3
--- /dev/null
+++ b/memory/wcsndup.c
@@ -0,0 +1,10 @@
+#include "memory.h"
+
+wchar_t *wcsndup(wchar_t const *restrict string, size_t max_lenght)
+{
+ size_t lenght = wcsnlen(string, max_lenght) + 1;
+ wchar_t *duplicate = reallocarray(NULL, lenght, sizeof *duplicate);
+ if (duplicate != NULL)
+ wmemcpy(duplicate, string, lenght);
+ return duplicate;
+}