X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib%2Fstring.c;h=9b779ddc3bbe42b6df36a70c3ece2213b40e5fa6;hb=17fd9915a4c639381804ed28274fa136ae3b0bee;hp=af17c16f616db4b8afc71cb55b31ad394457636b;hpb=430c166bcedd22e0ce93ce298747275f814b172f;p=oweals%2Fu-boot.git diff --git a/lib/string.c b/lib/string.c index af17c16f61..9b779ddc3b 100644 --- a/lib/string.c +++ b/lib/string.c @@ -326,6 +326,29 @@ char * strdup(const char *s) } #endif +char * strndup(const char *s, size_t n) +{ + size_t len; + char *new; + + if (s == NULL) + return NULL; + + len = strlen(s); + + if (n < len) + len = n; + + new = malloc(len + 1); + if (new == NULL) + return NULL; + + strncpy(new, s, len); + new[len] = '\0'; + + return new; +} + #ifndef __HAVE_ARCH_STRSPN /** * strspn - Calculate the length of the initial substring of @s which only