[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 02/10] lib/nolibc: Add strdup function


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Thu, 23 Aug 2018 13:59:30 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Thu, 23 Aug 2018 10:59:49 +0000
  • Ironport-phdr: 9a23:+C7T0hJoehRVsZqYjdmcpTZWNBhigK39O0sv0rFitYgfKfrxwZ3uMQTl6Ol3ixeRBMOHs60C07KempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffwdFiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLdQgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QLYpUjqg8qhrUgflhicZOTAk/m/Zict+g6BVoB+6uxBz35TZbJ2POfZiYq/Qe84RS2pbXsZWUixMGp2xb4wUD+odPOZYqZT2qV0TrRumGAmnGeTixSNPhn/twa060uIhHRvC3Aw9B9IOrW/Zo8nuNKsISeC10bLHwS/Zb/NRwDrw7pXDfBM5ofyUQL59ftfdxVMsGg7FlFmct5LpMjGP2ukDq2SX8uVtWf+1h2Mkqwx9uCajy8kih4XTm44YxU7I+CNky4gvP9K4UlR0Ydu8HZtVsCGVKpV5T9s5Q2FtpCY60roGuYOnfCQSyJQo2Rrfa/uffoiW5xLsTueRITNiiH15Y7KznQ6y8VW7xeHmTMm0105GritDktbSqnAAzwHf58eaRvdn/Uqs2SyD2x7N5uxGO0w5m7LXK5s7zb4xkpoTv17DHijzmEjukKCWcV4k+vSp6+TheLnmooKcN5dpigzlLqsugdazAfwlMgcVRWSb4+O82KX5/ULlWLVKkuE2kq7BvZDfJMQboK+5AwhO0oo69hmwESmm38ocnXQcKFJFeQmHj5TyO13UL/H3E/G/j06rkDdxyPDMJqfhDYnVLnjfjLfheq5w61VcyAUp19BQ/ZRUBqsaIP3pXE/xqNzYAQU/MwOuxubqE9N92Z0CVmKLGKCWK7nevkGV5ug3OemDeJcVuCrhK/gi//Puln45mVoafamvx5cXa224EepgI0SYf3XsmMwMEWEUsQUiSOzlkkaNXSRNaHavR6g8/C00CJq6DYffQYCgmLyA3DqhHp1XfGxGFFeMEXP0eIWEWPcMbzySL9RnkjMaSbehT5Uu2gq0uADk1ro0ZtbTrygZs5Pkz5156vPekTk29CdoFIKN3mfLSHt7zU0SQDpj96dkvU17gnOeybUw1/dfDsBS4bVNTx8nHZXHifRnAZboXVSSLZ+yVF+6T4D+UnkKRdUrzopWbg==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.