|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v2 02/10] lib/nolibc: Add strdup function
Shamelessly taken from Mini-OS.
Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
lib/nolibc/include/string.h | 1 +
lib/nolibc/string.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/lib/nolibc/include/string.h b/lib/nolibc/include/string.h
index 677f528..8674c77 100644
--- a/lib/nolibc/include/string.h
+++ b/lib/nolibc/include/string.h
@@ -57,6 +57,7 @@ size_t strlen(const char *str);
const char *strchr(const char *str, int c);
int strncmp(const char *str1, const char *str2, size_t len);
int strcmp(const char *str1, const char *str2);
+char *strdup(const char *str);
#ifdef __cplusplus
}
diff --git a/lib/nolibc/string.c b/lib/nolibc/string.c
index bf89106..bf4ab50 100644
--- a/lib/nolibc/string.c
+++ b/lib/nolibc/string.c
@@ -33,6 +33,7 @@
* THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
*/
+#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <limits.h>
@@ -166,3 +167,19 @@ int strcmp(const char *str1, const char *str2)
return __res;
}
+
+char *strdup(const char *str)
+{
+ char *__res;
+ int __len;
+
+ __len = strlen(str);
+
+ __res = malloc(__len + 1);
+ if (!__res)
+ return NULL;
+
+ memcpy(__res, str, __len + 1);
+
+ return __res;
+}
--
2.11.0
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |