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

[Minios-devel] [UNIKRAFT PATCH v3 02/10] lib/nolibc: Add strndup and strdup functions


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 10 Sep 2018 12:05:54 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Mon, 10 Sep 2018 09:06:22 +0000
  • Ironport-phdr: 9a23:HV93/xQrbnnJAq7+c2bsLUbYmNpsv+yvbD5Q0YIujvd0So/mwa6yYhyN2/xhgRfzUJnB7Loc0qyK6/+mATRIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfbF/IA+qoQnNq8IbnZZsJqEtxxXTv3BGYf5WxWRmJVKSmxbz+MK994N9/ipTpvws6ddOXb31cKokQ7NYCi8mM30u683wqRbDVwqP6WACXWgQjxFFHhLK7BD+Xpf2ryv6qu9w0zSUMMHqUbw5Xymp4qF2QxHqlSgHLSY0/mHJhMJtgqxVoxWvqB5xw4PPfI2ZKOBzcr/HcN8GWWZMWNtaWSxbAoO7aosCF/QMPeFDr4nhplsOqwa1Cw+xBOP31z9Dm3j70rE90+Q6DQHG3QogE8gKsHTJtNX1KbwfXvyuzKXS1TXDcuhZ1S3n6IjPax0sp+yHU7FoccfJ1EUiGB7Jgk+TpIHlJT+ZyPoBvmqB4+duTe6jlmEqpxxrrjWsxsogkJfFi4wbx1ze6Cl0z5g5KNulQ0Bhe9GkCoFftySCOotzRcMtXn9ntT4hyr0DpZ67ZC8KyIk7xxLHa/yIbYyI4hX7WeaPJDd3nnNleLalixmu6kis0PX8VtSv31pQtCpFlcHAtnEL1xPN9siKUuZx80i81TqV1A3e6vtILV4qmafZMZIszKY8lp8JvkTCGi/2ll/2jKiTdkg85ueo7P/nYqnnpp+aLYN0jhz+MrwzmsGkHes4KRICX3CG+eunzrHj50r5TK1QjvIqiqnZrIzaJcMDq668Ag9V1Icj6xGkDzu/zdsXg2cHI0xBeB+ci4jpOkrOIOzjDfuljFWjjjFry+rBPr37DZXHNmLDn6v5fbZh905czxI+zcte55JRDbEBJuj/WkzstNPGCB84MhK7w/z8BdV7yIwRRWaPDbWCP6/Ir1CI+/olI/OQa48NpDb9N/8l6ubujH8kg18dfLOl3YUQaHC8AvtmI0aZYX3ygtoaF2cFoBYxTOjwh1KZSzJceWuyDOoA4WQ+CYSnCpyGSo2zjbip2CagAoYQdm1ATFeWHiTGbYKBDtwLcz6TJIdFjyQZHeyqTJQ91BfosBLi1pJsNazM5yder5W1h4s93PHaiRxnrW88NM+ayWzYF2w=
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Port strdup function from Mini-OS.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 lib/nolibc/exportsyms.uk    |  2 ++
 lib/nolibc/include/string.h |  2 ++
 lib/nolibc/string.c         | 22 ++++++++++++++++++++++
 3 files changed, 26 insertions(+)

diff --git a/lib/nolibc/exportsyms.uk b/lib/nolibc/exportsyms.uk
index 6492581..61d49c7 100644
--- a/lib/nolibc/exportsyms.uk
+++ b/lib/nolibc/exportsyms.uk
@@ -62,6 +62,8 @@ strcmp
 strcspn
 strspn
 strtok
+strndup
+strdup
 
 # time
 nanosleep
diff --git a/lib/nolibc/include/string.h b/lib/nolibc/include/string.h
index 1d63ae9..b21e2c1 100644
--- a/lib/nolibc/include/string.h
+++ b/lib/nolibc/include/string.h
@@ -61,6 +61,8 @@ int strcmp(const char *str1, const char *str2);
 size_t strcspn(const char *s, const char *c);
 size_t strspn(const char *s, const char *c);
 char *strtok(char *restrict s, const char *restrict sep);
+char *strndup(const char *str, size_t len);
+char *strdup(const char *str);
 
 #ifdef __cplusplus
 }
diff --git a/lib/nolibc/string.c b/lib/nolibc/string.c
index d4a6469..6f853ba 100644
--- a/lib/nolibc/string.c
+++ b/lib/nolibc/string.c
@@ -57,6 +57,7 @@
  * ----------------------------------------------------------------------
  */
 
+#include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
 #include <limits.h>
@@ -264,3 +265,24 @@ char *strtok(char *restrict s, const char *restrict sep)
                p = 0;
        return s;
 }
+
+char *strndup(const char *str, size_t len)
+{
+       char *__res;
+       int __len;
+
+       __len = strnlen(str, len);
+
+       __res = malloc(__len + 1);
+       if (__res) {
+               memcpy(__res, str, __len);
+               __res[__len] = '\0';
+       }
+
+       return __res;
+}
+
+char *strdup(const char *str)
+{
+       return strndup(str, SIZE_MAX);
+}
-- 
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®.