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