wm: teppich

Download patch

ref: fda16cc781136673518f9f04ebd907c0e96cda86
parent: 92d82682e2b610e142678111efe851ef219df799
author: mkf <mkf@cloud9p.org>
date: Tue Nov 28 22:45:09 EST 2023

add strdup.

--- a/Makefile
+++ b/Makefile
@@ -35,6 +35,7 @@
 	libc/strtol.o\
 	libc/strncpy.o\
 	libc/strncat.o\
+	libc/strdup.o\
 	libc/memcpy.o\
 	libc/memset.o\
 	libc/lladd.o\
--- a/include/libc.h
+++ b/include/libc.h
@@ -12,6 +12,7 @@
 long strtol(char *nptr, char **endptr, int base);
 char* strncpy(char *dst, const char *src, size_t num);
 char* strncat(char *s1, char *s2, long n);
+char* strdup(char *s);
 
 void* memset(void* src, char c, unsigned int len);
 void* memcpy(void *a1, void *a2, unsigned int len);
--- /dev/null
+++ b/libc/strdup.c
@@ -1,0 +1,12 @@
+#include <u.h>
+#include <libc.h>
+#include <mem.h>
+
+char*
+strdup(char *s)
+{
+	char *dup;
+
+	dup = malloc(strlen(s) + 1); /* s + \0 */
+	return strncpy(s, dup, strlen(s));
+}