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

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



Reviewed-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>

Costin Lupu <costin.lupu@xxxxxxxxx> writes:

> 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
>

-- 
Yuri Volchkov
Software Specialist

NEC Europe Ltd
Kurfürsten-Anlage 36
D-69115 Heidelberg

_______________________________________________
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®.