1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  */
5 #include <stdlib.h>
6 #include <string.h>
7 
strndup(const char * s,size_t n)8 char *strndup(const char *s, size_t n)
9 {
10 	size_t l = strnlen(s, n) + 1;
11 	char *p = malloc(l);
12 
13 	if (p) {
14 		memcpy(p, s, l - 1);
15 		p[l - 1] = '\0';
16 	}
17 	return p;
18 }
19